[TestCase("QH QC 2C 2D 2H", "4S 5D 3H 3S 3D", false)] // Rule: Full-house (FH) beats Taok // TODO: Four-of-a-Kind (Foak) // TODO: Straight Flush public void WhenHandIsCompared(string win, string lose, bool expectTie) { var winningHand = new PokerHand(win); var losingHand = new PokerHand(lose); if (expectTie) { Assert.That(winningHand.CompareTo(losingHand), Is.EqualTo(0)); Assert.That(losingHand.CompareTo(winningHand), Is.EqualTo(0)); } else { Assert.That(winningHand.CompareTo(losingHand), Is.GreaterThan(0)); Assert.That(losingHand.CompareTo(winningHand), Is.LessThan(0)); } }
static void Main(string[] args) { Console.WriteLine("Beginning long-running tests with machine-learning test cases..."); using (var tr = new StreamReader(@"poker-hand-testing.data")) { int testNumber = 0; int failedTests = 0; string testcase; while (null != (testcase = tr.ReadLine())) { if (!string.IsNullOrWhiteSpace(testcase)) { ++testNumber; var testcaseArray = testcase.Split(','); var testcaseData = new int[10]; for (int i = 0; i < 10; i++) testcaseData[i] = int.Parse(testcaseArray[i]); var hand = BuildPokerHandFromData(testcaseData); List<Card> orderedCards; if ((int)hand.ParseRank(out orderedCards) != int.Parse(testcaseArray[10])) { ++failedTests; Console.WriteLine("Test case failed: {0}", hand.ToString()); } } } Console.WriteLine("{0} tests executed, {1} tests failed", testNumber, failedTests); } Console.WriteLine("Beginning tests from project Euler..."); using (var tr = new StreamReader(@"poker-hand-testing-project-euler.data")) { int iWonByPlayer1 = 0; string testcase; while (null != (testcase = tr.ReadLine())) { if (!string.IsNullOrWhiteSpace(testcase)) { var testcaseArray = testcase.Split(' '); var hand1 = new PokerHand(string.Join(" ", testcaseArray.Take(5))); var hand2 = new PokerHand(string.Join(" ", testcaseArray.Skip(5).Take(5))); if (hand1.CompareTo(hand2) > 0) ++iWonByPlayer1; } } Console.WriteLine(iWonByPlayer1 == 376 ? "Passed.": "Failed."); } }