Ejemplo n.º 1
0
        internal static void Main()
        {
            ICard card = new Card(CardFace.Ace, CardSuit.Clubs);
            Console.WriteLine(card);

            IHand hand = new Hand(new List<ICard>()
            {
                new Card(CardFace.Five, CardSuit.Diamonds),
                new Card(CardFace.Five, CardSuit.Spades),
                new Card(CardFace.Nine, CardSuit.Clubs),
                new Card(CardFace.Nine, CardSuit.Diamonds),
                new Card(CardFace.King, CardSuit.Hearts),
            });
            Console.WriteLine(hand);

            IHand otherHand = new Hand(new List<ICard>()
            {
                new Card(CardFace.Six, CardSuit.Hearts),
                new Card(CardFace.Six, CardSuit.Spades),
                new Card(CardFace.Three, CardSuit.Hearts),
                new Card(CardFace.Three, CardSuit.Diamonds),
                new Card(CardFace.King, CardSuit.Clubs),
            });
            Console.WriteLine(otherHand);

            IPokerHandsChecker checker = new PokerHandsChecker();
            Console.WriteLine(checker.IsStraightFlush(hand));
            Console.WriteLine(checker.IsStraight(hand));
            Console.WriteLine(checker.IsThreeOfAKind(hand));
            Console.WriteLine(checker.IsFlush(hand));
            Console.WriteLine(checker.IsOnePair(hand));
            Console.WriteLine(checker.IsTwoPair(hand));

            Console.WriteLine(checker.CompareHands(hand, otherHand));
        }
Ejemplo n.º 2
0
        public void TestOnHandWithNoCards()
        {
            var handWithNoCards = new Hand(new List<ICard>());
            var expected = false;
            var actual = this.pokerHandsChecker.IsOnePair(handWithNoCards);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 3
0
        public void ToStringHandWithNoCards()
        {
            var emptyHand = new Hand(new List<ICard>());
            var expected = string.Empty;
            var actual = emptyHand.ToString();

            Assert.AreEqual(expected, actual);
        }
        public void TestInitializeHand()
        {
            this.hand = new Hand();
            this.mockedImageOfCard = new Bitmap(4, 4);
            this.board = new Card[5];

            Assert.IsNotNull(board, "board should not be null!");
            Assert.IsNotNull(hand, "mockedImageOfCard should not be null!");
            Assert.IsNotNull(hand, "hand should not be null!");
        }
Ejemplo n.º 5
0
        public void ToStringHandWithOneCardTenOfClubs()
        {
            var handWithOneCardTenOfClubs = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ten, CardSuit.Clubs)
            });

            var expected = "10♣";
            var actual = handWithOneCardTenOfClubs.ToString();
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 6
0
        public void ToStringHandWithSameCards()
        {
            var handWithFiveCards = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ace, CardSuit.Hearts),
                new Card(CardFace.Ace, CardSuit.Hearts),
                new Card(CardFace.Ace, CardSuit.Hearts),
                new Card(CardFace.Ace, CardSuit.Hearts)
            });

            var expected = "A♥ A♥ A♥ A♥";
            var actual = handWithFiveCards.ToString();
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 7
0
        public void TestOnHandWithFourDifferentCardsOnEqualSuit()
        {
            var handWithFiveDifferentCardsOnEqualSuit = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ten, CardSuit.Diamonds),
                new Card(CardFace.Seven, CardSuit.Diamonds),
                new Card(CardFace.Two, CardSuit.Diamonds),
                new Card(CardFace.Eight, CardSuit.Diamonds)
            });

            var expected = false;
            var actual = this.pokerHandsChecker.IsOnePair(handWithFiveDifferentCardsOnEqualSuit);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        public void TestOnHandWithValidFullHouse()
        {
            var handWithFiveDifferentCardsOnEqualSuit = new Hand(new List<ICard>()
            {
                new Card(CardFace.Six, CardSuit.Clubs),
                new Card(CardFace.Six, CardSuit.Diamonds),
                new Card(CardFace.Six, CardSuit.Hearts),
                new Card(CardFace.Ace, CardSuit.Spades),
                new Card(CardFace.Ace, CardSuit.Clubs),
            });

            var expected = false;
            var actual = this.pokerHandsChecker.IsOnePair(handWithFiveDifferentCardsOnEqualSuit);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 9
0
        public void TestOnHandWithThreeEqualOnSuitOfFiveCards()
        {
            var handWithFiveDifferentCardsOnEqualSuit = new Hand(new List<ICard>()
            {
                new Card(CardFace.Six, CardSuit.Clubs),
                new Card(CardFace.Six, CardSuit.Clubs),
                new Card(CardFace.Six, CardSuit.Clubs),
                new Card(CardFace.Seven, CardSuit.Diamonds),
                new Card(CardFace.Ace, CardSuit.Clubs),
            });

            var expected = false;
            var actual = this.pokerHandsChecker.IsOnePair(handWithFiveDifferentCardsOnEqualSuit);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 10
0
        public void ToStringHandWithFiveCards()
        {
            var handWithFiveCards = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Seven, CardSuit.Diamonds),
                new Card(CardFace.Ace, CardSuit.Hearts),
                new Card(CardFace.Two, CardSuit.Spades),
                new Card(CardFace.Eight, CardSuit.Diamonds)
            });

            var expected = "10♣ 7♦ A♥ 2♠ 8♦";
            var actual = handWithFiveCards.ToString();
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 11
0
        public void TestOnHandWithTwoEqualCards()
        {
            var handWithTwoEqualCard = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Ace, CardSuit.Hearts),
                new Card(CardFace.Two, CardSuit.Spades),
                new Card(CardFace.Eight, CardSuit.Diamonds)
            });

            var expected = false;
            var actual = this.pokerHandsChecker.IsValidHand(handWithTwoEqualCard);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 12
