From 2c84e82a0263c9bf87cc660a9aabeb5f69828253 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sat, 29 Dec 2018 22:29:45 +0100 Subject: Add new generation method --- src/Test/VeriFuzz/Graph/Random.hs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/Test') diff --git a/src/Test/VeriFuzz/Graph/Random.hs b/src/Test/VeriFuzz/Graph/Random.hs index 8d3eb50..7f9e3e6 100644 --- a/src/Test/VeriFuzz/Graph/Random.hs +++ b/src/Test/VeriFuzz/Graph/Random.hs @@ -12,9 +12,10 @@ Define the random generation for the directed acyclic graph. module Test.VeriFuzz.Graph.Random where -import Data.Graph.Inductive (Graph, LEdge, mkGraph) -import Test.QuickCheck (Arbitrary, Gen) -import qualified Test.QuickCheck as QC +import Data.Graph.Inductive (Graph, LEdge, mkGraph) +import Data.Graph.Inductive.PatriciaTree (Gr) +import Test.QuickCheck (Arbitrary, Gen) +import qualified Test.QuickCheck as QC -- | Gen instance to create an arbitrary edge, where the edges are limited by -- `n` that is passed to it. @@ -28,19 +29,18 @@ arbitraryEdge n = do with = QC.suchThat $ QC.resize n QC.arbitrary -- | Gen instance for a random acyclic DAG. -randomDAG :: (Arbitrary l, Arbitrary e, Graph gr) - => Int -- ^ The number of nodes - -> Gen (gr l e) -- ^ The generated graph. It uses Arbitrary to +randomDAG :: (Arbitrary l, Arbitrary e) + => Gen (Gr l e) -- ^ The generated graph. It uses Arbitrary to -- generate random instances of each node -randomDAG n = do +randomDAG = do list <- QC.infiniteListOf QC.arbitrary - l <- QC.infiniteListOf $ arbitraryEdge n - return . mkGraph (nodes list) $ take (10*n) l + l <- QC.infiniteListOf $ aE + QC.sized (\n -> return . mkGraph (nodes list n) $ take (10*n) l) where - nodes l = zip [0..n] $ take n l + nodes l n = zip [0..n] $ take n l + aE = QC.sized arbitraryEdge -- | Generate a random acyclic DAG with an IO instance. -genRandomDAG :: (Arbitrary l, Arbitrary e, Graph gr) - => Int - -> IO (gr l e) -genRandomDAG = QC.generate . randomDAG +genRandomDAG :: (Arbitrary l, Arbitrary e) + => IO (Gr l e) +genRandomDAG = QC.generate randomDAG -- cgit