Skip to content

Commit

Permalink
Deck types and full card deck initialization in place, along tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rami Karjalainen committed Sep 7, 2011
1 parent 9c74713 commit d2bb4c1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/PokerCardEvaluator/PokerCardEvaluator.fs
@@ -1,3 +1,12 @@
module PokerCardEvaluator
open Microsoft.FSharp.Reflection

let dummyForTest = false
type Suit = Heart | Diamond | Club | Spade
type Card = | Ace of Suit | King of Suit | Queen of Suit | Jack of Suit
| ValueCard of int * Suit

let GetFullCardsForSuit suit = seq { yield Ace(suit); yield King(suit); yield Queen(suit); yield Jack(suit)
for value in [2..10] do yield ValueCard(value, suit); }

let GetDeck = Seq.map (fun c -> GetFullCardsForSuit c) >> Seq.concat
let Deck = GetDeck [Heart;Diamond;Club;Spade]
18 changes: 17 additions & 1 deletion test/PokerCardEvaluatorTests/PokerCardEvaluationTest.fs
Expand Up @@ -3,5 +3,21 @@
open Xunit
open PokerCardEvaluator

let fullSuiteOf = function | x -> [Ace(x);King(x);Queen(x);Jack(x);ValueCard(2, x);
ValueCard(3, x);ValueCard(4, x);ValueCard(5, x);ValueCard(6, x);
ValueCard(7, x);ValueCard(8, x);ValueCard(9, x);ValueCard(10, x)]

[<Fact>]
let DeckContainsAllCards() = Assert.Equal (52, (Seq.length Deck))

[<Fact>]
let DeckContainsAllHearts() = Assert.Equal (fullSuiteOf Heart, Deck |> Seq.take 13 |> Seq.toList)

[<Fact>]
let DeckContainsAllDiamonds() = Assert.Equal (fullSuiteOf Diamond, Deck |> Seq.skip 13 |> Seq.take 13 |> Seq.toList)

[<Fact>]
let DeckContainsAllClubs() = Assert.Equal (fullSuiteOf Club, Deck |> Seq.skip 26 |> Seq.take 13 |> Seq.toList)

[<Fact>]
let SimpleTestingDummy() = Assert.False dummyForTest
let DeckContainsAllSpapes() = Assert.Equal (fullSuiteOf Spade, Deck |> Seq.skip 39 |> Seq.take 13 |> Seq.toList)

0 comments on commit d2bb4c1

Please sign in to comment.