0
        public void TestOnTwoPairАgainstLowerTwoPair()
        {
            var handWithUpperTwoPair = new Hand(new List<ICard>()
            {
                new Card(CardFace.Four, CardSuit.Spades),
                new Card(CardFace.Four, CardSuit.Clubs),
                new Card(CardFace.Three, CardSuit.Spades),
                new Card(CardFace.Three, CardSuit.Hearts),
                new Card(CardFace.King, CardSuit.Diamonds)
            });

            var handWithLowerTwoPair = new Hand(new List<ICard>()
            {
                new Card(CardFace.Four, CardSuit.Hearts),
                new Card(CardFace.Four, CardSuit.Diamonds),
                new Card(CardFace.Three, CardSuit.Diamonds),
                new Card(CardFace.Three, CardSuit.Clubs),
                new Card(CardFace.Ten, CardSuit.Spades)
            });

            var actual = this.pokerHandsChecker.CompareHands(handWithUpperTwoPair, handWithLowerTwoPair);
            Assert.AreEqual(LeftIsBigger, actual);
        }
Ejemplo n.º 13
0
        public void TestOnHandWithHighCard_2()
        {
            var handWithFiveDifferentCardsOnEqualSuit = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Jack, CardSuit.Diamonds),
                new Card(CardFace.Seven, CardSuit.Hearts),
                new Card(CardFace.King, CardSuit.Diamonds),
                new Card(CardFace.Ace, CardSuit.Clubs)
            });

            var expected = false;
            var actual = this.pokerHandsChecker.IsOnePair(handWithFiveDifferentCardsOnEqualSuit);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 14
0
        public void TestOnHandWithValidStraight_2()
        {
            var handWithFiveDifferentCardsOnEqualSuit = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ace, CardSuit.Clubs),
                new Card(CardFace.Two, CardSuit.Diamonds),
                new Card(CardFace.Three, CardSuit.Hearts),
                new Card(CardFace.Four, CardSuit.Diamonds),
                new Card(CardFace.Five, CardSuit.Clubs)
            });

            var expected = false;
            var actual = this.pokerHandsChecker.IsOnePair(handWithFiveDifferentCardsOnEqualSuit);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 15
0
        public void TestOnHandWithTwoEqualOfSixCardsOnEqualSuit()
        {
            var handWithTwoEqualOfSixCardsOnEqualSuit = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Seven, CardSuit.Clubs),
                new Card(CardFace.Ace, CardSuit.Clubs),
                new Card(CardFace.Two, CardSuit.Clubs),
                new Card(CardFace.Eight, CardSuit.Clubs)
            });

            var expected = false;
            var actual = this.pokerHandsChecker.IsOnePair(handWithTwoEqualOfSixCardsOnEqualSuit);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 16
