Пример #1
0
class TestPlaying(unittest.TestCase):
    def setUp(self):
        self.profile = Profile()
        self.floor = Floor()
        self.level = Level(self.profile, 1)
        self.level.floor = self.floor
        self.level.load_level = mock.Mock()
        self.level.is_failed = mock.Mock(return_value=False)

    def test_load_level_once_when_playing_multiple_turns(self):
        self.level.play(2)
        self.level.load_level.assert_called_once_with()

    def test_prepare_turn_and_play_turn_each_object_specified_amount(self):
        unit = Warrior()
        unit.prepare_turn = mock.Mock()
        unit.perform_turn = mock.Mock()
        self.floor.add(unit, 0, 0, 'north')
        self.level.play(2)
        unit.prepare_turn.assert_called_with()
        unit.perform_turn.assert_called_with()
        self.assertEqual(2, unit.prepare_turn.call_count)
        self.assertEqual(2, unit.perform_turn.call_count)

    def test_should_return_immediately_when_passed(self):
        unit = Warrior()
        unit.turn = mock.Mock()
        self.floor.add(unit, 0, 0, 'north')
        self.level.is_passed = mock.Mock(return_value=True)
        self.level.play(2)

    def test_call_fxn_in_play_for_each_turn(self):
        self.i = 0

        def foo():
            self.i += 1

        self.level.play(2, foo)
        self.assertEqual(self.i, 2)

    def test_should_count_down_time_bonus_once_each_turn(self):
        self.level.time_bonus = 10
        self.level.play(3)
        self.assertEqual(self.level.time_bonus, 7)

    def test_should_count_down_time_bonus_to_zero(self):
        self.level.time_bonus = 2
        self.level.play(5)
        self.assertEqual(self.level.time_bonus, 0)

    def test_should_have_a_pretty_score_calculation(self):
        self.assertEqual(self.level.score_calculation(123, 45),
                         "123 + 45 = 168")

    def test_should_not_have_score_calc_when_starting_score_is_zero(self):
        self.assertEqual(self.level.score_calculation(0, 45), "45")
Пример #2
0
class TestPlaying(unittest.TestCase):
    def setUp(self):
        self.profile = Profile()
        self.floor = Floor()
        self.level = Level(self.profile, 1)
        self.level.floor = self.floor
        self.level.load_level = mock.Mock()
        self.level.is_failed = mock.Mock(return_value=False)

    def test_load_level_once_when_playing_multiple_turns(self):
        self.level.play(2)
        self.level.load_level.assert_called_once_with()

    def test_prepare_turn_and_play_turn_each_object_specified_amount(self):
        unit = Warrior()
        unit.prepare_turn = mock.Mock()
        unit.perform_turn = mock.Mock()
        self.floor.add(unit, 0, 0, 'north')
        self.level.play(2)
        unit.prepare_turn.assert_called_with()
        unit.perform_turn.assert_called_with()
        self.assertEqual(2, unit.prepare_turn.call_count)
        self.assertEqual(2, unit.perform_turn.call_count)

    def test_should_return_immediately_when_passed(self):
        unit = Warrior()
        unit.turn = mock.Mock()
        self.floor.add(unit, 0, 0, 'north')
        self.level.is_passed = mock.Mock(return_value=True)
        self.level.play(2)

    def test_call_fxn_in_play_for_each_turn(self):
        self.i = 0

        def foo():
            self.i += 1

        self.level.play(2, foo)
        self.assertEqual(self.i, 2)

    def test_should_count_down_time_bonus_once_each_turn(self):
        self.level.time_bonus = 10
        self.level.play(3)
        self.assertEqual(self.level.time_bonus, 7)

    def test_should_count_down_time_bonus_to_zero(self):
        self.level.time_bonus = 2
        self.level.play(5)
        self.assertEqual(self.level.time_bonus, 0)

    def test_should_have_a_pretty_score_calculation(self):
        self.assertEqual(self.level.score_calculation(123, 45),
                         "123 + 45 = 168")

    def test_should_not_have_score_calc_when_starting_score_is_zero(self):
        self.assertEqual(self.level.score_calculation(0, 45), "45")