Exemple #1
0
    def test_convert_to_hand_should_convert_string_to_hand(self):
        card1 = Card(DeckSuite.HEARTS, DeckValue.EIGHT)
        card2 = Card(DeckSuite.TILES, DeckValue.TEN)
        card3 = Card(DeckSuite.PIKES, DeckValue.ACE)
        hand = Hand(card1, card2, card3)

        self.assertEqual(hand, convert_to_hand("H8 T10 PA"))
Exemple #2
0
 def test_is_four_of_kind_should_return_false(self):
     card1 = Card(DeckSuite.CLOVERS, DeckValue.JACK)
     card2 = Card(DeckSuite.TILES, DeckValue.JACK)
     card3 = Card(DeckSuite.HEARTS, DeckValue.JACK)
     card4 = Card(DeckSuite.TILES, DeckValue.KING)
     card5 = Card(DeckSuite.PIKES, DeckValue.ACE)
     self.assertFalse(
         HandsHelper.is_four_of_kind(card1, card2, card3, card4, card5))
Exemple #3
0
 def test_is_royal_flush_should_return_false(self):
     card1 = Card(DeckSuite.TILES, DeckValue.TEN)
     card2 = Card(DeckSuite.TILES, DeckValue.JACK)
     card3 = Card(DeckSuite.TILES, DeckValue.TWO)
     card4 = Card(DeckSuite.TILES, DeckValue.KING)
     card5 = Card(DeckSuite.TILES, DeckValue.ACE)
     self.assertFalse(
         HandsHelper.is_royal_flush(card1, card2, card3, card4, card5))
Exemple #4
0
 def test_is_flush_should_return_true_if_cards_are_of_one_kind(self):
     card1 = Card(DeckSuite.TILES, DeckValue.TWO)
     card2 = Card(DeckSuite.TILES, DeckValue.THREE)
     card3 = Card(DeckSuite.TILES, DeckValue.EIGHT)
     card4 = Card(DeckSuite.TILES, DeckValue.NINE)
     card5 = Card(DeckSuite.TILES, DeckValue.ACE)
     self.assertTrue(HandsHelper.is_flush(card1, card2, card3, card4,
                                          card5))
Exemple #5
0
 def test_is_straight_should_return_false(self):
     card1 = Card(DeckSuite.TILES, DeckValue.TWO)
     card2 = Card(DeckSuite.TILES, DeckValue.THREE)
     card3 = Card(DeckSuite.TILES, DeckValue.EIGHT)
     card4 = Card(DeckSuite.TILES, DeckValue.NINE)
     card5 = Card(DeckSuite.CLOVERS, DeckValue.ACE)
     self.assertFalse(
         HandsHelper.is_straight(card1, card2, card3, card4, card5))
Exemple #6
0
 def test_is_one_pair_should_return_false(self):
     card1 = Card(DeckSuite.CLOVERS, DeckValue.SEVEN)
     card2 = Card(DeckSuite.PIKES, DeckValue.JACK)
     card3 = Card(DeckSuite.HEARTS, DeckValue.QUEEN)
     card4 = Card(DeckSuite.TILES, DeckValue.THREE)
     card5 = Card(DeckSuite.PIKES, DeckValue.ACE)
     self.assertFalse(
         HandsHelper.is_one_pair(card1, card2, card3, card4, card5))
Exemple #7
0
 def test_is_full_house_should_return_true_for_three_and_two_cards_with_same_value(
         self):
     card1 = Card(DeckSuite.CLOVERS, DeckValue.JACK)
     card2 = Card(DeckSuite.PIKES, DeckValue.JACK)
     card3 = Card(DeckSuite.HEARTS, DeckValue.JACK)
     card4 = Card(DeckSuite.TILES, DeckValue.KING)
     card5 = Card(DeckSuite.PIKES, DeckValue.KING)
     self.assertTrue(
         HandsHelper.is_full_house(card1, card2, card3, card4, card5))
Exemple #8
0
 def test_is_four_of_kind_should_return_true_for_four_cards_with_same_values(
         self):
     card1 = Card(DeckSuite.CLOVERS, DeckValue.JACK)
     card2 = Card(DeckSuite.TILES, DeckValue.JACK)
     card3 = Card(DeckSuite.HEARTS, DeckValue.JACK)
     card4 = Card(DeckSuite.TILES, DeckValue.JACK)
     card5 = Card(DeckSuite.PIKES, DeckValue.ACE)
     self.assertTrue(
         HandsHelper.is_four_of_kind(card1, card2, card3, card4, card5))
