def test_if_attack_chance_more_than_05(self): s1 = Soldier() s2 = Soldier() exp = s1.xp s1.attack_chance = Mock(return_value=0.6) s1.damage = Mock(return_value=8.5) s1.attack(s2) self.assertEqual(s2.hp, 91.5) self.assertEqual(s1.xp, exp + 1) self.assertFalse(s1.is_active)
class Tests_for_Soldier_class(TestCase): def setUp(self): self.soldier = Soldier(100, 0) R.seed(0) def test_attack_probability_in_0_1(self): self.soldier.experience = 50 attack_probability = self.soldier.attack_probability self.assertTrue(attack_probability >= 0 and attack_probability <= 1) def test_experience_not_more_50(self): self.soldier.experience = 100 self.assertEqual(self.soldier.experience, 50) def test_experience_not_less_0(self): self.soldier.experience = -100 self.assertEqual(self.soldier.experience, 0) def test_damage_inflicte(self): self.soldier.damage_inflicte(1) self.assertEqual(self.soldier.health, 99) def test_hit_return_True(self): self.assertEqual(self.soldier.hit, True) def test_beat_returns_damage(self): other_soldier = Soldier(100, 0) self.soldier.experience = 50 self.assertEqual(self.soldier.beat(other_soldier), self.soldier.damage) def test_experiance_was_increase(self): other_soldier = Soldier(100, 0) self.soldier.beat(other_soldier) self.assertEqual(self.soldier.experience, 1)
def setUp(self): self.soldier = Soldier(100, 0) R.seed(0)
def test_experiance_was_increase(self): other_soldier = Soldier(100, 0) self.soldier.beat(other_soldier) self.assertEqual(self.soldier.experience, 1)
def test_beat_returns_damage(self): other_soldier = Soldier(100, 0) self.soldier.experience = 50 self.assertEqual(self.soldier.beat(other_soldier), self.soldier.damage)
def test_if_damage_more_than_hp(self): s = Soldier() s.get_damage(150) self.assertEqual(s.hp, 0)
def setUp(self): self.soldier = Soldier()
def __init__(self, id, army_id): self.id = id self.army_id = army_id self.units = ([Soldier(i, self.id) for i in range(SOLDIERS_COUNT)] + [Vehicle(i, self.id) for i in range(VEHICLES_COUNT)])
def test_if_attack_chance_less_than_05(self, mock): mock.return_value = 0.1 s = Soldier() s2 = Soldier() s.attack(s2) self.assertEqual(s2.hp, 100)
def test_attack_cooldown_is_1_soldier_not_active(self): s1 = Soldier() s2 = Soldier() s1.attack(s2) self.assertFalse(s1.is_active)
def test_soldier_is_active(self): s = Soldier() self.assertTrue(s.is_active)
def test_attack_xp_raise(self): s1 = Soldier() s2 = Soldier() s1.attack(s2) self.assertEqual(s1.xp, 1)
def test_if_damage_is_float(self): s = Soldier() s.get_damage(4.5) self.assertEqual(s.hp, 95.5)
def test_if_hp_is_str(self): """Тест не должен отработать""" s = Soldier() s.hp = 'i' self.assertEqual(s.hp, 'i')
def create_soldier(cls): """This method returns Soldier class instance""" soldier = Soldier() return soldier
def test_if_soldier_xp_is_not_int(self): s = Soldier() s.xp = 'jmdf' self.assertIsInstance(s.xp, int)
def create_vehicle(self, count_of_operators): operators = list() for _ in range(count_of_operators): operators.append(Soldier()) return Vehicle(operators)
class TestClassSoldier(unittest.TestCase): """Testing the Soldier class""" def setUp(self): """Initialization of Soldier object""" self.sold = Soldier(0, 0) self.R = Random(seed) def test_attack_success(self): """Checking the attack success calculation""" self.sold.health = 0.7 self.sold.experience = 50 self.assertEqual(self.sold.attack_success, 0.5) def test_strength(self): """Checking the strength calculation""" self.sold.health = 0.7 self.sold.experience = 10 self.assertEqual(self.sold.strength, 0.9) def test_get_damage(self): """Checking the health calculation after getting damage damage is less than health """ self.sold.health = 0.8 self.sold.get_damage(0.32) self.assertEqual(self.sold.health, 0.48) def test_get_damage_out_of_limit(self): """Checking the health calculation after getting damage damage is more than health """ self.sold.health = 0.2 self.sold.get_damage(0.32) self.assertEqual(self.sold.health, 0) def test_damage(self): """Checking the damage calculation""" self.sold.experience = 27 self.assertEqual(self.sold.damage, 0.32) def test_level_up(self): """Checking the experience incrementation""" self.sold.experience = 12 self.sold.level_up() self.assertEqual(self.sold.experience, 13) def test_level_up_out_of_limit(self): """Checking the experience incrementation experience reached the max value """ self.sold.experience = 50 self.sold.level_up() self.assertEqual(self.sold.experience, 50) def test_is_active(self): """Checking the soldier's activity without any health""" self.sold.health = 0 self.assertFalse(self.sold.is_active)
class TestSoldier(unittest.TestCase): def setUp(self): self.soldier = Soldier() def test_init(self): self.assertEqual(self.soldier.exp, 0) self.assertEqual(self.soldier.recharge_time, 0) self.assertNotEqual(self.soldier.hp, 0) def test_inflict_damage(self): self.assertEqual(self.soldier.inflict_damage(), 0.05) self.soldier.gain_exp() self.assertEqual(round(self.soldier.inflict_damage(), 2), 0.06) def test_gain_exp(self): self.soldier.gain_exp() self.assertEqual(self.soldier.exp, 1) self.soldier.exp = 50 self.soldier.gain_exp() self.assertNotEqual(self.soldier.exp, 51) def test_get_damage(self): self.soldier.get_damage(20) self.assertEqual(self.soldier.hp, 80) def test_recharge(self): self.soldier.recharge() self.assertGreater(self.soldier.recharge_time, 0) def test_is_charged(self): self.assertTrue(self.soldier.is_charged) self.soldier.recharge() self.assertFalse(self.soldier.is_charged) def test_is_active(self): self.assertTrue(self.soldier.is_active) self.soldier.get_damage(100) self.assertFalse(self.soldier.is_active) def test_attack_success(self): probability = self.soldier.attack_success() self.assertTrue(0 <= probability <= 1)
def setUp(self): """Initialization of Soldier object""" self.sold = Soldier(0, 0) self.R = Random(seed)
class ProducerUnitSoldier(ProducerUnit): '''Production of soldier units''' __product = Soldier() def __init__(self, product=__product, **kwargs): ProducerUnit.__init__(self, product=product, **kwargs)
def test_if_soldier_xp_is_more_than_50(self): s = Soldier() s.xp = 100 self.assertNotEqual(s.xp, 100) self.assertEqual(s.xp, 50)