@@ -8,11 +8,12 @@ module Main (main) where
88
99import Control.Monad (replicateM )
1010import Data.Data (Proxy (.. ))
11- import Paths_antigen (getDataDir )
12- import System.FilePath ((</>) )
1311import Data.List (sort )
1412import Data.List.NonEmpty (NonEmpty (.. ))
13+ import qualified Data.Text as T
1514import Data.Word (Word32 , Word64 , Word8 )
15+ import Paths_antigen (getDataDir )
16+ import System.FilePath ((</>) )
1617import Test.AntiGen (
1718 AntiGen ,
1819 antiChoose ,
@@ -38,7 +39,6 @@ import Test.AntiGen.Internal (
3839 withAnnotation ,
3940 zapAntiGenResult ,
4041 )
41- import qualified Data.Text as T
4242import Test.Hspec (Spec , describe , hspec , it , shouldBe , shouldSatisfy )
4343import Test.Hspec.Golden (Golden (.. ))
4444import Test.Hspec.QuickCheck (prop )
@@ -109,8 +109,11 @@ annotatedPositive =
109109
110110annotatedTuple :: AntiGen (Int , Int )
111111annotatedTuple = do
112- x <- withAnnotation " first positive" $ (getPositive @ Int <$> arbitrary) |! (getNonPositive <$> arbitrary)
113- y <- withAnnotation " second positive" $ (getPositive @ Int <$> arbitrary) |! (getNonPositive <$> arbitrary)
112+ x <-
113+ withAnnotation " first positive" $ (getPositive @ Int <$> arbitrary) |! (getNonPositive <$> arbitrary)
114+ y <-
115+ withAnnotation " second positive" $
116+ (getPositive @ Int <$> arbitrary) |! (getNonPositive <$> arbitrary)
114117 pure (x, y)
115118
116119complexAnnotations :: AntiGen (Int , Int )
@@ -326,21 +329,19 @@ utilsSpec =
326329 chooseBoundedIntegralTest @ Word32
327330 chooseBoundedIntegralTest @ Int
328331 describe " replicateMNorm" $ do
329- prop " behaves like replicateM when not zapped" $ \ (n :: Int ) -> do
330- let n' = abs n `mod` 10
332+ prop " behaves like replicateM when not zapped" . forAll (choose (0 , 1000 )) $ \ n -> do
331333 let gen = antiPositive @ Int
332- fromNorm <- runAntiGen $ replicateMNorm n' gen
333- fromReplicateM <- runAntiGen $ replicateM n' gen
334+ fromNorm <- runAntiGen $ replicateMNorm n gen
335+ fromReplicateM <- runAntiGen $ replicateM n gen
334336 pure $
335337 counterexample (" replicateMNorm: " <> show fromNorm) $
336338 counterexample (" replicateM: " <> show fromReplicateM) $
337339 length fromNorm === length fromReplicateM
338- prop " produces correct length" $ \ (n :: Int ) -> do
339- let n' = abs n `mod` 20
340- result <- runAntiGen $ replicateMNorm n' (antiPositive @ Int )
341- pure $ length result === n'
340+ prop " produces correct length" . forAll (choose (0 , 1000 )) $ \ n -> do
341+ result <- runAntiGen $ replicateMNorm n (antiPositive @ Int )
342+ pure $ length result === n
342343 prop " all elements satisfy the generator property when not zapped" $ do
343- let n = 10
344+ n <- choose ( 0 , 1000 )
344345 result <- runAntiGen $ replicateMNorm n (antiPositive @ Int )
345346 pure $ all (> 0 ) result
346347
@@ -460,16 +461,24 @@ prettyZapResultSpec =
460461 describe " prettyZapResult" $ do
461462 it " no zaps" $
462463 golden " no_zaps" $
463- T. unpack $ prettyZapResult $ ZapResult () [] 0
464+ T. unpack $
465+ prettyZapResult $
466+ ZapResult () [] 0
464467 it " single zap without annotation" $
465468 golden " single_zap_no_annotation" $
466- T. unpack $ prettyZapResult $ ZapResult () [] 1
469+ T. unpack $
470+ prettyZapResult $
471+ ZapResult () [] 1
467472 it " single zap with simple annotation" $
468473 golden " single_zap_simple" $
469- T. unpack $ prettyZapResult $ ZapResult () [" positive" :| [] ] 1
474+ T. unpack $
475+ prettyZapResult $
476+ ZapResult () [" positive" :| [] ] 1
470477 it " single zap with nested annotation" $
471478 golden " single_zap_nested" $
472- T. unpack $ prettyZapResult $ ZapResult () [" root" :| [" child" , " leaf" ]] 1
479+ T. unpack $
480+ prettyZapResult $
481+ ZapResult () [" root" :| [" child" , " leaf" ]] 1
473482 it " multiple zaps with annotations" $
474483 golden " multiple_zaps" $
475484 T. unpack $
@@ -483,7 +492,9 @@ prettyZapResultSpec =
483492 3
484493 it " zaps with mixed annotated and unannotated" $
485494 golden " mixed_annotations" $
486- T. unpack $ prettyZapResult $ ZapResult () [" annotated" :| [] ] 3
495+ T. unpack $
496+ prettyZapResult $
497+ ZapResult () [" annotated" :| [] ] 3
487498
488499main :: IO ()
489500main = hspec $ do
0 commit comments