Пример #1
0
        public void Test_OnePair_CreateInstance(string strCards, bool isValid)
        {
            var cards   = Utils.ParseCards(strCards);
            var onePair = OnePair.CreateInstance(cards);

            CreateInstanceHelper(onePair, HandRanks.OnePair, cards, isValid);
        }
Пример #2
0
        public void test_scores()
        {
            var highCard = new HighCard();

            Assert.AreEqual(0, highCard.Score);
            var onePair = new OnePair();

            Assert.AreEqual(1, onePair.Score);
            var twoPairs = new TwoPairs();

            Assert.AreEqual(2, twoPairs.Score);
            var set = new Set();

            Assert.AreEqual(3, set.Score);
            var straight = new Straight();

            Assert.AreEqual(4, straight.Score);
            var flush = new Flush();

            Assert.AreEqual(5, flush.Score);
            var fullHouse = new FullHouse();

            Assert.AreEqual(6, fullHouse.Score);
            var quads = new Quads();

            Assert.AreEqual(7, quads.Score);
            var straightFlush = new StraightFlush();

            Assert.AreEqual(8, straightFlush.Score);
            var royalFlush = new RoyalFlush();

            Assert.AreEqual(9, royalFlush.Score);
        }
Пример #3
0
        public void Test_OnePair_EqualityOperators(string strInputA, string strInputB, bool areEqual)
        {
            var cardsA = Utils.ParseCards(strInputA);
            var cardsB = Utils.ParseCards(strInputB);

            var OnePairOne = OnePair.CreateInstance(cardsA);
            var OnePairTwo = OnePair.CreateInstance(cardsB);

            EqualityOperatorsHelper(OnePairOne, OnePairTwo, areEqual);
        }
Пример #4
0
        public void Test_OnePair_ComparableTests(string strInputA, string strInputB, int comp)
        {
            var cardsA = Utils.ParseCards(strInputA);
            var cardsB = Utils.ParseCards(strInputB);

            var onePairOne = OnePair.CreateInstance(cardsA);
            var onePairTwo = OnePair.CreateInstance(cardsB);

            ComparableTestsHelper(onePairOne, onePairTwo, comp);
        }
        public void test()
        {
            var first = new OnePair();

            first.SetCards(new List <Card>
            {
                new Card(Suit.Clubs, Rank.Eight),
                new Card(Suit.Diamonds, Rank.Eight),
                new Card(Suit.Hearts, Rank.Two),
                new Card(Suit.Spades, Rank.Ace),
                new Card(Suit.Spades, Rank.Three),
                new Card(Suit.Diamonds, Rank.Six),
                new Card(Suit.Clubs, Rank.Seven),
            });
            Assert.IsTrue(first.IsPresent());
            var second = new OnePair();

            second.SetCards(new List <Card>
            {
                new Card(Suit.Clubs, Rank.Eight),
                new Card(Suit.Diamonds, Rank.Eight),
                new Card(Suit.Hearts, Rank.Two),
                new Card(Suit.Spades, Rank.Ace),
                new Card(Suit.Spades, Rank.Three),
                new Card(Suit.Diamonds, Rank.Six),
                new Card(Suit.Clubs, Rank.Seven),
            });
            Assert.IsTrue(second.IsPresent());
            var third = new OnePair();

            third.SetCards(new List <Card>
            {
                new Card(Suit.Clubs, Rank.Eight),
                new Card(Suit.Diamonds, Rank.Eight),
                new Card(Suit.Hearts, Rank.Two),
                new Card(Suit.Spades, Rank.Four),
                new Card(Suit.Spades, Rank.Three),
                new Card(Suit.Diamonds, Rank.Six),
                new Card(Suit.Clubs, Rank.Seven),
            });
            Assert.IsTrue(third.IsPresent());
            var hands = new List <IPokerHand>
            {
                first,
                second,
                third
            };

            Assert.AreEqual(0, first.CompareTo(second));
            var sortedList = new WinnerDetector().GetOrdered(hands);

            Assert.AreEqual(2, sortedList[0].Count());
            Assert.AreEqual(1, sortedList[1].Count());
            Assert.AreSame(third, sortedList[1].First());
        }
        public void one_pair_no()
        {
            var set   = new OnePair();
            var cards = new List <Card>
            {
                new Card(Suit.Clubs, Rank.Eight),
                new Card(Suit.Hearts, Rank.Five)
            };

            set.SetCards(cards);
            var result = set.IsPresent();

            Assert.IsFalse(result);
        }
