I recently started playing with Haskell, and though I don't entirely
grok concepts such as monads, I try to bulldoze my way through and
hope that by using Haskell long enough, the "eureka" light will turn
on in my head.
As such, I am trying to develop small programs in Haskell for fun. My
latest one is a cribbage point counter. I have successfully written
the library, and from my limited manual tests, it seems to function
well enough. Now however, I would try to push testing further and I
want to see what QuickCheck is all about.
I skimmed over the QuickCheck manual, but I haven't found what I was
looking for. Basically, I want to test my individual counting
functions (count pairs, count straights, count flush, etc.) with a
hand of five card. Here are my type declarations in the library,
followed by how I made Rank and Suit instances of Arbitrary
-- Types
data Suit = Clubs | Diamond | Heart | Spade
deriving (Show, Eq)
data Rank = Ace
| Two
| Three
| Four
| Five
| Six
| Seven
| Eight
| Nine
| Ten
| Jack
| Queen
| King
deriving (Show, Eq, Enum)
type Card = (Rank, Suit)
type Hand = [Card]
-- Arbitrary instances
instance Arbitrary Suit where
arbitrary = do
suit <- oneof $ map return [Clubs, Diamond, Heart, Spade]
return suit
instance Arbitrary Rank where
arbitrary = do
n <- choose (0, 12)
return (toEnum n)
(Feel free to suggest a better way to do arbitrary if my current code
isn't good.)
Next, I would need a way to generate a Hand, a list of *exactly* five
unique Cards. I am quite unsure about how to do that. Would anyone
be kind enough to help me?
Thank you,
Vincent.