コード例 #1
0
ファイル: PokerHand.cs プロジェクト: lordjeb/kata-pokerhands
        /// <summary>
        /// Returns less than one if _this_ hand is the losing hand.
        /// Returns greater than one if _this_ hand is the winning hand.
        /// Returns zero if the hands are a tie.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public int CompareTo(PokerHand other)
        {
            List<Card> rankedAndOrderedCards;
            List<Card> otherRankedAndOrderedCards;
            var thisRank = ParseRank(out rankedAndOrderedCards);
            var otherRank = other.ParseRank(out otherRankedAndOrderedCards);
            if (thisRank != otherRank)
            {
                return thisRank - otherRank;
            }

            Debug.WriteLine("Comparing ({0})({1})", ShortNotationFromCardList(rankedAndOrderedCards), ShortNotationFromCardList(otherRankedAndOrderedCards));

            Card highCard;
            Card otherHighCard;
            int idx = 0;
            do
            {
                highCard = rankedAndOrderedCards[idx];
                otherHighCard = otherRankedAndOrderedCards[idx];
                idx++;
            } while (highCard.Value == otherHighCard.Value && idx < rankedAndOrderedCards.Count);

            return (int)highCard.Value - (int)otherHighCard.Value;
        }
コード例 #2
0
        public void WhenHandIsRanked(string shortNotation, PokerHand.Rank expectedResult, string expectedOrderedList)
        {
            var hand = new PokerHand(shortNotation);
            var remainingCards = new List<Card>();

            var actualResult = hand.ParseRank(out remainingCards);

            Assert.That(actualResult, Is.EqualTo(expectedResult));
            Assert.That(remainingCards, Is.EqualTo(PokerHand.CardListFromShortNotation(expectedOrderedList)));
        }