class TestWeapon(unittest.TestCase): def setUp(self): self.sword = Weapon('Sword', 15, 0.4) def test_init_weapon(self): self.assertEqual(self.sword.type, 'Sword') self.assertEqual(self.sword.damage, 15) self.assertEqual(self.sword.critical_strike_percent, 0.4) def test_critical_hit(self): critical_hit_used = False critical_hit_not_used = False while True: if self.sword.critical_hit(): critical_hit_used = True return while True: if not self.sword.critical_hit(): critical_hit_not_used = True return self.assertTrue(critical_hit_used) self.assertFalse(critical_hit_not_used) def test_critical_raises_error(self): with self.assertRaises(ValueError): axe = Weapon('Axe', 25, 2)
def test_critical_hit_true_and_false(self): new_weapon = Weapon("Mighty Axe", 25, 0.2) results = [] for i in range(10): results.append(new_weapon.critical_hit()) self.assertIn(True, results) self.assertIn(False, results)
def test_weapon_no_crit(self): new_weapon = Weapon("alwayscrit", 10, 0) for i in range(0, 1000): iscrit = new_weapon.critical_hit() if iscrit: break self.assertFalse(iscrit)
def test_critical_hit(self): weapon = Weapon("axe", 10, 0.5) results = [] for x in range(1000): results.append(weapon.critical_hit()) self.assertTrue(True in results) self.assertTrue(False in results)
def test_weapon_critical_hit(self): new_weapon = Weapon("alwayscrit", 10, 1) for i in range(0, 10): iscrit = new_weapon.critical_hit() if not iscrit: break self.assertTrue(iscrit)
class TestWeapon(unittest.TestCase): def setUp(self): self.axe = Weapon("Mighty Axe", 25, 0.2) def test_weapon_init(self): self.assertEqual(self.axe.type, "Mighty Axe") self.assertEqual(self.axe.damage, 25) self.assertEqual(self.axe.critical_strike_percent, 0.2) def test_value_error(self): with self.assertRaises(ValueError): Weapon("Mighty Axe", 25, 2) def test_critical_hit(self): has_been_true = False has_been_false = False for i in range(1000): if self.axe.critical_hit(): has_been_true = True else: has_been_false = True self.assertTrue(has_been_true) self.assertTrue(has_been_false)
def test_weapon_critical(self): new_weapon = Weapon("Ico", 100, 0.2) self.assertEqual(new_weapon.name, "Ico") self.assertEqual(new_weapon.damage, 100) self.assertEqual(new_weapon.critical_strike_percent, 0.2) weapontests = [] for n in range(1, 11): weapontests.append(new_weapon.critical_hit()) self.assertIn(200, weapontests) self.assertIn(False, weapontests)
def test_critical_hit(self): test_weapon = Weapon("axe", 20, 0.2) is_False = False is_True = False for i in range(100): if test_weapon.critical_hit(): is_True = True else: is_False = True self.assertTrue(is_True) self.assertTrue(is_False)
class TestWeapon(unittest.TestCase): def setUp(self): self.axe = Weapon("axe", 12, 1) def test_init(self): self.assertEqual("axe", self.axe.type) self.assertEqual(12, self.axe.damage) self.assertEqual(1, self.axe.critical_strike_percent) def test_critical_hit_one(self): self.axe.critical_strike_percent = 1 self.assertFalse(self.axe.critical_hit()) def test_critical_hit_two(self): self.axe.critical_strike_percent = 2 self.assertTrue(self.axe.critical_hit()) def test_critical_hit_other(self): self.axe.critical_strike_percent = 13 self.assertFalse(self.axe.critical_hit())
class WeaponTests(unittest.TestCase): def setUp(self): self.the_weapon = Weapon("Mighty Axe", 25, 0.2) def test_weapon_init(self): self.assertEqual("Mighty Axe", self.the_weapon.type) self.assertEqual(25, self.the_weapon.damage) self.assertEqual(0.2, self.the_weapon.critical_strike_percent) def test_value_error(self): with self.assertRaises(ValueError): Weapon("", 25, 20) def test_critical_hit(self): true = False false = True for i in range(0, 1000): true = true or self.the_weapon.critical_hit() false = false and self.the_weapon.critical_hit() self.assertFalse(false) self.assertTrue(true)
class WeaponTest(unittest.TestCase): def setUp(self): self.weapon = Weapon("Mighty Axe", 25, 0.2) def test_weapon_init(self): self.assertEqual(self.weapon.type, "Mighty Axe") self.assertEqual(self.weapon.damage, 25) self.assertEqual(self.weapon.critical_strike_percent, 0.2) def test_critical_hit(self): self.assertTrue(self.weapon.critical_hit())
class TestWeapon(unittest.TestCase): def setUp(self): self.axe = Weapon("Axe", 10, 0.2) def test_attributes(self): self.assertEqual("Axe", self.axe.type) self.assertEqual(10, self.axe.damage) self.assertEqual(0.2, self.axe.critical_strike_percent) def test_critical_hit_never(self): self.axe.critical_strike_percent = 0 damage_values = [] for x in range(1, 10000): current_damage = self.axe.critical_hit() damage_values.append(current_damage) self.assertFalse(20 in damage_values) def test_critical_hit_always(self): self.axe.critical_strike_percent = 1 damage_values = [] for x in range(1, 10000): current_damage = self.axe.critical_hit() damage_values.append(current_damage) self.assertFalse(10 in damage_values) def test_critical_hit_sometimes(self): self.axe.critical_strike_percent = 1 damage_values = [] for x in range(1, 10000): current_damage = self.axe.critical_hit() damage_values.append(current_damage) self.assertFalse(10 in damage_values)
class TestWeapon(unittest.TestCase): def setUp(self): self.bow = Weapon("Mighty Bow", 13, 0.17) def test_init(self): self.assertEqual(self.bow.name, "Mighty Bow") self.assertEqual(self.bow.damage, 13) self.assertEqual(self.bow.critical_strike_percent, 0.17) def test_if_critical_hit(self): crits = [] for i in range(100): crits.append(self.bow.critical_hit()) self.assertTrue(True in crits)
class WeaponTest (unittest.TestCase): def setUp(self): self.weapon = Weapon("Mighty Axe", 25, 0.2) def test_weapon_init(self): self.assertEqual(self.weapon.type, "Mighty Axe") self.assertEqual(self.weapon.damage, 25) self.assertEqual(self.weapon.critical_strike_percent, 0.2) def test_critical_hit(self): self.assertTrue(self.weapon.critical_hit())
class WeaponTest(unittest.TestCase): def setUp(self): self.default_weapon = Weapon('Mighty Axe', 25, 0.2) def test_init_weapon(self): self.assertEqual(self.default_weapon.type, 'Mighty Axe') self.assertEqual(self.default_weapon.damage, 25) self.assertEqual(self.default_weapon.critical_strike_percent, 0.2) def test_critical_hit(self): results = [] for x in range(1000): results.append(self.default_weapon.critical_hit()) self.assertTrue(True in results) self.assertTrue(False in results)
class Test_weapon(unittest.TestCase): def setUp(self): self.weapon = Weapon("Nutcracker", 20, 0.2) def test_weapon_type(self): output = "Nutcracker" result = self.weapon.type self.assertEqual(result, output) def test_critical_hit(self): results = [] for hit in range(0, 1000): results.append(self.weapon.critical_hit()) print (set(results)) self.assertEqual(2, len(set(results)))
class WeaponTest(unittest.TestCase): def setUp(self): self.destroyer_weapon = Weapon('Destroyer Axe', 30, 0.7) def test_init_weapon(self): self.assertEqual(self.destroyer_weapon.type, 'Destroyer Axe') self.assertEqual(self.destroyer_weapon.damage, 30) self.assertEqual(self.destroyer_weapon.critical_strike_percent, 0.7) def test_critical_hit(self): result = [] for x in range(1000): result.append(self.destroyer_weapon.critical_hit()) self.assertIn(True, result) self.assertIn(False, result)
class TestWeapon(unittest.TestCase): def setUp(self): self.short_sword = Weapon("Short Sword", 10, 0.1) def test_init(self): self.assertEqual("Short Sword", self.short_sword.name) self.assertEqual(10, self.short_sword.damage) self.assertEqual(0.1, self.short_sword.critical_strike_percent) def test_critical_hit(self): list_of_booleans = [] for i in range(0, 1000): list_of_booleans.append(self.short_sword.critical_hit()) self.assertIn(True, list_of_booleans) self.assertIn(False, list_of_booleans)
class Entity(object): def __init__(self, name, health): self.name = name self.health = health self.max_health = health self.weapon = Weapon("Axe", 6, 0.5) self.i_coord = 0 self.j_coord = 0 def get_health(self): return self.health def is_alive(self): return self.health > 0 def take_damage(self, dmg_points): if dmg_points > self.health: self.health = 0 else: self.health -= dmg_points def take_healing(self, healing_points): if self.is_alive() == False: return False elif healing_points + self.health > self.max_health: self.health = self.max_health return True else: self.health += healing_points return True def equip_weapon(self, weapon): self.weapon = weapon def has_weapon(self): if self.weapon == None: return False return True def attack(self): if self.weapon == None: return 0 elif self.weapon.critical_hit() == True: return self.weapon.damage * 2 else: return self.weapon.damage
class TestWeapon(unittest.TestCase): def setUp(self): self.axe = Weapon("Mighty Axe", 25, 0.2) def test_weapon_init(self): self.assertEqual(self.axe.type, "Mighty Axe") self.assertEqual(self.axe.damage, 25) self.assertEqual(self.axe.critical_strike_percent, 0.2) def test_critical_strike_percent_error(self): with self.assertRaises(ValueError): Weapon("Dingo", 25, 3.5) def test_critical_hit(self): flags = set() for i in range(1000): flags.add(self.axe.critical_hit()) self.assertEqual(2, len(flags))
class TestWeapon(unittest.TestCase): def setUp(self): self.wep = Weapon("Polearm", 30, 0.5) def test_weapon_init(self): self.assertEqual(self.wep.type, "Polearm") self.assertEqual(self.wep.damage, 30) self.assertEqual(self.wep.critical_strike_percent, 0.5) def test_critical_hit(self): crit = False not_crit = False n = 1000 for i in range(n): if self.wep.critical_hit(): crit = True else: not_crit = True self.assertTrue(crit and not_crit)
class WeaponTest(unittest.TestCase): def setUp(self): self.weapon = Weapon("Sword", 11, 0.4) def test_init(self): self.assertEqual(self.weapon.type, "Sword") self.assertEqual(self.weapon.damage, 11) self.assertEqual(self.weapon.critical_percent, 0.4) def test_set_crit_with_higher_value(self): result = self.weapon.set_critical_percent(3) self.assertEqual(result, 1.0) def test_set_crit_witn_lower_value(self): result = self.weapon.set_critical_percent(-1) self.assertEqual(result, 0.1) def test_critical_strike_chance(self): self.assertIn(self.weapon.critical_hit(), [True, False])
class Test_Weapon(unittest.TestCase): def setUp(self): self.weapon = Weapon("Mighty Axe", 25, 0.2) def test_init_weapon(self): self.assertEqual(self.weapon.type, "Mighty Axe") self.assertEqual(self.weapon.damage, 25) self.assertEqual(self.weapon.critical_strike_percent, 0.2) def test_init_weapon_wrong_crit_chance(self): with self.assertRaises(ValueError): axe = Weapon("axe", 5, 4) with self.assertRaises(ValueError): axe = Weapon("axe", 5, -1) def test_critical_hit(self): results = set() for i in range(1000): results.add(self.weapon.critical_hit()) self.assertEqual(len(results), 2)
class WeaponTest(unittest.TestCase): def setUp(self): self.w = Weapon("axe", 50, 0.4) def test_init(self): self.assertEqual(self.w.type, "axe") self.assertEqual(self.w.demage, 50) self.assertEqual(self.w.critical_strike_percent, 0.4) with self.assertRaises(ValueError): self.weapon = Weapon("axe", 50, 2) def test_critical_hit(self): arr = [] flag = [False, False] for i in range(1, 100): arr.append(self.w.critical_hit()) for i in arr: if i: flag[0] = True else: flag[1] = True
class TestWeapon(unittest.TestCase): def setUp(self): self.test_weapon = Weapon("Wirt's Leg", 45, 0.9) def test_weapon_init(self): self.assertEqual(self.test_weapon.name, "Wirt's Leg") self.assertEqual(self.test_weapon.damage, 45) self.assertEqual(self.test_weapon.critChance, 0.9) def test_critical_hit_error_negative_crit(self): with self.assertRaises(ValueError): weapon = Weapon("Name", 10, -1) def test_critical_hit_error_bigger_crit(self): with self.assertRaises(ValueError): weapon = Weapon("Name", 10, 2) def test_critical_hit(self): results = [] for i in range(0, 1000): results.append(self.test_weapon.critical_hit()) self.assertEqual(2, len(set(results)))
class TestWeapon(unittest.TestCase): def setUp(self): self.my_weapon = Weapon("Axe", 20, 0.4) def test_init(self): self.assertEqual(self.my_weapon.type, "Axe") self.assertEqual(self.my_weapon.damage, 20) self.assertEqual(self.my_weapon.critical_strike_percent, 0.4) def test_value_error(self): with self.assertRaises(ValueError): self.weapon = Weapon("Axe", 20, 4) def test_critical_hit(self): answers = [] for i in range(1, 100): if self.my_weapon.critical_hit() == True: answers.append(1) else: answers.append(0) self.assertIn(1, answers) self.assertIn(0, answers)
class TestWeapon(unittest.TestCase): def setUp(self): self.my_weapon = Weapon("Axe", 20, 0.4) def test_init(self): self.assertEqual(self.my_weapon.type, "Axe") self.assertEqual(self.my_weapon.damage, 20) self.assertEqual(self.my_weapon.critical_strike_percent, 0.4) def test_value_error(self): with self.assertRaises(ValueError): self.weapon = Weapon("Axe", 20 , 4) def test_critical_hit(self): answers = [] for i in range(1, 100): if self.my_weapon.critical_hit() == True: answers.append(1) else: answers.append(0) self.assertIn(1, answers) self.assertIn(0, answers)
class WeaponTest(unittest.TestCase): def setUp(self): self.w = Weapon("axe", 50, 0.4) def test_init(self): self.assertEqual(self.w.type, "axe") self.assertEqual(self.w.demage, 50) self.assertEqual(self.w.critical_strike_percent, 0.4) with self.assertRaises(ValueError): self.weapon = Weapon("axe", 50, 2) def test_critical_hit(self): arr = [] flag = [False, False] for i in range(1, 100): arr.append(self.w.critical_hit()) for i in arr: if i: flag[0]=True else: flag[1]=True
class TestWeapon(unittest.TestCase): def setUp(self): self.wep = Weapon("Durvo", 25, 0.2) def test_weapon_init(self): self.assertEqual("Durvo", self.wep.type) self.assertEqual(25, self.wep.damage) self.assertEqual(0.2, self.wep.critical_strike_percent) def test_value_error(self): with self.assertRaises(ValueError): weap = Weapon("Durvo", 50, 1.2) def test_critical_strike(self): is_false = False is_true = False for i in range(100): if self.wep.critical_hit(): is_true = True else: is_false = True self.assertTrue(is_true) self.assertTrue(is_false)
def test_Weapon_critical_hit(self): my_weapon = Weapon("Axe", 31, 1) self.assertTrue(my_weapon.critical_hit())
def test_critical_hit_false(self): another_warglaive = Weapon("Sword (again)", 10, 0) self.assertFalse(another_warglaive.critical_hit())
def test_critical_hit_true(self): warglaive = Weapon("Sword", 11, 1) self.assertTrue(warglaive.critical_hit())