module Lecture01A where import Test.QuickCheck -- This is the file created during lecture 1 2009-10-27 -- David Sands, tr.im/tda451 euroRate = 10.21 price :: Double price = 5 euro,sek :: Double -> Double sek e = e * euroRate euro s = s / euroRate prop_EuroSek :: Double -> Bool prop_EuroSek e = euro (sek e) ~== e (~==) :: Double -> Double -> Bool x ~== y = abs (x - y) < epsilon where epsilon = 0.000001 prop_ApproxEq :: Double -> Double -> Bool prop_ApproxEq x y = if x ~== y then y ~== x else True {-- Notes: Although this test was good enough to catch the bug in the original definition of ~==, there is a problem when using this for random testing: most of the time randomly generated x and y will not be "approximately equal" so the test will not be useful. Soon we will see ways that we can fix this problem using QuickCheck --} absolute :: Integer -> Integer absolute x | x >= 0 = x absolute x | x < 0 = -x