Skip to content

Commit

Permalink
Set 16b Ex 3: better description, more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
opqdonut committed May 23, 2022
1 parent e81bca2 commit 1379ad0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 4 additions & 3 deletions exercises/Set16b.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion exercises/Set16bTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])]

Expand Down

0 comments on commit 1379ad0

Please sign in to comment.