Posts

Showing posts from March 26, 2019

Poker Game: Unit testing different poker hands without violating DRY principles

Image
0 $begingroup$ I'm currently in the process of refactoring an old poker game which violates many of the SOLID principles. I was trying to use the TDD approach to refactoring and I found myself having to hard code a player's hand every time I wrote a unit test for a specific poker hand check. For example, here are the unit tests for a one pair poker hand check: [Test] public void OnePair_IsLowPair_ReturnsTrue() { SuperCard testHand = { new CardClub(Rank.Ace), new CardSpade(Rank.Ace), new CardDiamond(Rank.Five), new CardHeart(Rank.Jack), new CardClub(Rank.Three) }; bool result = PokerHandEvaluator.OnePair(testHand); Assert.That(result == true); } [Test] public vo...