Set 16b Ex 3: better description, more tests

This commit is contained in:
Joel Kaasinen
2022-05-23 15:59:20 +03:00
parent e81bca2c3c
commit 1379ad0ce9
2 changed files with 13 additions and 4 deletions
+4 -3
View File
@@ -36,9 +36,10 @@ composeRates rate1 rate2 = todo
-- * Name Last - for last names
-- * Name Full - for full names
--
-- In this exercise, you should define the types First, Last, Full and
-- Name. Then implement the functions fromName, toFirst and toLast. Give
-- the functions the commented-out types
-- In this exercise, you should define the phantom types First, Last
-- and Full, and the parameterised type Name. Then implement the
-- functions fromName, toFirst and toLast. Give the functions the
-- commented-out types
--
-- Examples:
-- fromName (toFirst "bob") ==> "bob"
+9 -1
View File
@@ -57,6 +57,14 @@ letter = choose ('a','z')
word = listOf1 letter
assertPhantom (DataType vars cs) =
conjoin [counterexample " should have no constructors (be a phantom type)" $ null cs
,counterexample " should have no type parameters" $ null vars]
ex3_phantom_First = $(reifyType "First") assertPhantom
ex3_phantom_Last = $(reifyType "Last") assertPhantom
ex3_phantom_Full = $(reifyType "Full") assertPhantom
ex3_v = forAll word $ \w ->
conjoin [counterexample ("fromName (toFirst "++show w++")") $
fromName (toFirst w) ?== w
@@ -110,7 +118,7 @@ ex5_c = counterexample "render (Money 1.0 :: Money CHF)" $
tests = [(1,"pounds",[ex1_t,ex1_v])
,(2,"composeRates",[ex2_v, ex2_t1, ex2_t2])
,(3,"firstlastfull1",[ex3_v, ex3_t1, ex3_t2])
,(3,"firstlastfull1",[ex3_phantom_First, ex3_phantom_Last, ex3_phantom_Full, ex3_v, ex3_t1, ex3_t2])
,(4,"firstlastfull2",[ex4_v1, ex4_t1, ex4_v2, ex4_t2])
,(5,"Render currency",[ex5_e, ex5_u, ex5_c])]