@Test public void canRecognizeHigherFourOfAKind(){ CardSet cardSet = new CardSet( aCard(HEART, ACE), aCard(DIAMOND, ACE), aCard(CLUB, ACE), aCard(SPADE, ACE), aCard(HEART, TEN)); Hand hand = handResolver.hand(cardSet); assertThat(hand) .hasRanking(RANKING.FOUR_OF_A_KIND); }
public Hand hand(CardSet cardSet) { List<Card> handCards = cardSet.getSortedCards(); if (cardSet.ofOneColor() && cardSet.isSequential()) return new Hand(STRAIGHT_FLUSH, handCards); if (cardSet.ofOneColor() && !cardSet.isSequential()) return new Hand(FLUSH, handCards); if (cardSet.hasRanksDiversity(5) && cardSet.isSequential()) return new Hand(STRAIGHT, handCards); if (cardSet.hasRanksDiversity(2) && cardSet.containsRankWithMultiplicity(4)) return new Hand(FOUR_OF_A_KIND, handCards); if (cardSet.hasRanksDiversity(2) && !cardSet.containsRankWithMultiplicity(4)) return new Hand(FULL_HOUSE, handCards); if (cardSet.hasRanksDiversity(3) && cardSet.containsRankWithMultiplicity(3)) return new Hand(THREE_OF_A_KIND, handCards); if (cardSet.hasRanksDiversity(3) && cardSet.containsRankWithMultiplicity(1)) return new Hand(TWO_PAIRS, handCards); if (cardSet.hasRanksDiversity(4)){ return new Hand(ONE_PAIR, handCards); } return new Hand(HIGH_CARD, handCards); }
HandResolver { public Hand hand(CardSet cardSet) { List<Card> handCards = cardSet.getSortedCards(); if (cardSet.ofOneColor() && cardSet.isSequential()) return new Hand(STRAIGHT_FLUSH, handCards); if (cardSet.ofOneColor() && !cardSet.isSequential()) return new Hand(FLUSH, handCards); if (cardSet.hasRanksDiversity(5) && cardSet.isSequential()) return new Hand(STRAIGHT, handCards); if (cardSet.hasRanksDiversity(2) && cardSet.containsRankWithMultiplicity(4)) return new Hand(FOUR_OF_A_KIND, handCards); if (cardSet.hasRanksDiversity(2) && !cardSet.containsRankWithMultiplicity(4)) return new Hand(FULL_HOUSE, handCards); if (cardSet.hasRanksDiversity(3) && cardSet.containsRankWithMultiplicity(3)) return new Hand(THREE_OF_A_KIND, handCards); if (cardSet.hasRanksDiversity(3) && cardSet.containsRankWithMultiplicity(1)) return new Hand(TWO_PAIRS, handCards); if (cardSet.hasRanksDiversity(4)){ return new Hand(ONE_PAIR, handCards); } return new Hand(HIGH_CARD, handCards); } }
HandResolver { public Hand hand(CardSet cardSet) { List<Card> handCards = cardSet.getSortedCards(); if (cardSet.ofOneColor() && cardSet.isSequential()) return new Hand(STRAIGHT_FLUSH, handCards); if (cardSet.ofOneColor() && !cardSet.isSequential()) return new Hand(FLUSH, handCards); if (cardSet.hasRanksDiversity(5) && cardSet.isSequential()) return new Hand(STRAIGHT, handCards); if (cardSet.hasRanksDiversity(2) && cardSet.containsRankWithMultiplicity(4)) return new Hand(FOUR_OF_A_KIND, handCards); if (cardSet.hasRanksDiversity(2) && !cardSet.containsRankWithMultiplicity(4)) return new Hand(FULL_HOUSE, handCards); if (cardSet.hasRanksDiversity(3) && cardSet.containsRankWithMultiplicity(3)) return new Hand(THREE_OF_A_KIND, handCards); if (cardSet.hasRanksDiversity(3) && cardSet.containsRankWithMultiplicity(1)) return new Hand(TWO_PAIRS, handCards); if (cardSet.hasRanksDiversity(4)){ return new Hand(ONE_PAIR, handCards); } return new Hand(HIGH_CARD, handCards); }  }
HandResolver { public Hand hand(CardSet cardSet) { List<Card> handCards = cardSet.getSortedCards(); if (cardSet.ofOneColor() && cardSet.isSequential()) return new Hand(STRAIGHT_FLUSH, handCards); if (cardSet.ofOneColor() && !cardSet.isSequential()) return new Hand(FLUSH, handCards); if (cardSet.hasRanksDiversity(5) && cardSet.isSequential()) return new Hand(STRAIGHT, handCards); if (cardSet.hasRanksDiversity(2) && cardSet.containsRankWithMultiplicity(4)) return new Hand(FOUR_OF_A_KIND, handCards); if (cardSet.hasRanksDiversity(2) && !cardSet.containsRankWithMultiplicity(4)) return new Hand(FULL_HOUSE, handCards); if (cardSet.hasRanksDiversity(3) && cardSet.containsRankWithMultiplicity(3)) return new Hand(THREE_OF_A_KIND, handCards); if (cardSet.hasRanksDiversity(3) && cardSet.containsRankWithMultiplicity(1)) return new Hand(TWO_PAIRS, handCards); if (cardSet.hasRanksDiversity(4)){ return new Hand(ONE_PAIR, handCards); } return new Hand(HIGH_CARD, handCards); }  Hand hand(CardSet cardSet); }
HandResolver { public Hand hand(CardSet cardSet) { List<Card> handCards = cardSet.getSortedCards(); if (cardSet.ofOneColor() && cardSet.isSequential()) return new Hand(STRAIGHT_FLUSH, handCards); if (cardSet.ofOneColor() && !cardSet.isSequential()) return new Hand(FLUSH, handCards); if (cardSet.hasRanksDiversity(5) && cardSet.isSequential()) return new Hand(STRAIGHT, handCards); if (cardSet.hasRanksDiversity(2) && cardSet.containsRankWithMultiplicity(4)) return new Hand(FOUR_OF_A_KIND, handCards); if (cardSet.hasRanksDiversity(2) && !cardSet.containsRankWithMultiplicity(4)) return new Hand(FULL_HOUSE, handCards); if (cardSet.hasRanksDiversity(3) && cardSet.containsRankWithMultiplicity(3)) return new Hand(THREE_OF_A_KIND, handCards); if (cardSet.hasRanksDiversity(3) && cardSet.containsRankWithMultiplicity(1)) return new Hand(TWO_PAIRS, handCards); if (cardSet.hasRanksDiversity(4)){ return new Hand(ONE_PAIR, handCards); } return new Hand(HIGH_CARD, handCards); }  Hand hand(CardSet cardSet);  }