mirror of
https://github.com/iritmaximus/haskell.git
synced 2026-10-12 19:13:39 +03:00
Set 3a Ex 7&8: better error messages for infinite loops
This commit is contained in:
@@ -114,19 +114,19 @@ ex6_powers_large = m_powers 27 -- 5^27 still fits in Int
|
||||
|
||||
ex7_while_number = property $ do
|
||||
n <- choose (0,20 :: Integer)
|
||||
return $ counterexample ("while (/="++show n++") (+1) 0") $
|
||||
return $ counterexample ("while (/="++show n++") (+1) 0") $ within timeLimit $
|
||||
while (/=n) (+1) 0 ?== n
|
||||
|
||||
ex7_while_string = property $ do
|
||||
n <- word
|
||||
let w = n++n
|
||||
p = (/=n)
|
||||
return $ counterexample ("while (/="++show n++") tail "++show w) $
|
||||
return $ counterexample ("while (/="++show n++") tail "++show w) $ within timeLimit $
|
||||
while p tail w == n
|
||||
|
||||
ex8_whileRight_Left = forAllBlind word $ \w ->
|
||||
forAllBlind (choose (1::Int,10)) $ \i ->
|
||||
counterexample ("let f _ = Left " ++ show w ++ " in whileRight f " ++ show i) $
|
||||
counterexample ("let f _ = Left " ++ show w ++ " in whileRight f " ++ show i) $ within timeLimit $
|
||||
let f _ = Left w in whileRight f i ?== w
|
||||
|
||||
ex8_whileRight_step = property $ do
|
||||
@@ -137,7 +137,7 @@ ex8_whileRight_step = property $ do
|
||||
let log = ceiling . logBase 2 . fromIntegral
|
||||
divUp x y = ceiling (fromIntegral x / fromIntegral y)
|
||||
answer = start * 2 ^ (log (limit `divUp` start))
|
||||
return $ counterexample ("whileRight (step " ++ show limit ++ ") " ++ show start) $
|
||||
return $ counterexample ("whileRight (step " ++ show limit ++ ") " ++ show start) $ within timeLimit $
|
||||
whileRight (step limit) start ?== answer
|
||||
|
||||
ex9_1 = property $ do
|
||||
|
||||
Reference in New Issue
Block a user