lundi 30 novembre 2015

How would I perform property-based testing on a card game's Deal function?

I am studying property-based testing and am curious how I would apply this type of testing to a BlackJack game's Deal function.

Here's a unit test (aka: Example-based test):

[<Test>]
let ``deal two cards`` () =
    let hand = 2
    let dealPlayer cardCount = 
        [for i in [1..cardCount] -> shuffleDeck.Pop] 
        |> Seq.toList

    (dealPlayer hand).Length |> should equal (2)

What would be an example of a property-based test?

  • Would I test that the two cards are within a range of 4 suits? (i.e. Spades, Diamonds, Hearts, Clubs) Wouldn't relying on a static type already ensure that for me?

  • Would I test that the two cards are within the range of numbers or faces? (i.e. 2..10;Jack;Queen;King;Ace) Again, wouldn't relying on a static type already ensure that for me?

Again, what should I consider when performing property-based tests for a blackjack game?

Aucun commentaire:

Enregistrer un commentaire