Permalink
Browse files

Div0: helper functions.

  • Loading branch information...
leepike committed Jan 27, 2013
1 parent 039eff4 commit d5bc31c6bc54e07f7568ab7a5c4f93c75f67bc06
Showing with 21 additions and 5 deletions.
  1. +21 −5 examples/Div0.hs
View
@@ -38,9 +38,9 @@ instance Arbitrary Exp where
, liftM2 Div mkM' mkM' ]
where mkM' = mkM =<< choose (0,n-1)
- -- shrink (C i) = map C (shrink i)
- -- shrink (Add e0 e1) = [e0, e1]
- -- shrink (Div e0 e1) = [e0, e1]
+ shrink (C i) = map C (shrink i)
+ shrink (Add e0 e1) = [e0, e1]
+ shrink (Div e0 e1) = [e0, e1]
-- property: so long as 0 isn't in the divisor, we won't try to divide by 0.
-- It's false: something might evaluate to 0 still.
@@ -66,14 +66,30 @@ divSubTerms (Div e0 e1) = divSubTerms e0 && divSubTerms e1
-- Nothing -> True
-- Just i -> i < 5
-
divTest :: IO ()
divTest = smartCheck args prop_div
where
args = scStdArgs { qcArgs = stdArgs
-- { maxSuccess = 1000
-- , maxSize = 20 }
, format = PrintString
+ , extrap = True
}
----------------------------------------------------------------------------------
+-- Get the minimal offending sub-value.
+findVal :: Exp -> (Exp,Exp)
+findVal (Div e0 e1)
+ | eval e1 == Just 0 = (e0,e1)
+ | eval e1 == Nothing = findVal e1
+ | otherwise = findVal e0
+findVal a@(Add e0 e1)
+ | eval e0 == Nothing = findVal e0
+ | eval e1 == Nothing = findVal e1
+ | eval a == Just 0 = (a,a)
+findVal _ = error "not possible"
+
+divSubValue :: Exp
+divSubValue =
+ Add (Div (C 5) (C (-12))) (Add (Add (C 2) (C 4)) (Add (C 7) (Div (C 3) (Add (C (-5)) (C 5)))))
+
+--------------------------------------------------------------------------------

0 comments on commit d5bc31c

Please sign in to comment.