Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Div0 example: wibble.

  • Loading branch information...
commit b9f6a9849bc3f5cc2a1911208b6b969fbd660e09 1 parent 07bb2f4
Lee Pike authored

Showing 1 changed file with 13 additions and 13 deletions. Show diff stats Hide diff stats

  1. +13 13 examples/Div0.hs
26 examples/Div0.hs
@@ -19,22 +19,22 @@ data Exp = C Int
19 19 | Div Exp Exp
20 20 deriving (Read, Show, Typeable, Generic)
21 21
22   -instance SubTypes Exp
  22 +instance SubTypes Exp
23 23
24 24 eval :: Exp -> Maybe Int
25 25 eval (C i) = Just i
26 26 eval (Add e0 e1) =
27 27 liftM2 (+) (eval e0) (eval e1)
28   -eval (Div e0 e1) =
29   - let e = eval e1 in
30   - if e == Just 0 then Nothing
  28 +eval (Div e0 e1) =
  29 + let e = eval e1 in
  30 + if e == Just 0 then Nothing
31 31 else liftM2 div (eval e0) e
32 32
33 33 instance Arbitrary Exp where
34 34 arbitrary = sized mkM
35 35 where
36 36 mkM 0 = liftM C arbitrary
37   - mkM n = oneof [ liftM2 Add mkM' mkM'
  37 + mkM n = oneof [ liftM2 Add mkM' mkM'
38 38 , liftM2 Div mkM' mkM' ]
39 39 where mkM' = mkM =<< choose (0,n-1)
40 40
@@ -44,9 +44,9 @@ instance Arbitrary Exp where
44 44
45 45 -- property: so long as 0 isn't in the divisor, we won't try to divide by 0.
46 46 -- It's false: something might evaluate to 0 still.
47   -div_prop :: Exp -> Property
48   -div_prop e = divSubTerms e ==> eval e /= Nothing
49   --- div_prop e = property $ case x of
  47 +prop_div :: Exp -> Property
  48 +prop_div e = divSubTerms e ==> eval e /= Nothing
  49 +-- prop_div e = property $ case x of
50 50 -- Nothing -> True
51 51 -- Just True -> True
52 52 -- _ -> False
@@ -62,15 +62,15 @@ divSubTerms (Div e0 e1) = divSubTerms e0 && divSubTerms e1
62 62 -- div0 (A _ _) = property False
63 63 -- div0 _ = property True
64 64
65   --- test_prop m = case eval m of
  65 +-- prop_test m = case eval m of
66 66 -- Nothing -> True
67 67 -- Just i -> i < 5
68   -
  68 +
69 69
70 70 divTest :: IO ()
71   -divTest = smartCheck args div_prop
72   - where
73   - args = scStdArgs { qcArgs = stdArgs
  71 +divTest = smartCheck args prop_div
  72 + where
  73 + args = scStdArgs { qcArgs = stdArgs
74 74 -- { maxSuccess = 1000
75 75 -- , maxSize = 20 }
76 76 , format = PrintString

0 comments on commit b9f6a98

Please sign in to comment.
Something went wrong with that request. Please try again.