Ejemplo n.º 1
0
        public void HandIsStraightFlush5High()
        {
            //Arrange
            List <Card> cards = new List <Card>();

            cards.Add(new Card(Suits.Hearts, 3));
            cards.Add(new Card(Suits.Hearts, 2));
            cards.Add(new Card(Suits.Clubes, 3));
            cards.Add(new Card(Suits.Hearts, 5));
            cards.Add(new Card(Suits.Hearts, Constancts.CardValues.Ten));
            cards.Add(new Card(Suits.Hearts, 4));
            cards.Add(new Card(Suits.Hearts, Constancts.CardValues.Ace));


            //Act
            StraightFlush h             = new StraightFlush();
            Hand          straightFlush = h.IsMatch(cards).Value;

            //Assert
            Assert.IsNotNull(straightFlush);
            Assert.AreEqual(5, straightFlush.CardsInTheHand.Count);
            Assert.AreEqual <int>(5, straightFlush.CardsInTheHand[0].Value);
            Assert.AreEqual <int>(1, straightFlush.CardsInTheHand[4].Value);
            Assert.AreEqual("❤A", straightFlush.CardsInTheHand[4].ToString());
        }
Ejemplo n.º 2
0
        public void AceAsOne()
        {
            var hand1 = new StraightFlush();

            hand1.SetCards(Cards.New()
                           .Ace(Suit.Clubs)
                           .Two(Suit.Clubs)
                           .Three(Suit.Clubs)
                           .Four(Suit.Clubs)
                           .Five(Suit.Clubs)
                           .Nine(Suit.Spades)
                           .Ten(Suit.Spades));
            var hand2 = new StraightFlush();

            hand2.SetCards(Cards.New()
                           .Two(Suit.Clubs)
                           .Three(Suit.Clubs)
                           .Four(Suit.Clubs)
                           .Five(Suit.Clubs)
                           .Six(Suit.Clubs)
                           .Nine(Suit.Spades)
                           .Jack(Suit.Spades));
            Assert.IsTrue(hand1.IsPresent());
            Assert.IsTrue(hand2.IsPresent());
            Assert.Less(hand1, hand2);
        }
Ejemplo n.º 3
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);
        }
        public void Test_StraightFlush_CreateInstance(string strCards, bool isValid)
        {
            var cards         = Utils.ParseCards(strCards);
            var straightFlush = StraightFlush.CreateInstance(cards);

            CreateInstanceHelper(straightFlush, HandRanks.StraightFlush, cards, isValid);
        }
Ejemplo n.º 5
0
        public void GivenHandCardThenCheckIfStraightFlush(string handCard, bool expectedResult)
        {
            var handCardFormatted = Common.ConvertCardStringToList(handCard);

            var isStraightFlush = new StraightFlush().IsThisType(handCardFormatted);

            Assert.True(isStraightFlush == expectedResult);
        }
Ejemplo n.º 6
0
        public void ShouldSayIfStraightFlush()
        {
            Hand          theHand = new Hand("7H, 8H, 9H, 10H, JH");
            StraightFlush sFlush  = new StraightFlush();
            var           result  = sFlush.IsTypeOf(theHand);

            Assert.That(result, Is.EqualTo(true));
        }
        public void Test_StraightFlush_EqualityOperators(string strStraightFlushOne, string strStraightFlushTwo, bool areEqual)
        {
            var cardsA = Utils.ParseCards(strStraightFlushOne);
            var cardsB = Utils.ParseCards(strStraightFlushTwo);

            var straightFlushOne = StraightFlush.CreateInstance(cardsA);
            var straightFlushTwo = StraightFlush.CreateInstance(cardsB);

            EqualityOperatorsHelper(straightFlushOne, straightFlushTwo, areEqual);
        }
        public void Test_StraightFlush_ComparableTests(string strInputA, string strInputB, int comp)
        {
            var cardsA = Utils.ParseCards(strInputA);
            var cardsB = Utils.ParseCards(strInputB);

            var straightFlushOne = StraightFlush.CreateInstance(cardsA);
            var straightFlushTwo = StraightFlush.CreateInstance(cardsB);

            ComparableTestsHelper(straightFlushOne, straightFlushTwo, comp);
        }
