mirror of
https://github.com/iritmaximus/haskell.git
synced 2026-10-12 19:13:39 +03:00
Set 16b Ex 3: better description, more tests
This commit is contained in:
+4
-3
@@ -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"
|
||||
|
||||
@@ -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])]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user