Beispiel #1
0
class TasteOfTheLanceTest(unittest.TestCase):
    def setUp(self):
        self.p1 = Knight("P1")
        self.p2 = Knight("P2")

        self.controller = Controller(self.p1, self.p2)
        self.charge = Charge(self.controller)
        when(self.controller).get_p1().thenReturn(self.p1)
        when(self.controller).get_p2().thenReturn(self.p2)

        self.held, sys.stdout = sys.stdout, StringIO()

    def tearDown(self):
        unstub()

    def test_round_p1_unhorsed(self):
        when(self.p1).get_unhorsed().thenReturn(True)

        self.controller.get_round_results(1)
        output = sys.stdout.getvalue().strip()
        self.assertEquals("Sir P2 wins by unhorsing Sir P1", output)

    def test_round_p2_unhorsed(self):
        when(self.p2).get_unhorsed().thenReturn(True)

        self.controller.get_round_results(1)
        output = sys.stdout.getvalue().strip()
        self.assertEquals("Sir P1 wins by unhorsing Sir P2", output)

    def test_round_p1_disqualified(self):
        when(self.p1).get_disqualified().thenReturn(True)

        self.controller.get_round_results(1)
        output = sys.stdout.getvalue().strip()
        self.assertEquals(
            "Sir P1 has failed to start twice and has been disqualified.",
            output)

    def test_round_p2_disqualified(self):
        when(self.p2).get_disqualified().thenReturn(True)

        self.controller.get_round_results(1)
        output = sys.stdout.getvalue().strip()
        self.assertEquals(
            "Sir P2 has failed to start twice and has been disqualified.",
            output)

    def test_final_results_p1_wins_points(self):
        when(self.p1).get_points().thenReturn(5)
        when(self.p2).get_points().thenReturn(0)

        self.controller.get_final_results()
        output = sys.stdout.getvalue().strip()
        self.assertEquals("Sir P1 wins 5 to 0", output)

    def test_final_results_p2_wins_points(self):
        when(self.p1).get_points().thenReturn(0)
        when(self.p2).get_points().thenReturn(5)

        self.controller.get_final_results()
        output = sys.stdout.getvalue().strip()
        self.assertEquals("Sir P2 wins 5 to 0", output)

    def test_final_results_tie_points(self):
        when(self.p1).get_points().thenReturn(5)
        when(self.p2).get_points().thenReturn(5)

        self.controller.get_final_results()
        output = sys.stdout.getvalue().strip()
        self.assertEquals("Sir P1 and Sir P2 tie with 5 points.", output)

    def test_round_p1_failed_to_start(self):
        self.p1.move(5)
        self.p2.move(10)
        self.p1.determine_failed_to_start()
        self.p2.determine_failed_to_start()
        self.assertNotEquals(0, self.p1.get_current_position())
        self.assertNotEquals(0, self.p2.get_current_position())

        self.controller.get_round_results(1)
        output = sys.stdout.getvalue().strip()
        self.assertEquals("Sir P1 failed to start and the round is over.",
                          output)

    def test_round_p2_failed_to_start(self):
        self.p1.move(10)
        self.p2.move(5)
        self.p1.determine_failed_to_start()
        self.p2.determine_failed_to_start()
        self.assertNotEquals(0, self.p1.get_current_position())
        self.assertNotEquals(0, self.p2.get_current_position())

        self.controller.get_round_results(1)
        output = sys.stdout.getvalue().strip()
        self.assertEquals("Sir P2 failed to start and the round is over.",
                          output)

    def test_round_points(self):
        when(self.p1).get_points().thenReturn(2)
        when(self.p2).get_points().thenReturn(3)
        self.controller.get_round_results(1)
        output = sys.stdout.getvalue().strip()
        self.assertEquals(
            "At the end of round 1 Sir P1 has 2 points, and Sir P2 has 3 points.",
            output)

    def test_reset_players(self):
        self.p1.move(5)
        self.p2.move(8)
        self.p1.determine_failed_to_start()
        self.p2.determine_failed_to_start()
        self.assertNotEquals(0, self.p1.get_current_position())
        self.assertNotEquals(0, self.p2.get_current_position())
        self.assertTrue(self.p1.get_failed_to_start())
        self.assertFalse(self.p2.get_failed_to_start())

        self.controller.reset_players_for_new_round()
        self.assertEquals(0, self.p1.get_current_position())
        self.assertEquals(0, self.p2.get_current_position())
        self.assertFalse(self.p1.get_failed_to_start())
        self.assertFalse(self.p2.get_failed_to_start())

    def test_full_round(self):
        self.controller.do_kick()
        self.assertNotEquals(0, self.p1.get_current_position())
        self.assertNotEquals(0, self.p2.get_current_position())

        when(self.p1).get_failed_to_start().thenReturn(False)
        when(self.p2).get_failed_to_start().thenReturn(False)
        self.controller.do_charge()

        when(self.p1).get_tactical_card().thenReturn(rps.COUNTER)
        when(self.p2).get_tactical_card().thenReturn(rps.SHIELD)
        self.controller.do_tactics_rps()
        self.assertTrue(self.p1.get_won_rps())

        when(self.p1).get_accept_heavy_blows().thenReturn(False)
        when(self.p2).get_accept_heavy_blows().thenReturn(False)
        self.controller.do_taste_of_the_lance()
        self.assertFalse(self.p1.get_unhorsed())
        self.assertFalse(self.p2.get_unhorsed())