Ejemplo n.º 9
0
            public void SpadesTwoToSix()
            {
                // ARRANGE
                var game = StraightFlushGameBuilder.Spades()
                           .From(Rank.TWO).To(Rank.SIX);

                // ACT
                var result = new StraightFlush().Evaluate(game);

                // ASSERT
                Assert.IsTrue(result.Success());
                Assert.AreSame(game.Cards, result.UsedCards);
            }
Ejemplo n.º 10
0
            public void DiamondsFiveToNine()
            {
                // ARRANGE
                var game = StraightFlushGameBuilder.Diamonds()
                           .From(Rank.FIVE).To(Rank.NINE);

                // ACT
                var result = new StraightFlush().Evaluate(game);

                // ASSERT
                Assert.IsTrue(result.Success());
                Assert.AreSame(game.Cards, result.UsedCards);
            }
Ejemplo n.º 11
0
        public void HandStraightFlushTestDuplicate()
        {
            //Arrange
            List <Card> cards = new List <Card>();

            cards.Add(new Card(Suits.Clubes, "A"));
            cards.Add(new Card(Suits.Clubes, "A"));

            //Act
            StraightFlush hand = new StraightFlush();

            //Assert
            Assert.ThrowsException <InvalidOperationException>(() => hand.IsMatch(cards));
        }
Ejemplo n.º 12
0
        public void IsStraightFlush()
        {
            _cardHand = new List <Card> {
                new Card(CardRank.Six, CardSuit.Clubs),
                new Card(CardRank.Five, CardSuit.Clubs),
                new Card(CardRank.Four, CardSuit.Clubs),
                new Card(CardRank.Three, CardSuit.Clubs),
                new Card(CardRank.Two, CardSuit.Clubs)
            };

            var hand = new StraightFlush();

            Assert.IsTrue(hand.HasHand(_cardHand));
        }
        public void Test_StraightFlush_EqualityOperators_ForNull()
        {
            var cards        = Utils.ParseCards("4H 5H 6H 7H 8H");
            var straintFlush = StraightFlush.CreateInstance(cards);

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

            Assert.True((StraightFlush)null == (StraightFlush)null);
            Assert.False((StraightFlush)null == straintFlush);
            Assert.False(straintFlush == (StraightFlush)null);

            Assert.False((StraightFlush)null != (StraightFlush)null);
            Assert.True((StraightFlush)null != straintFlush);
            Assert.True(straintFlush != (StraightFlush)null);
        }
