From 763ba7108e22a71cbc3d2241fde32fc98eaf9552 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Wed, 20 Jul 2011 15:08:54 +0000 Subject: [PATCH] Test genNumsToTotal by using it to generate a datatype. This is because QuickCheck 2 no longer exports the "generate" function; since it's a test generator anyway, we may as well test it by using it to test something trivial. --- flow/FlowGraphTest.hs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/flow/FlowGraphTest.hs b/flow/FlowGraphTest.hs index 7b20324..99ed409 100644 --- a/flow/FlowGraphTest.hs +++ b/flow/FlowGraphTest.hs @@ -620,6 +620,15 @@ genNumsToTotal n = do ch <- choose (1,n) chs <- genNumsToTotal (n-ch) return (ch:chs) +-- | Helper type to test genNumsToTotal. +data NumsTotalling = NumsTotalling Int [Int] + deriving (Show) + +instance Arbitrary NumsTotalling where + arbitrary = do n <- arbitrary + ns <- genNumsToTotal n + return $ NumsTotalling n ns + -- | A function that takes a generator for an item, and generates a list of those, -- dividing up the size at random. The list will be length log_2(N) on average, I think. genList :: (Int -> GenL a) -> Int -> GenL [a] @@ -836,9 +845,9 @@ testModify = where g' = A.Only emptyMeta g - -- | This tests our genNumsToTotal function, which is itself a test generator; nasty! - prop_gennums :: Int -> QCProp - prop_gennums n = generate 0 (mkStdGen 0) (genNumsToTotal n >>* sum) *==* n + -- | This tests our genNumsToTotal function, which is itself a test generator. + prop_gennums :: NumsTotalling -> QCProp + prop_gennums (NumsTotalling n ns) = n *==* sum ns -- | Repeatedly pairs the map with each element of the powerset of its keys helper :: Monad m => Map.Map Meta (A.Structured a -> m (A.Structured a)) -> [(Map.Map Meta (A.Structured a -> m (A.Structured a)), [Meta])]