在这种情况下,我不会立即关心内容。如果你对这个行为进行建模,你会得到一组卡片,这些卡片会变成一副牌(下面,aDeck
需要一个IEnumerable<Card>
)。然后你会洗牌并处理它们。
public class Deck
{
...
public Deck(IEnumerable<Card> cards) { ... Shuffle() ... }
public void DealTo(IDealable dealable, int numberOfCards) {...}
}
在这里,您创建一个简单的测试用例来处理一张卡片:
var deck = new Deck(new Card[] { <somecard> });
var hand = new Hand();
deck.DealTo(hand, 1);
Assert.AreEqual(<somecard>, hand[0]);
...加上你能想到的任何测试。
然后你创建一个扑克牌组:
public class PokerDeck : Deck
{
public PokerDeck() : base(<poker cards>)
}
// Pinochle, Uno, whatever
因此,要测试 PokerDeck,您可能会从以下内容开始:
var deck = new PokerDeck();
IDealable testHand = new TestDealable();
deck.DealTo(testHand, 52);
//assert all are distinct
//assert all make up expected deck
//assert is shuffled
// test with multiple players / "dealables"
模拟德州扑克将是这样的:
// first card
foreach(var player in players)
deck.DealTo(player, 1);
// second
foreach(var player in players)
deck.DealTo(player, 1);
// wait for action
// flop
deck.DealTo(burnPile, 1);
deck.DealTo(board, 3);
// wait for action
// turn
deck.DealTo(burnPile, 1);
deck.DealTo(board, 1);
// wait for action
// river
deck.DealTo(burnPile, 1);
deck.DealTo(board, 1);