Exemple #9
0
 def test_is_royal_flush_should_return_true_if_deck_is_flush_and_straight_flush(
         self):
     card1 = Card(DeckSuite.TILES, DeckValue.TEN)
     card2 = Card(DeckSuite.TILES, DeckValue.JACK)
     card3 = Card(DeckSuite.TILES, DeckValue.QUEEN)
     card4 = Card(DeckSuite.TILES, DeckValue.KING)
     card5 = Card(DeckSuite.TILES, DeckValue.ACE)
     self.assertTrue(
         HandsHelper.is_royal_flush(card1, card2, card3, card4, card5))
Exemple #10
0
 def test_is_two_pair_should_return_true_for_three_cards_with_same_value(
         self):
     card1 = Card(DeckSuite.CLOVERS, DeckValue.JACK)
     card2 = Card(DeckSuite.PIKES, DeckValue.JACK)
     card3 = Card(DeckSuite.HEARTS, DeckValue.ACE)
     card4 = Card(DeckSuite.TILES, DeckValue.ACE)
     card5 = Card(DeckSuite.PIKES, DeckValue.TWO)
     self.assertTrue(
         HandsHelper.is_two_pair(card1, card2, card3, card4, card5))
Exemple #11
0
    def test_select_strongest_hand_should_return_one_pair(self):
        card1 = Card(DeckSuite.CLOVERS, DeckValue.JACK)
        card2 = Card(DeckSuite.PIKES, DeckValue.JACK)
        card3 = Card(DeckSuite.HEARTS, DeckValue.QUEEN)
        card4 = Card(DeckSuite.TILES, DeckValue.THREE)
        card5 = Card(DeckSuite.PIKES, DeckValue.ACE)
        hand1 = Hand(card1, card2, card3, card4, card5)

        card6 = Card(DeckSuite.CLOVERS, DeckValue.JACK)
        card7 = Card(DeckSuite.PIKES, DeckValue.TWO)
        card8 = Card(DeckSuite.HEARTS, DeckValue.QUEEN)
        card9 = Card(DeckSuite.TILES, DeckValue.THREE)
        card10 = Card(DeckSuite.PIKES, DeckValue.ACE)
        hand2 = Hand(card6, card7, card8, card9, card10)

        self.assertEqual(hand1, select_strongest_hand(hand1, hand2))
Exemple #12
0
    def test_is_straight_should_return_true_if_cards_are_ordered(self):
        card1 = Card(DeckSuite.TILES, DeckValue.SIX)
        card2 = Card(DeckSuite.TILES, DeckValue.SEVEN)
        card3 = Card(DeckSuite.HEARTS, DeckValue.EIGHT)
        card4 = Card(DeckSuite.TILES, DeckValue.NINE)
        card5 = Card(DeckSuite.CLOVERS, DeckValue.TEN)
        self.assertTrue(
            HandsHelper.is_straight(card1, card2, card3, card4, card5))

        card6 = Card(DeckSuite.TILES, DeckValue.TEN)
        card7 = Card(DeckSuite.TILES, DeckValue.JACK)
        card8 = Card(DeckSuite.HEARTS, DeckValue.QUEEN)
        card9 = Card(DeckSuite.TILES, DeckValue.KING)
        card10 = Card(DeckSuite.CLOVERS, DeckValue.ACE)
        self.assertTrue(
            HandsHelper.is_straight(card6, card7, card8, card9, card10))
Exemple #13
0
    def test_convert_to_hands_should_return_array_of_hands_with_cards(self):
        card1 = Card(DeckSuite.HEARTS, DeckValue.EIGHT)
        card2 = Card(DeckSuite.TILES, DeckValue.TEN)
        card3 = Card(DeckSuite.PIKES, DeckValue.ACE)
        hand1 = Hand(card1, card2, card3)

        card4 = Card(DeckSuite.PIKES, DeckValue.JACK)
        card5 = Card(DeckSuite.HEARTS, DeckValue.QUEEN)
        card6 = Card(DeckSuite.CLOVERS, DeckValue.KING)
        hand2 = Hand(card4, card5, card6)

        actual = convert_to_hands("H8 T10 PA, PJ HQ CK")
        self.assertListEqual([hand1, hand2], actual)
Exemple #14
0
def convert_to_card(val: str) -> Card:
    return (Card(DeckSuite(val[0:1]), DeckValue(val[1:2])) if len(val) == 2
            else Card(DeckSuite(val[0:1]), DeckValue(val[1:3])))
Exemple #15
0
 def test_convert_to_card_should_create_card_from_2_chars(self):
     card1 = Card(DeckSuite.HEARTS, DeckValue.EIGHT)
     self.assertEqual(card1, convert_to_card("H8"))
Exemple #16
0
 def test_convert_to_card_should_create_card_from_3_chars(self):
     card1 = Card(DeckSuite.TILES, DeckValue.TEN)
     self.assertEqual(card1, convert_to_card("T10"))