def test_torpedo_destroys_klingon(self):
        klingon = MockKlingon(500, 200)
        self.context.set_value_for_testing("target", klingon)
        Game.generator = MockRandom()

        self.game.fire_weapon(self.context)

        self.assertEqual(
            "Photons hit Klingon at 500 sectors with 825 units || Klingon destroyed! || ",
            self.context.get_all_output())
        self.assertEqual(7, self.game.torpedoes)
        self.assertTrue(klingon.delete_was_called())
Exemplo n.º 2
0
    def test_phasers_fired_klingon_destroyed(self):
        klingon = MockKlingon(distance=2000, energy=200)
        self.context.set_value_for_testing("amount", "1000")
        self.context.set_value_for_testing("target", klingon)
        Game.generator = MockRandom()

        self.game.fire_weapon(self.context)

        self.assertEqual(
            "Phasers hit Klingon at 2000 sectors with 400 units || Klingon destroyed! || ",
            self.context.get_all_output())
        self.assertEqual(self.energy_in_new_game - 1000,
                         self.game.EnergyRemaining())
        self.assertTrue(klingon.delete_was_called())
    def test_notified_if_no_torpedoes_remain(self):
        self.game.torpedoes = 0
        self.context.set_value_for_testing("target", MockKlingon(2000, 200))

        self.game.fire_weapon(self.context)

        self.assertEqual("No more photon torpedoes! || ",
                         self.context.get_all_output())
    def test_torpedo_damages_klingon(self):
        self.context.set_value_for_testing("target", MockKlingon(500, 2000))
        Game.generator = MockRandom()

        self.game.fire_weapon(self.context)

        self.assertEqual(
            "Photons hit Klingon at 500 sectors with 825 units || Klingon has 1175 remaining || ",
            self.context.get_all_output())
        self.assertEqual(7, self.game.torpedoes)
    def test_torpedo_misses_due_to_distance_and_clever_klingon_evasive_actions(
            self):
        distance_where_torpedoes_always_miss = 3500
        self.context.set_value_for_testing(
            "target", MockKlingon(distance_where_torpedoes_always_miss, 200))

        self.game.fire_weapon(self.context)

        self.assertEqual("Torpedo missed Klingon at 3500 sectors... || ",
                         self.context.get_all_output())
        self.assertEqual(7, self.game.torpedoes)
    def test_torpedo_misses_due_to_random_factors(self):
        distanceWhereRandomFactorsHoldSway = 2500
        self.context.set_value_for_testing(
            "target", MockKlingon(distanceWhereRandomFactorsHoldSway, 200))
        Game.generator = MockRandom()  # without this the test would often fail

        self.game.fire_weapon(self.context)

        self.assertEqual("Torpedo missed Klingon at 2500 sectors... || ",
                         self.context.get_all_output())
        self.assertEqual(7, self.game.torpedoes)
Exemplo n.º 7
0
    def test_phasers_fired_when_klingon_out_of_range_and_energy_expended_anyway(
            self):
        max_phaser_range = 4000
        out_of_range = max_phaser_range + 1
        self.context.set_value_for_testing("amount", "1000")
        self.context.set_value_for_testing("target", MockKlingon(out_of_range))

        self.game.fire_weapon(self.context)

        self.assertEqual(
            "Klingon out of range of phasers at " + str(out_of_range) +
            " sectors... || ", self.context.get_all_output())
        self.assertEqual(self.energy_in_new_game - 1000,
                         self.game.EnergyRemaining())
Exemplo n.º 8
0
    def test_phaser_damage_displays_remaining_and_minimum_damage_of_one(self):
        # defect #038429: eventually there will be a different minimum fired
        minimal_fired = "0"

        minimal_hit = "1"
        self.context.set_value_for_testing("amount", minimal_fired)
        self.context.set_value_for_testing("target", MockKlingon(2000, 200))
        Game.generator = MockRandom()

        self.game.fire_weapon(self.context)

        self.assertEqual(
            "Phasers hit Klingon at 2000 sectors with " + minimal_hit +
            " units || Klingon has 199 remaining || ",
            self.context.get_all_output())