Exemple #1
0
    def test_attack(self, mock_inflict_damage):
        mock_inflict_damage.return_value = 10
        enemy = Squad('s2', [Soldier()])
        squad = Squad('s1', [Soldier()])

        squad.attack(enemy)
        self.assertEqual(enemy.units[0].health, 90)
Exemple #2
0
    def test_get_damage_with_two_operators(self):
        vehicle = Vehicle([Soldier(), Soldier()])

        vehicle.get_damage(100)
        self.assertEqual(vehicle.health, 140)
        for operator in vehicle.operators:
            self.assertEqual(operator.health, 80)
Exemple #3
0
    def test_get_damage(self, mock_active_operators):
        vehicle = Vehicle([Soldier(), Soldier(), Soldier()])
        mock_active_operators.return_value = vehicle.operators

        vehicle.get_damage(100)
        self.assertEqual(vehicle.health, 140)
        for operator in vehicle.operators:
            self.assertLess(operator.health, 100)

        mock_active_operators.return_value = []
        with self.assertRaises(IndexError):
            vehicle.get_damage(100)
Exemple #4
0
 def setUp(self):
     self.soldier = Soldier()
Exemple #5
0
class TestSoldier(unittest.TestCase):
    def setUp(self):
        self.soldier = Soldier()

    def test_get_damage(self):
        self.soldier.get_damage(50)
        self.assertEqual(self.soldier.health, 50)

    def test_get_damage_max(self):
        self.soldier.get_damage(150)
        self.assertEqual(self.soldier.health, 0)

    def test_is_active(self):
        self.assertTrue(self.soldier.is_active)

    def test_is_active_negative(self):
        self.soldier.get_damage(100)
        self.assertFalse(self.soldier.is_active)

    def test_inflict_damage(self):
        self.assertEqual(self.soldier.inflict_damage(), 0.5)

    def test_get_experience(self):
        self.soldier.get_experience(1)
        self.assertEqual(self.soldier.experience, 1)

    def test_get_experience_max(self):
        self.soldier.get_experience(55)
        self.assertEqual(self.soldier.experience, 50)

    def test_is_available(self):
        self.assertTrue(self.soldier.is_available)
        self.soldier.recharge()
        self.assertFalse(self.soldier.is_available)

    def test_recharge(self):
        self.assertEqual(self.soldier.recharge_time, 0)
        self.soldier.recharge()
        self.assertNotEqual(self.soldier.recharge_time, 0)
Exemple #6
0
 def create(self, data=None):
     return Soldier()
Exemple #7
0
    def test_get_damage_max(self):
        vehicle = Vehicle([Soldier(), Soldier()])

        vehicle.get_damage(1000)
        self.assertFalse(vehicle.is_active)
Exemple #8
0
    def test_get_damage_with_one_operator(self):
        vehicle = Vehicle([Soldier()])

        vehicle.get_damage(100)
        self.assertEqual(vehicle.health, 140)
        self.assertEqual(vehicle.operators[0].health, 60)