Commits

Tony Morris  committed 3fb25f7

Testing

  • Participants
  • Parent commits 101781a

Comments (0)

Files changed (4)

File Cards/Card.hs

 
 import Cards.Suit
 import Cards.Rank
+import Test.QuickCheck
 
 data Card = Card {
   rank :: Rank,
 allCards = do r <- [Two ..]
               s <- [Spades ..]
               return (r ! s)
+
+instance Arbitrary Card where
+  arbitrary = elements allCards
+
+prop_ana_cata :: Card -> Bool
+prop_ana_cata c = card c (!) == c
+
+prop_rank :: Card -> Bool
+prop_rank c = card c const == rank c
+
+prop_suit :: Card -> Bool
+prop_suit c = card c (flip const) == suit c

File Cards/Rank.hs

 module Cards.Rank where
 
+import Test.QuickCheck
+
 data Rank = Two | Three | Four | Five | Six | Seven | Eight | Nine | Ten | Jack | Queen | King | Ace
   deriving (Eq, Ord, Enum, Bounded)
 
 
 rank' :: (Enum a) => Int -> a
 rank' = toEnum . subtract 2
+
+instance Arbitrary Rank where
+  arbitrary = elements [Two ..]
+
+prop_rank' :: Int -> Property
+prop_rank' n = n >= 2 && n <= 14 ==> fromEnum (rank' n :: Rank) + 2 == n

File Cards/Suit.hs

 module Cards.Suit where
 
+import Test.QuickCheck
+
 data Suit = Spades | Clubs | Hearts | Diamonds
   deriving (Eq, Enum, Bounded)
 
   show Clubs = "C"
   show Hearts = "H"
   show Diamonds = "D"
+
+instance Arbitrary Suit where
+  arbitrary = elements [Spades ..]
   Description:     Choose the new, split-up base package.
 
 Library
-  Build-Depends: base < 5 && >= 3, mtl
+  Build-Depends: base < 5 && >= 3, mtl, QuickCheck >= 2, HUnit
 
   GHC-Options:    -Wall
   Exposed-Modules: Cards.Card,