Skip to content

Commit 92d27bf

Browse files
committed
Set 3a Ex 7&8: better error messages for infinite loops
1 parent 8f6a8d3 commit 92d27bf

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

exercises/Set3aTest.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,19 @@ ex6_powers_large = m_powers 27 -- 5^27 still fits in Int
114114

115115
ex7_while_number = property $ do
116116
n <- choose (0,20 :: Integer)
117-
return $ counterexample ("while (/="++show n++") (+1) 0") $
117+
return $ counterexample ("while (/="++show n++") (+1) 0") $ within timeLimit $
118118
while (/=n) (+1) 0 ?== n
119119

120120
ex7_while_string = property $ do
121121
n <- word
122122
let w = n++n
123123
p = (/=n)
124-
return $ counterexample ("while (/="++show n++") tail "++show w) $
124+
return $ counterexample ("while (/="++show n++") tail "++show w) $ within timeLimit $
125125
while p tail w == n
126126

127127
ex8_whileRight_Left = forAllBlind word $ \w ->
128128
forAllBlind (choose (1::Int,10)) $ \i ->
129-
counterexample ("let f _ = Left " ++ show w ++ " in whileRight f " ++ show i) $
129+
counterexample ("let f _ = Left " ++ show w ++ " in whileRight f " ++ show i) $ within timeLimit $
130130
let f _ = Left w in whileRight f i ?== w
131131

132132
ex8_whileRight_step = property $ do
@@ -137,7 +137,7 @@ ex8_whileRight_step = property $ do
137137
let log = ceiling . logBase 2 . fromIntegral
138138
divUp x y = ceiling (fromIntegral x / fromIntegral y)
139139
answer = start * 2 ^ (log (limit `divUp` start))
140-
return $ counterexample ("whileRight (step " ++ show limit ++ ") " ++ show start) $
140+
return $ counterexample ("whileRight (step " ++ show limit ++ ") " ++ show start) $ within timeLimit $
141141
whileRight (step limit) start ?== answer
142142

143143
ex9_1 = property $ do

0 commit comments

Comments
 (0)