instance Arbitrary v => Arbitrary (Edge v) where
arbitrary = do s <- arbitrary
t <- arbitrary
return $ Edge {source = s, target = t}
instance (Ord v, Arbitrary v) => Arbitrary (Graph v) where
arbitrary = aux `suchThat` validGraph
where aux = do lNodes <- arbitrary
lEdges <- arbitrary
return $ Graph {nodes = fromList lNodes, edges = fromList lEdges}
I currently have this to generate my Graphs. However by using sample on ghci I noticed that it either doesn't generate edges or it generates a single one. Is it possible to control the number of edges generated? How would I do it?
EDIT: A Graph is considered valid when the source and target nodes of an edge exist.
Aucun commentaire:
Enregistrer un commentaire