Ejemplo n.º 14
0
            public void WrapAround()
            {
                // ARRANGE
                var game = new Game(
                    CardBuilder.King().Hearths(),
                    CardBuilder.Ace().Hearths(),
                    CardBuilder.Two().Hearths(),
                    CardBuilder.Three().Hearths(),
                    CardBuilder.Four().Hearths());

                // ACT
                var result = new StraightFlush().Evaluate(game);

                // ASSERT
                Assert.IsFalse(result.Success());
            }
        public void straightflush_no()
        {
            var set   = new StraightFlush();
            var cards = new List <Card>
            {
                new Card(Suit.Clubs, Rank.Ace),
                new Card(Suit.Diamonds, Rank.Ace),
                new Card(Suit.Spades, Rank.Ace),
                new Card(Suit.Hearts, Rank.King),
                new Card(Suit.Spades, Rank.Ten),
                new Card(Suit.Spades, Rank.King)
            };

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

            Assert.IsFalse(result);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Checks if 7 element StraightFlush combination is RoyalFlush
        /// </summary>
        /// <param name="cards">
        /// Array of 5 cards
        /// </param>
        /// <returns>
        /// Cards in RoyalFlush combination if exits otherwise null
        /// </returns>
        public override Combination Check(Card[] cards)
        {
            Combination straightFlush = new StraightFlush(null).Check(cards, false);

            if (straightFlush == null)
            {
                Data.Combinations[CombinationType.StraightFlush] = null;
                return(null);
            }
            Data.Combinations[CombinationType.StraightFlush] = straightFlush.Cards;

            if (straightFlush.Cards[0].Rank == CardRank.Ace && straightFlush.Cards[4].Rank == CardRank.King)
            {
                return(new Combination(Type, cards));
            }

            return(null);
        }
        public void straightflush_yes()
        {
            var set   = new StraightFlush();
            var cards = new List <Card>
            {
                new Card(Suit.Spades, Rank.King),
                new Card(Suit.Spades, Rank.Jack),
                new Card(Suit.Spades, Rank.Queen),
                new Card(Suit.Spades, Rank.Nine),
                new Card(Suit.Spades, Rank.Ten),
                new Card(Suit.Diamonds, Rank.Six),
                new Card(Suit.Spades, Rank.Two)
            };

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

            Assert.IsTrue(result);
        }
Ejemplo n.º 18
0
        public void HandIsNotStraightFlush()
        {
            //Arrange
            List <Card> cards = new List <Card>();

            cards.Add(new Card(Suits.Clubes, 9));
            cards.Add(new Card(Suits.Clubes, "J"));
            cards.Add(new Card(Suits.Clubes, 5));
            cards.Add(new Card(Suits.Hearts, "A"));
            cards.Add(new Card(Suits.Clubes, "A"));
            cards.Add(new Card(Suits.Clubes, 8));
            cards.Add(new Card(Suits.Clubes, 7));

            //Act
            StraightFlush straightFlush = new StraightFlush();

            //Assert
            Assert.IsFalse(straightFlush.IsMatch(cards).HasValue);
        }
Ejemplo n.º 19
0
        public void StraightFlush_6_Is_Better_Than_StraightFlush_5()
        {
            const long straightFlushHand1 = 0x000000000000700F;     // 0000 0000 0000/0000 0000.0000 0/000.0000 0000.00/00 0000.0000 011/1.0000 0000.1111
            const long straightFlushHand2 = 0x000000000000301F;     // 00000000 0000//0000 0000.0000 0/000.0000 0000.00/00 0000.0000 001/1.0000 0001.1111

            var pht1 = new StraightFlush();

            var ph1 = new PokerHand(straightFlushHand1);

            pht1.Parse(ph1);
            var ph2 = new PokerHand(straightFlushHand2);

            pht1.Parse(ph2);

            Assert.Equal(1, ph1.CompareTo(ph2));
            Assert.Equal(-1, ph2.CompareTo(ph1));
            ph2 = new PokerHand(straightFlushHand1);
            pht1.Parse(ph2);
            Assert.Equal(0, ph1.CompareTo(ph2));
        }
Ejemplo n.º 20
0
        public void StraightFlush_1()
        {
            var straightFlushHands = new Dictionary <long, string>()
            {
                { 0x000000000040201F, string.Empty },                                         // 00000000 0000//0000 0000.0000 0/000.0000 0000.00/00 0100.0000 001/0.0000 0001.1111
                { 0x00000000004020F8, string.Empty },
                { 0x00000F8000000000, string.Empty },
                { 0x000F800000000000, string.Empty },
                { 0x000000000040300F, "Hand got a `petite` straight flush i.e. 12345 " },     // 00000000 0000//0000 0000.0000 0/000.0000 0000.00/00 0100.0000 001/1.0000 0000.1111
            };

            var pht = new StraightFlush();

            foreach (var hand in straightFlushHands)
            {
                var ph = new PokerHand(hand.Key);
                Assert.True(pht.Parse(ph), hand.Value);
                Assert.Equal(PokerHandAnalyzer.Strength.StraightFlush, ph.Strength);
            }
        }
Ejemplo n.º 21
0
        public void StraightFlush_Is_Better_Than_FourOfAKind()
        {
            const long straightFlushHand = 0x000000000040201F;   // 00000000 0000//0000 0000.0000 0/000.0000 0000.00/00 0100.0000 001/0.0000 0001.1111
            const long fourOfAKindHand   = 0x0008004002001000;   // 0000 0000 0000/1000 0000.0000 0/100.0000 0000.00/10 0000.0000 000/1.0000 0000.0000

            var pht1 = new StraightFlush();
            var pht2 = new FourOfAKind();

            var ph1 = new PokerHand(straightFlushHand);

            pht1.Parse(ph1);
            var ph2 = new PokerHand(fourOfAKindHand);

            pht2.Parse(ph2);

            Assert.Equal(-1, ph1.CompareTo(ph2));
            Assert.Equal(1, ph2.CompareTo(ph1));
            ph2 = new PokerHand(straightFlushHand);
            pht1.Parse(ph2);
            Assert.Equal(0, ph1.CompareTo(ph2));
        }
Ejemplo n.º 22
0
        public void HandIsRoyalFlush()
        {
            //Arrange
            List <Card> cards = new List <Card>();

            cards.Add(new Card(Suits.Hearts, "A"));
            cards.Add(new Card(Suits.Hearts, 3));
            cards.Add(new Card(Suits.Hearts, "Q"));
            cards.Add(new Card(Suits.Clubes, 3));
            cards.Add(new Card(Suits.Hearts, "K"));
            cards.Add(new Card(Suits.Hearts, "T"));
            cards.Add(new Card(Suits.Hearts, "J"));

            //Act
            StraightFlush h             = new StraightFlush();
            Hand          straightFlush = h.IsMatch(cards).Value;

            //Assert
            Assert.IsNotNull(straightFlush);
            Assert.AreEqual(5, straightFlush.CardsInTheHand.Count);
        }
Ejemplo n.º 23
0
        public void HandIsStraightFlush6High()
        {
            //Arrange
            List <Card> cards = new List <Card>();

            cards.Add(new Card(Suits.Hearts, 3));
            cards.Add(new Card(Suits.Hearts, 2));
            cards.Add(new Card(Suits.Clubes, 3));
            cards.Add(new Card(Suits.Hearts, "A"));
            cards.Add(new Card(Suits.Hearts, 5));
            cards.Add(new Card(Suits.Hearts, 4));
            cards.Add(new Card(Suits.Hearts, 6));

            //Act
            StraightFlush h             = new StraightFlush();
            Hand          straightFlush = h.IsMatch(cards).Value;

            //Assert
            Assert.IsNotNull(straightFlush);
            Assert.AreEqual(5, straightFlush.CardsInTheHand.Count);
            Assert.AreEqual <int>(6, straightFlush.CardsInTheHand[0].Value);
            Assert.AreEqual <int>(2, straightFlush.CardsInTheHand[4].Value);
        }
Ejemplo n.º 24
0
        public void HandIsStraightFlushJackHigh()
        {
            //Arrange
            List <Card> cards = new List <Card>();

            cards.Add(new Card(Suits.Clubes, 9));
            cards.Add(new Card(Suits.Clubes, "J"));
            cards.Add(new Card(Suits.Clubes, "T"));
            cards.Add(new Card(Suits.Clubes, "K"));
            cards.Add(new Card(Suits.Clubes, "A"));
            cards.Add(new Card(Suits.Clubes, 8));
            cards.Add(new Card(Suits.Clubes, 7));

            //Act
            StraightFlush h             = new StraightFlush();
            Hand          straightFlush = h.IsMatch(cards).Value;

            //Assert
            Assert.IsNotNull(straightFlush);
            Assert.AreEqual(5, straightFlush.CardsInTheHand.Count);
            Assert.AreEqual <int>(11, straightFlush.CardsInTheHand[0].Value);
            Assert.AreEqual <int>(7, straightFlush.CardsInTheHand[4].Value);
            Assert.AreEqual(Constancts.HandRanks.StraightFlush, straightFlush.Rank);
        }
Ejemplo n.º 25
0
        public void SetupCardPattern()
        {
            var highCard = new HighCard();
            var onePair = new OnePair(highCard);
            var twoPair = new TwoPair(onePair);
            var threeOfAKind = new ThreeOfAKind(twoPair);
            var straight = new Straight(threeOfAKind);
            var flush = new Flush(straight);
            var fullHouse = new FullHouse(flush);
            var fourOfAKind = new FourOfAKind(fullHouse);
            var straightFlush = new StraightFlush(fourOfAKind, straight, flush);
            var royalFlush = new RoyalFlush(straightFlush, straight, flush);

            cardHandIdentifier = royalFlush;

            pokerEngine = new PokerEngine();
        }
        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");
        }
 public void Setup()
 {
     _straightFlush = new StraightFlush();
 }