예제 #1
0
    def test_unit_attack(self):
        jack = Unit('Jack', 100, 20)
        bob = Unit('Bob', 100, 33)

        jack.attack(bob)

        self.assertEqual(jack.name, 'Jack')
        self.assertEqual(jack.hit_points, 83.5)
        self.assertEqual(jack.hit_points_limit, 100)
        self.assertEqual(jack.damage, 20)

        self.assertEqual(bob.name, 'Bob')
        self.assertEqual(bob.hit_points, 80)
        self.assertEqual(bob.hit_points_limit, 100)
        self.assertEqual(bob.damage, 33)

        bob.attack(jack)

        self.assertEqual(jack.name, 'Jack')
        self.assertEqual(jack.hit_points, 50.5)
        self.assertEqual(jack.hit_points_limit, 100)
        self.assertEqual(jack.damage, 20)

        self.assertEqual(bob.name, 'Bob')
        self.assertEqual(bob.hit_points, 70)
        self.assertEqual(bob.hit_points_limit, 100)
        self.assertEqual(bob.damage, 33)
예제 #2
0
    def test_attack_dead_unit(self):
        jack = Unit('Jack', 100, 20)
        bob = Unit('Bob', 100, 33)

        jack.take_damage(100)

        with self.assertRaises(UnitIsDead):
            bob.attack(jack)
예제 #3
0
    def test_unit_suicide(self):
        jack = Unit('Jack', 100, 120)

        jack.attack(jack)

        self.assertEqual(jack.name, 'Jack')
        self.assertEqual(jack.hit_points, 100)
        self.assertEqual(jack.hit_points_limit, 100)
        self.assertEqual(jack.damage, 120)