@@ -4,24 +4,34 @@ import Prelude
44
55import Control.Monad.Eff (Eff )
66import Control.Monad.Eff.Console (CONSOLE , log , logShow )
7+ import Control.Monad.Eff.Exception (try , EXCEPTION )
78import Control.Monad.Eff.Random (RANDOM )
8-
99import Data.Array.Partial (head )
10+ import Data.Either (isLeft )
1011import Data.Foldable (sum )
1112import Data.Generic.Rep (class Generic )
1213import Data.Generic.Rep.Show (genericShow )
13-
1414import Partial.Unsafe (unsafePartial )
15-
15+ import Test.Assert (assert , ASSERT )
16+ import Test.QuickCheck (class Testable , quickCheck , (/=?), (<=?), (<?), (==?), (>=?), (>?))
1617import Test.QuickCheck.Arbitrary (arbitrary , genericArbitrary , class Arbitrary )
1718import Test.QuickCheck.Gen (Gen , vectorOf , randomSample' )
1819
1920data Foo a = F0 a | F1 a a | F2 { foo :: a , bar :: Array a }
2021derive instance genericFoo :: Generic (Foo a ) _
2122instance showFoo :: Show a => Show (Foo a ) where show = genericShow
22- instance arbitraryFoo :: Arbitrary a => Arbitrary (Foo a ) where arbitrary = genericArbitrary
23+ instance arbitraryFoo :: Arbitrary a => Arbitrary (Foo a ) where arbitrary = genericArbitrary
24+
2325
24- main :: Eff (console :: CONSOLE , random :: RANDOM ) Unit
26+ quickCheckFail
27+ :: forall t e
28+ . Testable t
29+ => t
30+ -> Eff (assert :: ASSERT , console :: CONSOLE , random :: RANDOM | e ) Unit
31+ quickCheckFail = assert <=< map isLeft <<< try <<< quickCheck
32+
33+
34+ main :: Eff (assert :: ASSERT , console :: CONSOLE , random :: RANDOM , exception :: EXCEPTION ) Unit
2535main = do
2636 log " Try with some little Gens first"
2737 logShow =<< go 10
@@ -36,6 +46,26 @@ main = do
3646 log " Generating via Generic"
3747 logShow =<< randomSample' 10 (arbitrary :: Gen (Foo Int ))
3848
49+ quickCheck \(x :: Int ) -> x <? x + 1
50+ quickCheck \(x :: Int ) -> x <=? x + 1
51+ quickCheck \(x :: Int ) -> x >=? x - 1
52+ quickCheck \(x :: Int ) -> x >? x - 1
53+ quickCheck \(x :: Int ) -> x + x ==? x * 2
54+ quickCheck \(x :: Int ) -> x + x /=? x * 3
55+
56+ quickCheck $ 1 ==? 1
57+ quickCheckFail $ 1 /=? 1
58+ quickCheck $ 1 <? 2
59+ quickCheckFail $ 1 >=? 2
60+ quickCheck $ 3 <=? 3
61+ quickCheckFail $ 3 >? 3
62+ quickCheck $ 3 >=? 3
63+ quickCheckFail $ 3 <? 3
64+ quickCheck $ 4 /=? 3
65+ quickCheckFail $ 4 ==? 3
66+ quickCheck $ 4 >? 3
67+ quickCheckFail $ 4 <=? 3
68+
3969 where
4070 go n = map (sum <<< unsafeHead) $ randomSample' 1 (vectorOf n (arbitrary :: Gen Int ))
4171
0 commit comments