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.charge = Charge(controller)

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

    def tearDown(self):
        unstub()

    def test_roll_movement(self):
        when(random).randint(1, dice.D6).thenReturn(5)
        roll_val = self.charge.roll_movement()
        self.assertEquals(5, roll_val)

    def test_roll_movement_negative(self):
        when(random).randint(1, dice.D6).thenReturn(-1)
        roll_val = self.charge.roll_movement()
        self.assertEquals(1, roll_val)

    def test_limit_movement_no_contact(self):
        when(self.p1).get_current_position().thenReturn(12)
        when(self.p2).get_current_position().thenReturn(5)
        spaces_to_move = self.charge.limit_movement(6)
        self.assertEquals(6, spaces_to_move)

    def test_limit_movement_with_contact(self):
        when(self.p1).get_current_position().thenReturn(12)
        when(self.p2).get_current_position().thenReturn(8)
        spaces_to_move = self.charge.limit_movement(6)
        self.assertEquals(4, spaces_to_move)

    def test_at_point_of_contact_true(self):
        when(self.p1).get_current_position().thenReturn(17)
        when(self.p2).get_current_position().thenReturn(7)
        at_contact = self.charge.check_point_of_contact()
        self.assertFalse(self.p1.get_failed_to_start())
        self.assertFalse(self.p2.get_failed_to_start())
        self.assertTrue(at_contact)

    def test_at_point_of_contact_false(self):
        when(self.p1).get_current_position().thenReturn(12)
        when(self.p2).get_current_position().thenReturn(8)
        at_contact = self.charge.check_point_of_contact()
        self.assertFalse(at_contact)

    def test_fail_start_p1(self):
        when(self.p1).get_current_position().thenReturn(6)
        when(self.p2).get_current_position().thenReturn(18)
        self.charge.do_charge()
        self.assertTrue(self.p1.get_failed_to_start())
        self.assertFalse(self.p2.get_failed_to_start())

    def test_fail_start_p2(self):
        when(self.p1).get_current_position().thenReturn(18)
        when(self.p2).get_current_position().thenReturn(6)
        self.charge.do_charge()
        self.assertFalse(self.p1.get_failed_to_start())
        self.assertTrue(self.p2.get_failed_to_start())

    def test_do_charge(self):
        when(random).randint(1, dice.D6).thenReturn(5)
        self.assertEquals(0, self.p1.get_current_position())
        self.assertEquals(0, self.p2.get_current_position())
        self.charge.do_charge()
        self.assertEquals(14, self.p1.get_current_position())
        self.assertEquals(10, self.p2.get_current_position())