2021-10-18
Utility functions. Noticing infinite loops.
Having little functions that run tests is better than retyping your test code every time. Automation means you will test more, and you don’t have to remember the correct results if your program shows them.
Infinite Loops
Print something before and after your checks to help you figure out when you have an infinite loop. I saw someone with
ck = do putStrLn "Begin"
putStrLn $ show checks
putStrLn "End"
The example check below never terminates (infinite loop)… try it
with the ck
function above and notice how you never see “End”.
f [] = False
f (x:xs)
| x /= 3 = f xs
| x == 3 = f (x:xs)
checks = [
f [2] == False
,f [3] == True
]