Code for Bob

From HaskellWiki
Revision as of 02:53, 21 November 2006 by BrettGiles (talk | contribs) (Code For Bob moved to Code for Bob)

Jump to: navigation, search
#!/usr/local/bin/runhugs
import "/home/ralf/hudak_soe/HUnit-1.0/HUnit"
newtype Lover a = Lover {loverDiary :: (Name,a)}
    deriving Show 
type Name = String

createLover :: Name -> a -> (Lover a)
createLover name times = Lover (name,times)

chainAffairs :: Num a => Lover a -> Lover a -> Lover a
chainAffairs (Lover (names, oldtimes)) (Lover (newlady, newtimes)) = 
    Lover ((newlady ++ names), (oldtimes + newtimes))

startAffairWith :: Num a => Name -> Lover b -> Lover a
startAffairWith name (Lover (names,times)) = Lover (name,0)

jenny = startAffairWith "Jenny "
luisa = startAffairWith "Luisa "
antonia = startAffairWith "Antonia "

bob = createLover "Paula " 5

oneMoreTime :: Num a => Lover a -> Lover a
oneMoreTime (Lover (name, times)) = Lover (name, times+1)

test1 = TestCase (assertEqual "this test" ("Lover{loverDiary=(\"Paula \",5)}") 
		  (show bob))
--test1 = TestCase (assertEqual "this test" () ())
tests = TestList [TestLabel "test1" test1]

main = do runTestTT tests
	  do
	  let
	  bob' = (oneMoreTime bob)
	  test2 = TestCase (assertEqual 
			    "this test" ("Lover{loverDiary=(\"Paula \",6)}") 
			    (show bob'))
	  tests2 = TestList [TestLabel "test2" test2]
	  in
	  runTestTT tests2