0
        public void TestOnHandWithTwoEqualOfSixCardsWithDifferentFaces()
        {
            var handWithTwoEqualOfSixCards = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Seven, CardSuit.Diamonds),
                new Card(CardFace.Ace, CardSuit.Hearts),
                new Card(CardFace.Two, CardSuit.Spades),
                new Card(CardFace.Eight, CardSuit.Diamonds)
            });

            var expected = false;
            var actual = this.pokerHandsChecker.IsOnePair(handWithTwoEqualOfSixCards);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 17
0
        public void TestOnTwoPairAgainstHighCard()
        {
            var handWithTwoPair = new Hand(new List<ICard>()
            {
                new Card(CardFace.King, CardSuit.Spades),
                new Card(CardFace.King, CardSuit.Clubs),
                new Card(CardFace.Nine, CardSuit.Hearts),
                new Card(CardFace.Nine, CardSuit.Diamonds),
                new Card(CardFace.Ace, CardSuit.Hearts),
            });

            var actual = this.pokerHandsChecker.CompareHands(handWithTwoPair, this.handWithHighCard);
            Assert.AreEqual(LeftIsBigger, actual);
        }
        public void TestOnHandWithThreeOfAKind()
        {
            var handWithFiveDifferentCardsOnEqualSuit = new Hand(new List<ICard>()
            {
                new Card(CardFace.Six, CardSuit.Clubs),
                new Card(CardFace.Six, CardSuit.Diamonds),
                new Card(CardFace.Six, CardSuit.Hearts),
                new Card(CardFace.Seven, CardSuit.Diamonds),
                new Card(CardFace.Ace, CardSuit.Clubs),
            });

            var expected = true;
            var actual = this.pokerHandsChecker.IsThreeOfAKind(handWithFiveDifferentCardsOnEqualSuit);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 19
0
        public void TestOnHandWithValidStraightFlush_3()
        {
            var handWithFiveDifferentCardsOnEqualSuit = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Jack, CardSuit.Clubs),
                new Card(CardFace.Queen, CardSuit.Clubs),
                new Card(CardFace.King, CardSuit.Clubs),
                new Card(CardFace.Ace, CardSuit.Clubs)
            });

            var expected = false;
            var actual = this.pokerHandsChecker.IsOnePair(handWithFiveDifferentCardsOnEqualSuit);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 20
0
        public void TestOnHandWithHighCard_3()
        {
            var handWithTwoEqualOfSixCardsOnEqualSuit = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ace, CardSuit.Hearts),
                new Card(CardFace.King, CardSuit.Hearts),
                new Card(CardFace.Queen, CardSuit.Clubs),
                new Card(CardFace.Ten, CardSuit.Diamonds),
                new Card(CardFace.Two, CardSuit.Spades),
            });

            var expected = false;
            var actual = this.pokerHandsChecker.IsOnePair(handWithTwoEqualOfSixCardsOnEqualSuit);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 21
0
        public void TestOnThreeOfAKindАgainstLowerThreeOfAKind()
        {
            var handWithLowerThreeOfAKind = new Hand(new List<ICard>()
            {
                new Card(CardFace.Two, CardSuit.Clubs),
                new Card(CardFace.Two, CardSuit.Diamonds),
                new Card(CardFace.Two, CardSuit.Hearts),
                new Card(CardFace.Seven, CardSuit.Diamonds),
                new Card(CardFace.Ace, CardSuit.Spades),
            });

            var actual = this.pokerHandsChecker.CompareHands(this.handWithThreeOfAKind, handWithLowerThreeOfAKind);
            Assert.AreEqual(LeftIsBigger, actual);
        }
Ejemplo n.º 22
0
        public void TestOnStraightАgainstStraightFlush()
        {
            var handWithStraight = new Hand(new List<ICard>()
            {
                new Card(CardFace.Five, CardSuit.Diamonds),
                new Card(CardFace.Six, CardSuit.Spades),
                new Card(CardFace.Seven, CardSuit.Diamonds),
                new Card(CardFace.Eight, CardSuit.Spades),
                new Card(CardFace.Nine, CardSuit.Hearts)
            });

            var actual = this.pokerHandsChecker.CompareHands(handWithStraight, this.handWithStraightFlush);
            Assert.AreEqual(RightIsBigger, actual);
        }
Ejemplo n.º 23
0
        public void TestOnStraightАgainstLowerStraight()
        {
            var handWithLowerStraight = new Hand(new List<ICard>()
            {
                new Card(CardFace.Four, CardSuit.Diamonds),
                new Card(CardFace.Five, CardSuit.Hearts),
                new Card(CardFace.Six, CardSuit.Diamonds),
                new Card(CardFace.Seven, CardSuit.Clubs),
                new Card(CardFace.Eight, CardSuit.Clubs)
            });

            var actual = this.pokerHandsChecker.CompareHands(this.handWithStraight, handWithLowerStraight);
            Assert.AreEqual(LeftIsBigger, actual);
        }
