Example #1
0
    public Hand(string hand)
    {
        this.hand = hand;

        Cards = hand
                .Split(' ')
                .Select(card => new Card(card));

        Ranking = new RankingValidator().GetHighestRanking(this);


        var sortSymbols = Cards
                          .Select(card => card.Symbol)
                          .Select(symbol => (idx: Poker.SymbolOreder.IndexOf(symbol), symbol: symbol))
                          .OrderByDescending(data => data.idx);

        Symbols     = sortSymbols.Select(data => data.symbol);
        SymbolScore = Cards.Sum(card => card.SymbolId());
        BestSymbol  = sortSymbols
                      .FirstOrDefault()
                      .symbol;

        var sortSuits = Cards
                        .Select(card => card.Suit)
                        .Select(suit => (idx: Poker.SuitOreder.IndexOf(suit), suit: suit))
                        .OrderByDescending(data => data.idx);

        Suits    = sortSuits.Select(data => data.suit);
        BestSuit = sortSuits
                   .FirstOrDefault()
                   .suit;
    }
Example #2
0
    public void IsTwoPair_should_be_true(string pokerHand)
    {
        // Arrange
        var hand      = new Hand(pokerHand);
        var validator = new RankingValidator();

        // Act & Assert
        Assert.True(validator.IsTwoPair(hand));
    }
Example #3
0
    public void These_hands_should_not_straight(string pokerHand)
    {
        // Arrange
        var hand      = new Hand(pokerHand);
        var validator = new RankingValidator();

        // Act & Assert
        Assert.False(validator.IsStraight(hand));
    }
        public override ValidationResult Validate()
        {
            var rankingValidator = new RankingValidator();
            var validationResult = rankingValidator.Validate(this);

            SetValidationResult(validationResult);

            return(validationResult);
        }
Example #5
0
    public void StraightFlush_should_be_highest_ranking_than_straight_and_flush()
    {
        // Arrange
        var hand             = new Hand("7S 8S 9S 6S 10S");
        var rankingValidator = new RankingValidator();

        // Act
        var actual = rankingValidator.GetHighestRanking(hand);

        // Assert
        Assert.Equal(Ranking.StraightFlush, actual);
    }
Example #6
0
    public void FullHouse_should_be_highest_ranking_than_three_of_a_kind()
    {
        // Arrange
        var hand             = new Hand("4S 5H 4C 5D 4H");
        var rankingValidator = new RankingValidator();

        // Act
        var actual = rankingValidator.GetHighestRanking(hand);

        // Assert
        Assert.Equal(Ranking.FullHouse, actual);
    }