Пример #7
0
        public void IsOnePair()
        {
            _cardHand = new List <Card> {
                new Card(CardRank.Ace, CardSuit.Clubs),
                new Card(CardRank.Eight, CardSuit.Diamonds),
                new Card(CardRank.Eight, CardSuit.Spades),
                new Card(CardRank.Two, CardSuit.Spades),
                new Card(CardRank.Jack, CardSuit.Spades)
            };

            var hand = new OnePair();

            Assert.IsTrue(hand.HasHand(_cardHand));
        }
Пример #8
0
        public void Test_OnePair_EqualityOperators_ForNull()
        {
            var cards   = Utils.ParseCards("4H AH AC 7D 8S");
            var onePair = OnePair.CreateInstance(cards);

            Assert.False(onePair.Equals(null));

            Assert.True((OnePair)null == (OnePair)null);
            Assert.False((OnePair)null == onePair);
            Assert.False(onePair == (OnePair)null);

            Assert.False((OnePair)null != (OnePair)null);
            Assert.True((OnePair)null != onePair);
            Assert.True(onePair != (OnePair)null);
        }
Пример #9
0
        public void OnePairUnitTests_1()
        {
            var onePairHands = new Dictionary <long, string>()
            {
                //{0x0008004002001000, string.Empty},                                      // 0000 0000 0000/1000 0000.0000 0/100.0000 0000.00/10 0000.0000 000/1.0000 0000.0000
                { 0x0000000002221111, string.Empty }                                         // 0000 0000 0000/0000 0000.0000 0/000.0000 0000.00/10 0010.0010 000/1.0001 0001.0001
            };

            var pht = new OnePair();

            foreach (var hand in onePairHands)
            {
                var ph = new PokerHand(hand.Key);
                Assert.True(pht.Parse(ph), hand.Value);
                Assert.Equal(PokerHandAnalyzer.Strength.OnePair, ph.Strength);
            }
        }
Пример #10
0
 public void SetUp()
 {
     _onePair = new OnePair();
 }
        private string GetScore(IPokerHand hand)
        {
            var royalFlush = new RoyalFlush(hand);

            if (royalFlush.IsHighRank)
            {
                return(royalFlush.Title);
            }

            var straightFlush = new StraightFlush(hand);

            if (straightFlush.IsHighRank)
            {
                return(straightFlush.Title);
            }

            var fourOfAKind = new FourOfAKind(hand);

            if (fourOfAKind.IsHighRank)
            {
                return(fourOfAKind.Title);
            }

            var fullHouse = new FullHouse(hand);

            if (fullHouse.IsHighRank)
            {
                return(fullHouse.Title);
            }

            var flush = new Flush(hand);

            if (flush.IsHighRank)
            {
                return(flush.Title);
            }

            var straight = new Straight(hand);

            if (straight.IsHighRank)
            {
                return(straight.Title);
            }

            var threeOfAKind = new ThreeOfAKind(hand);

            if (threeOfAKind.IsHighRank)
            {
                return(threeOfAKind.Title);
            }

            var twoPair = new TwoPair(hand);

            if (twoPair.IsHighRank)
            {
                return(twoPair.Title);
            }

            var onePair = new OnePair(hand);

            if (onePair.IsHighRank)
            {
                return(onePair.Title);
            }

            return("High Card");
        }