Ejemplo n.º 24
0
        public void TestOnHandWithTwoEqualOfSixCardsOnFiveWithEqualFaces()
        {
            var handWithFiveDifferentCardsOnEqualSuit = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Ten, CardSuit.Diamonds),
                new Card(CardFace.Ten, CardSuit.Hearts),
                new Card(CardFace.Ten, CardSuit.Spades),
                new Card(CardFace.Ace, CardSuit.Diamonds)
            });

            var expected = false;
            var actual = this.pokerHandsChecker.IsFourOfAKind(handWithFiveDifferentCardsOnEqualSuit);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 25
0
        public void TestOnHandWithTwoEqualOfFiveCardsOnEqualSuit()
        {
            var handWithTwoEqualOfFiveCardsOnEqualSuit = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ten, CardSuit.Diamonds),
                new Card(CardFace.Ten, CardSuit.Diamonds),
                new Card(CardFace.Ace, CardSuit.Diamonds),
                new Card(CardFace.Two, CardSuit.Diamonds),
                new Card(CardFace.Eight, CardSuit.Diamonds)
            });

            var expected = false;
            var actual = this.pokerHandsChecker.IsFourOfAKind(handWithTwoEqualOfFiveCardsOnEqualSuit);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 26
0
        public void TestOnHandWithTwoEqualOnSuitOfFiveCards()
        {
            var handWithFiveDifferentCardsOnEqualSuit = new Hand(new List<ICard>()
            {
                new Card(CardFace.King, CardSuit.Clubs),
                new Card(CardFace.King, CardSuit.Clubs),
                new Card(CardFace.Nine, CardSuit.Hearts),
                new Card(CardFace.Nine, CardSuit.Diamonds),
                new Card(CardFace.Jack, CardSuit.Clubs),
            });

            var expected = false;
            var actual = this.pokerHandsChecker.IsFourOfAKind(handWithFiveDifferentCardsOnEqualSuit);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 27
0
        public void TestOnHandWithValidStraightFlush_1()
        {
            var handWithFiveDifferentCardsOnEqualSuit = new Hand(new List<ICard>()
            {
                new Card(CardFace.Five, CardSuit.Clubs),
                new Card(CardFace.Six, CardSuit.Clubs),
                new Card(CardFace.Seven, CardSuit.Clubs),
                new Card(CardFace.Eight, CardSuit.Clubs),
                new Card(CardFace.Nine, CardSuit.Clubs)
            });

            var expected = false;
            var actual = this.pokerHandsChecker.IsOnePair(handWithFiveDifferentCardsOnEqualSuit);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 28
0
        public void TestOnTwoPairАgainstUpperTwoPair_1()
        {
            var handWithUpperTwoPair = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ace, CardSuit.Diamonds),
                new Card(CardFace.Ace, CardSuit.Clubs),
                new Card(CardFace.Nine, CardSuit.Spades),
                new Card(CardFace.Nine, CardSuit.Clubs),
                new Card(CardFace.Seven, CardSuit.Spades),
            });

            var actual = this.pokerHandsChecker.CompareHands(this.handWithTwoPair, handWithUpperTwoPair);
            Assert.AreEqual(RightIsBigger, actual);
        }
Ejemplo n.º 29
0
        public void TestOnHandWithFiveEqualCards()
        {
            var handWithFiveEqualCards = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Ten, CardSuit.Clubs)
            });

            var expected = false;
            var actual = this.pokerHandsChecker.IsOnePair(handWithFiveEqualCards);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 30
0
        public void TestOnFlushАgainstUpperFlush_1()
        {
            var handWithUpperFlush = new Hand(new List<ICard>()
            {
                new Card(CardFace.King, CardSuit.Spades),
                new Card(CardFace.Seven, CardSuit.Spades),
                new Card(CardFace.Ace, CardSuit.Spades),
                new Card(CardFace.Two, CardSuit.Spades),
                new Card(CardFace.Eight, CardSuit.Spades)
            });

            var actual = this.pokerHandsChecker.CompareHands(this.handWithFlush, handWithUpperFlush);
            Assert.AreEqual(RightIsBigger, actual);
        }