Beispiel #1
0
class Game_with_all_wrong_cards_on_top_of_the_deck(unittest.TestCase):
    def setUp(self):
        self.player1 = "Hans"
        self.player2 = "David"
        self.game = HanabiGame(self.player1)
        self.game.addPlayer(self.player2)
        self.game._setupDeckForTest(["R5", "O5", "G5", "B5", "P5", "R4", "O4", "G4", "B4", "P4"]) 
        self.game.start()

    def test_After_playing_2_cards_Game_is_not_over(self):
        self.game.play(1)
        self.game.play(1)
        self.assertFalse(self.game.isOver())

    def test_After_playing_3_cards_Game_is_over(self):
        self.game.play(1)
        self.game.play(1)
        self.game.play(2)
        self.assertTrue(self.game.isOver())
Beispiel #2
0
class Game_with_a_perfect_setup_on_table_hand_and_deck(unittest.TestCase):
    def setUp(self):
        self.player1 = "Hans"
        self.player2 = "David"
        self.game = HanabiGame(self.player1)
        self.game.addPlayer(self.player2)
        self.game._setupFireworksForTest(["O1","G1","G2","B1","B2","B3"])
        self.game._setupHandForTest(self.player1, ["R1","O2","G3","B4","B5"])
        self.game._setupHandForTest(self.player2, ["R2","O3","G4","R3","R4"])
        self.game._setupDeckForTest(["R5", "O4", "O5", "G4", "G5", "P1",  "P2", "P3",  "P4",  "P5"]) 
        self.game.start()

    def test_Player1_can_reorder_his_hand_cards(self):
        self.game.reorderHandCards(self.player1, [3,5,2,1,4])
        self.assertEqual(self.game.getHandCards(self.player1), ["G3","B5","O2","R1","B4"])

    def test_Player2_can_reorder_his_hand_cards(self):
        self.game.reorderHandCards(self.player2, [5,4,3,2,1])
        self.assertEqual(self.game.getHandCards(self.player2), ["R4","R3","G4","O3","R2"])

    def test_After_reordering_his_hand_cards_Player_still_his_turn(self):
        self.game.reorderHandCards(self.player1, [3,5,2,1,4])
        self.assertEqual(self.game.getActivePlayer(), self.player1)

    def test_Both_players_hold_5_cards(self):
        self.assertEqual(self.game.getNumberOfHandCards(self.player1), 5)
        self.assertEqual(self.game.getNumberOfHandCards(self.player2), 5)

    def test_Player1_hold_cards_R1_O2_G3_B4_B5(self):
        self.assertEqual(self.game.getHandCards(self.player1), ["R1","O2","G3","B4","B5"])

    def test_Hinting_player2_with_3_should_result_in_FTFTF(self):
        self.assertEqual(self.game.hint(self.player2, "3"), [False, True, False, True, False])

    def test_Hinting_player2_with_O_should_result_in_FTFFF(self):
        self.assertEqual(self.game.hint(self.player2, "O"), [False, True, False, False, False])

    def test_Firework_length_of_B_is_3(self):
        self.assertEqual(self.game.getFireworkLength("B"), 3)

    def test_After_player1_playing_his_first_card_five_times_and_player2_just_discarding_Score_is_11(self):
        for i in range(5):
            self.game.play(i+1)
            self.game.discard(1)
        self.assertEqual(self.game.getScore(), 11)

    def test_After_Hinting_2_times_and_completing_a_firework_Hints_should_be_7(self):
        for i in range(2):
            self.game.play(4+i)
            self.game.hint(self.player1,  "B")
        self.assertEqual(self.game.getHintsLeft(), 7)
        
    def test_After_playing_a_wrong_card_Thunderstorms_decreases_by_1(self):
        self.game.play(5)
        self.assertEqual(self.game.getThunderstormsLeft(), 2)
        
    def test_After_discards_a_card_with_8_hints_Hints_is_not_increased(self):
        self.game.discard(1)
        self.assertEqual(self.game.getHintsLeft(), 8)
        
    def test_After_hinting_2_times_Hints_is_decreased_by_2(self):
        self.game.hint(self.player2, "1")
        self.game.hint(self.player1, "1")
        self.game.play(1)
        self.game.play(1)
        self.assertEqual(self.game.getHintsLeft(), 6)
        
    def test_After_hinting_2_times_and_discarding_2_times_Hints_should_be_8_again(self):
        self.game.hint(self.player2, "1")
        self.game.hint(self.player1, "1")
        self.game.discard(1)
        self.game.discard(1)
        self.assertEqual(self.game.getHintsLeft(), 8)
        
    def test_After_playing_20_cards_Score_is_perfect(self):
        for i in range(10):
            self.game.play((i % 5) + 1)
            self.game.play((i % 5) + 1)
        self.assertEqual(self.game.getScore(), 25)

        
    def test_After_playing_20_cards_Game_is_over(self):
        for i in range(10):
            self.game.play((i % 5) + 1)
            self.game.play((i % 5) + 1)
        self.assertTrue(self.game.isOver())
        
    def test_First_5_cards_drawn_are_R5_O4_O5_G4_G5(self):
        self.game.discard(1)
        self.assertEqual(self.game._peekHandCard(1, self.player1), "R5")
        self.game.discard(1)
        self.assertEqual(self.game._peekHandCard(1, self.player2), "O4")
        self.game.discard(1)
        self.assertEqual(self.game._peekHandCard(1, self.player1), "O5")
        self.game.discard(1)
        self.assertEqual(self.game._peekHandCard(1, self.player2), "G4")
        self.game.discard(1)
        self.assertEqual(self.game._peekHandCard(1, self.player1), "G5")