Beispiel #2
0
class TasteOfTheLanceTest(unittest.TestCase):
    def setUp(self):
        self.p1 = Knight("P1")
        self.p2 = Knight("P2")
        controller = mock(Controller)
        self.lance = TasteOfTheLance(controller)

        when(self.p1).get_current_position().thenReturn(0)
        when(self.p1).get_bruises().thenReturn(0)

        when(controller).get_p1().thenReturn(self.p1)
        when(controller).get_p2().thenReturn(self.p2)

    def tearDown(self):
        unstub()

    def test_determine_strike_modifier_no_movement_no_tactical_no_bruises(
            self):
        self.lance.determine_strike_modifier(self.p1)
        self.assertEquals(0, self.p1.get_strike_modifier())

    def test_determine_strike_modifier_first_movement_bonus_no_tactical_no_bruises(
            self):
        when(self.p1).get_current_position().thenReturn(13)
        self.lance.determine_strike_modifier(self.p1)
        self.assertEquals(1, self.p1.get_strike_modifier())

    def test_determine_strike_modifier_second_movement_no_tactical_no_bruises(
            self):
        when(self.p1).get_current_position().thenReturn(16)
        self.lance.determine_strike_modifier(self.p1)
        self.assertEquals(2, self.p1.get_strike_modifier())

    def test_determine_strike_modifier_first_movement_bonus_with_tactical_no_bruises(
            self):
        when(self.p1).get_current_position().thenReturn(13)
        self.lance.determine_strike_modifier(self.p1, 1)
        self.assertEquals(2, self.p1.get_strike_modifier())

    def test_determine_strike_modifier_first_movement_bonus_with_tactical_with_three_bruises(
            self):
        when(self.p1).get_current_position().thenReturn(13)
        when(self.p1).get_bruises().thenReturn(3)
        self.lance.determine_strike_modifier(self.p1, 1)
        self.assertEquals(0, self.p1.get_strike_modifier())

    def test_strike_roll_glancing(self):
        when(self.p1).get_strike_modifier().thenReturn(0)
        when(random).randint(1, dice.D6).thenReturn(1)
        self.lance.strike_roll(self.p1, self.p2)
        self.assertEquals(0, self.p1.get_points())

    def test_strike_roll_light(self):
        when(self.p1).get_strike_modifier().thenReturn(0)
        when(random).randint(1, dice.D6).thenReturn(3)
        self.lance.strike_roll(self.p1, self.p2)
        self.assertEquals(2, self.p1.get_points())

    def test_strike_roll_heavy(self):
        when(self.p1).get_strike_modifier().thenReturn(0)
        when(random).randint(1, dice.D6).thenReturn(5)
        self.lance.strike_roll(self.p1, self.p2)
        self.assertEquals(3, self.p1.get_points())

    def test_strike_roll_accept_heavy_false(self):
        when(self.p1).get_strike_modifier().thenReturn(0)
        when(self.p2).get_accept_heavy_blows().thenReturn(False)
        when(random).randint(1, dice.D6).thenReturn(5)
        self.lance.strike_roll(self.p1, self.p2)
        self.assertEquals(2, self.p1.get_points())

    def test_heavy_blow_roll_add_bruise(self):
        when(random).randint(1, dice.D6).thenReturn(4)
        self.assertEquals(0, self.p2.get_bruises())
        self.lance.heavy_blow_roll(self.p2)
        self.assertEquals(1, self.p2.get_bruises())

    def test_heavy_blow_roll_unhorse(self):
        when(random).randint(1, dice.D6).thenReturn(6)
        self.lance.heavy_blow_roll(self.p2)
        self.assertTrue(self.p2.get_unhorsed())

    def test_lance_break_roll_no_break(self):
        when(random).randint(1, dice.D6).thenReturn(3)
        self.assertEquals(0, self.p1.get_points())
        self.lance.lance_break_roll(self.p1)
        self.assertEquals(0, self.p1.get_points())

    def test_lance_break_roll_break(self):
        when(random).randint(1, dice.D6).thenReturn(4)
        self.assertEquals(0, self.p1.get_points())
        self.lance.lance_break_roll(self.p1)
        self.assertEquals(1, self.p1.get_points())

    def test_do_taste_of_the_lance(self):
        when(random).randint(1, dice.D6).thenReturn(4)
        self.assertEquals(0, self.p1.get_points())
        self.assertEquals(0, self.p2.get_points())
        self.lance.do_taste_of_the_lance()
        self.assertEquals(2, self.p1.get_points())
        self.assertEquals(2, self.p2.get_points())