Ejemplo n.º 1
0
class TestEntiny(unittest.TestCase):
    def setUp(self):
        self.entity = Entity("Monster", 100)

    def test_init(self):
        self.assertEqual("Monster", self.entity.name)
        self.assertEqual(100, self.entity.health)

    def test_health(self):
        self.assertEqual(100, self.entity.get_health())

    def test_take_damage(self):
        self.assertEqual(self.entity.take_damage(80), 20)

    def test_take_damage_more(self):
        self.assertEqual(self.entity.take_damage(123), 0)

    def test_has_weapon(self):
        self.assertFalse(self.entity.has_weapon())

    def test_equip_weapon(self):
        axe = Weapon("Axe", 25, 2)
        self.entity.equip_weapon(axe)
        self.assertEqual(self.entity.weapon, axe)

    def test_has_weapon_added(self):
        axe = Weapon("Axe", 25, 2)
        self.entity.equip_weapon(axe)
        self.assertTrue(self.entity.has_weapon())
Ejemplo n.º 2
0
 def test_switch_weapon(self):
     new_entity = Entity("equipswitch", 100)
     axe = Weapon("skullsplitter", 10, 0.2)
     bow = Weapon("arrowless bow", 1, 1.0)
     new_entity.equip_weapon(axe)
     new_entity.equip_weapon(bow)
     self.assertEqual(new_entity.weapon.name, bow.name)
Ejemplo n.º 3
0
 def test_Entity_attack_with_weapon(self):
     my_weapon = Weapon("Axe", 31, 0.2)
     my_Entity = Entity("Ivan", 100)
     my_Entity.equip_weapon(my_weapon)
     attack = my_weapon.damage * (1 + my_weapon.critical_strike_percent)
     true_attack = my_Entity.attack()
     self.assertEqual(attack, true_attack)
Ejemplo n.º 4
0
class TestEntiny(unittest.TestCase):
	def setUp(self):
		self.entity = Entity("Monster", 100)

	def test_init(self):
		self.assertEqual("Monster", self.entity.name)
		self.assertEqual(100, self.entity.health)

	def test_health(self):
		self.assertEqual(100, self.entity.get_health())

	def test_take_damage(self):
		self.assertEqual(self.entity.take_damage(80),20)

	def test_take_damage_more(self):
		self.assertEqual(self.entity.take_damage(123),0)

	def test_has_weapon(self):
		self.assertFalse(self.entity.has_weapon())

	def test_equip_weapon(self):
		axe = Weapon("Axe", 25, 2)
		self.entity.equip_weapon(axe)
		self.assertEqual(self.entity.weapon, axe)

		
	def test_has_weapon_added(self):
		axe = Weapon("Axe", 25, 2)
		self.entity.equip_weapon(axe)
		self.assertTrue(self.entity.has_weapon())
Ejemplo n.º 5
0
 def test_switch_weapon(self):
     new_entity = Entity("equipswitch", 100)
     axe = Weapon("skullsplitter", 10, 0.2)
     bow = Weapon("arrowless bow", 1, 1.0)   
     new_entity.equip_weapon(axe)
     new_entity.equip_weapon(bow)
     self.assertEqual(new_entity.weapon.name, bow.name)
Ejemplo n.º 6
0
 def test_Entity_equip_weapon_no_weapon(self):
     my_weapon = Weapon("Axe", 31, 0.2)
     my_Entity = Entity("Ivan", 100)
     my_Entity.equip_weapon(my_weapon)
     self.assertEqual(my_Entity.weapon.type, "Axe")
     self.assertEqual(my_Entity.weapon.damage, 31)
     self.assertEqual(my_Entity.weapon.critical_strike_percent, 0.2)
class TestEntity(unittest.TestCase):

    def setUp(self):
        self.entity = Entity('Name', 100)

    def test_entity_init(self):
        self.assertEqual(self.entity.name, 'Name')
        self.assertEqual(self.entity.health, 100)

    def test_get_health(self):
        self.assertEqual(
            self.entity.get_health(), self.entity.health)

    def test_is_alive(self):
        self.assertTrue(self.entity.is_alive())
        self.entity.current_health = 0
        self.assertFalse(self.entity.is_alive())

    def test_take_damage(self):
        self.entity.take_damage(50)
        self.assertEqual(self.entity.get_health(), 50)

    def test_take_damage_more_than_hp(self):
        self.entity.take_damage(120)
        self.assertEqual(self.entity.get_health(), 0)

    def test_take_healing_on_death_player(self):
        self.entity.take_damage(100)
        self.assertFalse(self.entity.take_healing(50))

    def test_take_healing_more_than_max_health(self):
        self.entity.take_damage(20)
        self.assertTrue(self.entity.take_healing(30))
        self.assertEqual(self.entity.get_health(), 100)

    def test_take_normal_healing(self):
        self.entity.take_damage(50)
        self.assertTrue(self.entity.take_healing(30))
        self.assertEqual(self.entity.get_health(), 80)

    def test_has_no_weapon(self):
        self.assertFalse(self.entity.has_weapon())

    def test_has_weapon(self):
        self.weapon = Weapon('Axe', 25, 0.5)

    def test_equip_weapon(self):
        axe = Weapon('Axe', 25, 0.5)
        self.entity.equip_weapon(axe)
        self.assertTrue(self.entity.has_weapon())

    def test_attack_without_weapon(self):
        self.assertEqual(self.entity.attack(), 0)

    def test_attack_with_weapon(self):
        axe = Weapon('Axe', 25, 0.5)
        self.entity.equip_weapon(axe)
        self.assertEqual(self.entity.attack(), 25)
Ejemplo n.º 8
0
 def test_Entity_equip_weapon_with_weapon(self):
     my_weapon = Weapon("Axe", 31, 0.2)
     my_weapon2 = Weapon("Sword", 20, 0.5)
     my_Entity = Entity("Ivan", 100)
     my_Entity.equip_weapon(my_weapon)
     my_Entity.equip_weapon(my_weapon2)
     self.assertEqual(my_Entity.weapon.type, "Sword")
     self.assertEqual(my_Entity.weapon.damage, 20)
     self.assertEqual(my_Entity.weapon.critical_strike_percent, 0.5)
class TestEntity(unittest.TestCase):
    def setUp(self):
        self.entity = Entity('Name', 100)

    def test_entity_init(self):
        self.assertEqual(self.entity.name, 'Name')
        self.assertEqual(self.entity.health, 100)

    def test_get_health(self):
        self.assertEqual(self.entity.get_health(), self.entity.health)

    def test_is_alive(self):
        self.assertTrue(self.entity.is_alive())
        self.entity.current_health = 0
        self.assertFalse(self.entity.is_alive())

    def test_take_damage(self):
        self.entity.take_damage(50)
        self.assertEqual(self.entity.get_health(), 50)

    def test_take_damage_more_than_hp(self):
        self.entity.take_damage(120)
        self.assertEqual(self.entity.get_health(), 0)

    def test_take_healing_on_death_player(self):
        self.entity.take_damage(100)
        self.assertFalse(self.entity.take_healing(50))

    def test_take_healing_more_than_max_health(self):
        self.entity.take_damage(20)
        self.assertTrue(self.entity.take_healing(30))
        self.assertEqual(self.entity.get_health(), 100)

    def test_take_normal_healing(self):
        self.entity.take_damage(50)
        self.assertTrue(self.entity.take_healing(30))
        self.assertEqual(self.entity.get_health(), 80)

    def test_has_no_weapon(self):
        self.assertFalse(self.entity.has_weapon())

    def test_has_weapon(self):
        self.weapon = Weapon('Axe', 25, 0.5)

    def test_equip_weapon(self):
        axe = Weapon('Axe', 25, 0.5)
        self.entity.equip_weapon(axe)
        self.assertTrue(self.entity.has_weapon())

    def test_attack_without_weapon(self):
        self.assertEqual(self.entity.attack(), 0)

    def test_attack_with_weapon(self):
        axe = Weapon('Axe', 25, 0.5)
        self.entity.equip_weapon(axe)
        self.assertEqual(self.entity.attack(), 25)
Ejemplo n.º 10
0
class MyTests(unittest.TestCase):
    def setUp(self):
        self.test_ent = Entity("Bron", 100)
        self.weap = Weapon("Mighty Bow", 13, 0.17)

    def test_init(self): 
        self.assertEqual(self.test_ent.name, "Bron")
        self.assertEqual(self.test_ent.health, 100)
        self.assertEqual(self.test_ent._MAX_HEALT, 100)

    def test_known_as(self):
        self.assertEqual(self.test_ent.known_as(), "Bron")

    def test_is_alive(self):
        self.assertEqual(self.test_ent.is_alive(), True)

    def test_get_health(self):
        self.assertEqual(self.test_ent.get_health(), 100)

    def test_take_damage(self):
        self.test_ent.take_damage(50)
        self.assertEqual(self.test_ent.health, 50)
        self.test_ent.take_damage(60)
        self.assertEqual(self.test_ent.health, 0)
    
    def test_take_healing(self):
        self.test_ent.health = 50
        self.assertTrue(self.test_ent.take_healing(20))
        self.assertEqual(self.test_ent.health, 70)
    
    def test_take_healing_above_max(self):
        self.test_ent.health = 20
        self.test_ent.take_healing(120)
        self.assertEqual(self.test_ent.health, 100)
    
    def test_healing_on_dead(self):
        self.test_ent.health = 0
        self.assertFalse(self.test_ent.take_healing(100))

    def test_have_no_w(self):
        self.assertEqual(self.test_ent.has_weapon(), False)

    def test_have_w(self):
        self.test_ent.equip_weapon(self.weap)
        self.assertEqual(self.test_ent.has_weapon(), True)

    def test_attack_no_weapon(self):
        self.assertEqual(self.test_ent.attack(), 0)

    def test_attack_weapon(self):
        self.test_ent.equip_weapon(self.weap)
        self.assertEqual(self.test_ent.attack(), 13)
Ejemplo n.º 11
0
class TestEntity(unittest.TestCase):
    def setUp(self):
        self.en = Entity("Dude", 100)
        self.bow = Weapon("Mighty Bow", 13, 0.17)
        self.axe = Weapon("Thunder AXE!", 19, 0.25)

    def test_init(self):
        self.assertEqual(self.en.name, "Dude")
        self.assertEqual(self.en.health, 100)

    def test_is_alive(self):
        self.assertTrue(self.en.is_alive())

    def test_not_alive(self):
        self.en.health = 0
        self.assertFalse(self.en.is_alive())

    def test_take_damage(self):
        self.en.take_damage(50)
        self.assertEqual(self.en.health, 50)
        self.en.take_damage(60)
        self.assertEqual(self.en.health, 0)

    def test_take_healing(self):
        self.en.health = 50
        self.assertTrue(self.en.take_healing(20))
        self.assertEqual(self.en.health, 70)

    def test_take_healing_above_max(self):
        self.en.health = 20
        self.en.take_healing(120)
        self.assertEqual(self.en.health, 100)

    def test_healing_on_dead(self):
        self.en.health = 0
        self.assertFalse(self.en.take_healing(100))

    def test_if_weapon_equipped(self):
        self.assertFalse(self.en.has_weapon())
        self.en.equipped_weapon = self.bow
        self.assertTrue(self.en.has_weapon())

    def test_equip_weapon(self):
        self.en.equip_weapon(self.bow)
        self.assertEqual(self.en.equipped_weapon, self.bow)

    def test_equip_weapon_get_new_weapon(self):
        self.en.equip_weapon(self.bow)
        self.en.equip_weapon(self.axe)
        self.assertEqual(self.en.equipped_weapon, self.axe)

    def test_attack(self):
        self.assertEqual(self.en.attack(), 0)
        self.en.equip_weapon(self.bow)
        self.assertIn(self.en.attack(), [13, 26])
        self.en.equip_weapon(self.axe)
        self.assertIn(self.en.attack(), [19, 38])
Ejemplo n.º 12
0
class TestEntity(unittest.TestCase):

    def setUp(self):
        self.new_entity = Entity("Chen", 100, 100)
        self.new_weapon = Weapon("Some Sword", 1, 0)
        self.some_weapon = Weapon("Some Sword", 1, 1)

    def test_init_entity(self):
        self.assertEqual("Chen", self.new_entity.name)
        self.assertEqual(100, self.new_entity.health)
        self.assertEqual(100, self.new_entity.max_health)

    def test_get_health(self):
        self.assertEqual(100, self.new_entity.get_health())

    def test_is_alive(self):
        self.assertTrue(self.new_entity.is_alive())

    def test_take_damage(self):
        self.new_entity.take_damage(5.5)
        self.assertEqual(self.new_entity.health, 94.5)
        self.new_entity.take_damage(95)
        self.assertEqual(self.new_entity.health, 0)

    def test_take_healing(self):
        self.new_entity.take_healing(11)
        self.assertEqual(100, self.new_entity.health)
        self.new_entity.take_damage(15)
        self.new_entity.take_healing(16)
        self.assertEqual(100, self.new_entity.health)
        self.new_entity.take_damage(111)
        self.assertFalse(self.new_entity.take_healing(1))
        self.new_entity.health = 10
        self.assertTrue(self.new_entity.take_healing(1))

    def test_has_weapon(self):
        self.assertFalse(self.new_entity.has_weapon)
        self.assertEqual(0, self.new_entity.attack())
        self.new_entity.equip_weapon(self.new_weapon)
        self.assertEqual(1, self.new_entity.attack())
        self.assertTrue(self.new_entity.has_weapon)
        self.new_entity.equip_weapon(self.some_weapon)
        self.assertEqual(2, self.new_entity.attack())
Ejemplo n.º 13
0
class EntityTest(unittest.TestCase):
    def setUp(self):
        self.entity = Entity("Samy", 100)

    def test_entity_init(self):
        self.assertEqual(self.entity.name, "Samy")
        self.assertEqual(self.entity.health, 100)

    def test_get_health(self):

        self.assertEqual(self.entity.get_health(), 100)

    def test_is_alive_return_false(self):

        self.entity.fight_health = 0
        self.assertFalse(self.entity.is_alive())

    def test_is_alive(self):
        self.assertTrue(self.entity.is_alive())

    def test_take_damage(self):

        self.assertEqual(80, self.entity.take_damage(20))

    def test_take_damage_more_than_health(self):

        self.assertEqual(0, self.entity.take_damage(120))

    def test_take_healing_to_dead_person(self):
        self.entity.health = 0
        self.assertFalse(self.entity.take_healing(20))

    def test_take_healing_more_than_full_health(self):
        self.entity.health = 90
        self.assertFalse(self.entity.take_healing(100))

    def test_take_healing_true(self):
        self.entity.health = 40

    def test_equip_weapon(self):

        lopata_weapon = Weapon("Lopata", 35, 0.5)
        self.entity.equip_weapon(lopata_weapon)
        self.assertEqual(self.entity.weapon, lopata_weapon)

    def test_has_weapon(self):
        lopata_weapon = Weapon("Lopata", 35, 0.5)
        self.entity.equip_weapon(lopata_weapon)
        self.assertTrue(self.entity.has_weapon())

    def test_does_not_have_weapon(self):

        self.assertFalse(self.entity.has_weapon())

    def test_attack_with_weapopn(self):
        self.entity.equip_weapon(Weapon("ChainSaw", 55, 0.4))
        self.assertEqual(self.entity.attack(), 55)

    def test_attack_without_weapon(self):
        self.assertEqual(self.entity.attack(), 0)
Ejemplo n.º 14
0
class Test_Entity(unittest.TestCase):
    def setUp(self):
        self.entity = Entity("ent", 50)

    def test_has_weapon(self):

        self.entity.weapon = Weapon("Mighty Axe", 25, 0.2)
        self.assertTrue(self.entity.has_weapon())

    def test_equip_weapon(self):
        weapon = Weapon("Mighty Axe", 25, 0.2)
        self.entity.equip_weapon(weapon)
        self.assertEqual(self.entity.weapon, weapon)

    def test_attack_if_have_weapon_no_crit(self):
        weapon = Weapon("Mighty Axe", 25, 0.2)
        self.entity.equip_weapon(weapon)
        self.assertEqual(self.entity.attack(), self.entity.weapon.damage)

    def test_attack_if_have_weapon_crit(self):
        weapon = Weapon("Mighty Axe", 25, 0.2)
        self.entity.equip_weapon(weapon)
        if self.entity.weapon.critical_hit():
            self.assertEqual(self.entity.attack(),
                             self.entity.weapon.damage * 2)
        else:
            self.assertEqual(self.entity.attack(), self.entity.weapon.damage)

    def test_attack_if_havnt_weapon(self):
        self.assertEqual(self.entity.attack(), 0)
Ejemplo n.º 15
0
class Test_Entity(unittest.TestCase):

    def setUp(self):
        self.entity = Entity("ent", 50)

    def test_has_weapon(self):

        self.entity.weapon = Weapon("Mighty Axe", 25, 0.2)
        self.assertTrue(self.entity.has_weapon())

    def test_equip_weapon(self):
        weapon = Weapon("Mighty Axe", 25, 0.2)
        self.entity.equip_weapon(weapon)
        self.assertEqual(self.entity.weapon, weapon)

    def test_attack_if_have_weapon_no_crit(self):
        weapon = Weapon("Mighty Axe", 25, 0.2)
        self.entity.equip_weapon(weapon)
        self.assertEqual(self.entity.attack(), self.entity.weapon.damage)

    def test_attack_if_have_weapon_crit(self):
        weapon = Weapon("Mighty Axe", 25, 0.2)
        self.entity.equip_weapon(weapon)
        if self.entity.weapon.critical_hit():
            self.assertEqual(self.entity.attack(), self.entity.weapon.damage * 2)
        else:
            self.assertEqual(self.entity.attack(), self.entity.weapon.damage)

    def test_attack_if_havnt_weapon(self):
        self.assertEqual(self.entity.attack(), 0)
Ejemplo n.º 16
0
class Test_Entity(unittest.TestCase):

    def setUp(self):
        self.my_entity = Entity("Entity", 100)

    def test_init(self):
        self.assertEqual(self.my_entity.name, "Entity")
        self.assertEqual(self.my_entity.health, 100)
        self.assertEqual(self.my_entity.max_health, self.my_entity.health)
        self.assertEqual(self.my_entity.i_coord, 0)
        self.assertEqual(self.my_entity.j_coord, 0)


    def test_is_alive(self):
        self.assertTrue(self.my_entity.is_alive())

    def test_is_alive_2(self):
        self.my_entity.health = 0
        self.assertFalse(self.my_entity.is_alive())

    def test_take_damage(self):
        self.my_entity.take_damage(10)
        self.assertEqual(self.my_entity.health, 90)

    def test_take_damage_more_than_hp(self):
        self.my_entity.take_damage(110)
        self.assertEqual(self.my_entity.get_health(), 0)

    def test_take_healing_dead_hero(self):
        self.my_entity.take_damage(120)
        self.assertFalse(self.my_entity.take_healing(10))

    def test_take_healing_more_than_max_hp(self):
        self.my_entity.take_damage(50)
        self.my_entity.take_healing(100)
        self.assertEqual(self.my_entity.health, 100)

    def test_take_healing_less_then_max_hp(self):
        self.my_entity.take_damage(50)
        self.my_entity.take_healing(10)
        self.assertEqual(self.my_entity.health, 60)

    def test_has_weapon(self):
    	self.proba = Weapon("axe", 20, 0.0)
    	self.my_entity.equip_weapon(self.proba)
    	self.assertTrue(self.my_entity.has_weapon())

    def test_attack_with_weapon(self):
    	self.proba = Weapon("axe", 20, 0.5)
    	self.my_entity.equip_weapon(self.proba)
    	self.assertEqual(self.my_entity.attack(),20)

    def test_attack_without_weapon(self):
    	self.proba = None
    	self.my_entity.equip_weapon(self.proba)
    	self.assertEqual(self.my_entity.attack(), 0)
Ejemplo n.º 17
0
class TestEntity(unittest.TestCase):
    def setUp(self):
        self.test_entity = Entity("Gad", 100)

    def test_entity_init(self):
        test_entity = Entity("Gad", 100)
        self.assertEqual(test_entity.name, "Gad")
        self.assertEqual(test_entity.health, 100)

    def test_is_alive(self):
        self.assertTrue(self.test_entity.is_alive())

    def test_get_health(self):
        self.assertEqual(self.test_entity.get_health(), 100)

    def test_take_damage(self):
        self.test_entity.take_damage(30)
        self.assertEqual(self.test_entity.get_health(), 70)

    def test_take_damage_less_than_zero(self):
        self.test_entity.take_damage(200)
        self.assertEqual(self.test_entity.get_health(), 0)

    def test_take_healing(self):
        self.test_entity.take_damage(50)
        self.test_entity.take_healing(20)
        self.assertEqual(70, self.test_entity.get_health())

    def test_take_healing_dead(self):
        self.test_entity.take_damage(150)
        self.assertFalse(self.test_entity.is_alive())

    def test_take_healing_max_health(self):
        self.test_entity.take_damage(30)
        self.assertTrue(self.test_entity.take_healing(50))
        self.assertEqual(self.test_entity.get_health(), 100)

    def test_eqiup_weapon(self):
        weapon = Weapon("hammer", 20, 0.5)
        self.test_entity.equip_weapon(weapon)
        self.assertTrue(self.test_entity.has_weapon())

    def test_attack(self):
        weapon = Weapon("hammer", 20, 0.5)
        self.test_entity.equip_weapon(weapon)
        self.assertEqual(self.test_entity.attack(), 20)

    def test_attack_without_weapon(self):
        weapon = None
        self.test_entity.equip_weapon(weapon)
        self.assertEqual(0, self.test_entity.attack())
Ejemplo n.º 18
0
class TestEntity(unittest.TestCase):
    def setUp(self):
        self.test_entity = Entity("Gad", 100)

    def test_entity_init(self):
        test_entity = Entity("Gad", 100)
        self.assertEqual(test_entity.name, "Gad")
        self.assertEqual(test_entity.health, 100)

    def test_is_alive(self):
        self.assertTrue(self.test_entity.is_alive())

    def test_get_health(self):
        self.assertEqual(self.test_entity.get_health(), 100)

    def test_take_damage(self):
        self.test_entity.take_damage(30)
        self.assertEqual(self.test_entity.get_health(), 70)

    def test_take_damage_less_than_zero(self):
        self.test_entity.take_damage(200)
        self.assertEqual(self.test_entity.get_health(), 0)

    def test_take_healing(self):
        self.test_entity.take_damage(50)
        self.test_entity.take_healing(20)
        self.assertEqual(70, self.test_entity.get_health())

    def test_take_healing_dead(self):
        self.test_entity.take_damage(150)
        self.assertFalse(self.test_entity.is_alive())

    def test_take_healing_max_health(self):
        self.test_entity.take_damage(30)
        self.assertTrue(self.test_entity.take_healing(50))
        self.assertEqual(self.test_entity.get_health(), 100)

    def test_eqiup_weapon(self):
        weapon = Weapon("hammer", 20, 0.5)
        self.test_entity.equip_weapon(weapon)
        self.assertTrue(self.test_entity.has_weapon())

    def test_attack(self):
        weapon = Weapon("hammer", 20, 0.5)
        self.test_entity.equip_weapon(weapon)
        self.assertEqual(self.test_entity.attack(), 20)

    def test_attack_without_weapon(self):
        weapon = None
        self.test_entity.equip_weapon(weapon)
        self.assertEqual(0, self.test_entity.attack())
Ejemplo n.º 19
0
 def test_equip_weapon(self):
     new_entity = Entity("equip", 100)
     axe = Weapon("skullsplitter", 10, 1.2)
     new_entity.equip_weapon(axe)
     self.assertTrue(new_entity.has_weapon())
Ejemplo n.º 20
0
class TestEntity(unittest.TestCase):
    def setUp(self):
        self.born_entity = Entity("Shapeshifter", 100)

    def test_entity_init(self):
        self.assertEqual(self.born_entity.name, "Shapeshifter")
        self.assertEqual(self.born_entity.health, 100)

    def test_get_health(self):
        self.assertEqual(self.born_entity.get_health(), 100)

    def test_is_alive(self):
        self.assertTrue(self.born_entity.is_alive())

    def test_is_alive_dead(self):
        self.born_entity.health = 0
        self.assertFalse(self.born_entity.is_alive())

    def test_take_damage(self):
        damage = 20
        self.born_entity.take_damage(damage)
        self.assertEqual(self.born_entity.health, 80)

    def test_take_damage_float(self):
        damage = 20.5
        self.born_entity.take_damage(damage)
        self.assertEqual(self.born_entity.health, 79.5)

    def test_take_damage_more(self):
        damage = 120
        self.born_entity.take_damage(damage)
        self.assertEqual(self.born_entity.health, 0)

    def test_take_healing_is_dead(self):
        self.born_entity.health = 0
        healing_points = 20
        self.assertFalse(self.born_entity.take_healing(healing_points))
        self.assertEqual(self.born_entity.health, 0)

    def test_take_healing(self):
        healing_points = 10
        self.assertTrue(self.born_entity.take_healing(healing_points))
        self.assertEqual(self.born_entity.health, 100)

    def test_take_healing_add(self):
        self.born_entity.health = 70
        healing_points = 20
        self.assertTrue(self.born_entity.take_healing(healing_points))
        self.assertEqual(self.born_entity.health, 90)

    def test_has_weapon_no(self):
        self.assertFalse(self.born_entity.has_weapon())

    def test_has_weapon_yes(self):
        self.born_entity.weapon = Weapon("Mighty Axe", 25, 0.2)
        self.assertTrue(self.born_entity.has_weapon())

    def test_equip_weapon(self):
        weapon = Weapon("Mighty Axe", 25, 0.2)
        self.born_entity.equip_weapon(weapon)
        self.assertEqual(self.born_entity.weapon, weapon)

    def test_attack(self):
        self.born_entity.weapon = Weapon("Mighty Axe", 25, 0.5)
        damages = set()
        for i in range(1000):
            damages.add(self.born_entity.attack())

        self.assertIn(25, damages)
        self.assertIn(50, damages)
Ejemplo n.º 21
0
class TestEntity(unittest.TestCase):
    def setUp(self):
        self.entity = Entity("Entity", 100)

    def test_entity_init(self):
        self.assertEqual(self.entity.name, "Entity")
        self.assertEqual(self.entity.health, 100)

    def test_get_health(self):
        self.assertEqual(self.entity.get_health(), 100)

    def test_is_alive(self):
        self.assertTrue(self.entity.is_alive())

    def test_is_not_alive(self):
        self.entity.health = 0
        self.assertFalse(self.entity.is_alive())

    def test_take_damage(self):
        self.entity.take_damage(60)
        self.assertEqual(40, self.entity.get_health())
        self.entity.take_damage(14.5)
        self.assertEqual(25.5, self.entity.get_health())

    def test_take_too_much_damage(self):
        self.entity.take_damage(250.3)
        self.assertEqual(0, self.entity.get_health())

    def test_take_healing_alive(self):
        self.entity.take_damage(40)  # entity should be at 60
        self.assertEqual(60, self.entity.get_health())
        self.assertTrue(self.entity.take_healing(15))
        self.assertEqual(75, self.entity.get_health())

    def test_take_healing_overheal(self):
        self.assertTrue(self.entity.take_healing(24))
        self.assertEqual(100, self.entity.get_health())

    def test_take_healing_max_health(self):
        self.entity.health = 50
        self.assertTrue(self.entity.take_healing(70))
        self.assertEqual(100, self.entity.health)

    def test_take_healing_dead(self):
        self.entity.take_damage(100)  # entity is dead now
        self.assertFalse(self.entity.is_alive())
        self.assertFalse(self.entity.take_healing(90))
        self.assertEqual(0, self.entity.get_health())

    def test_has_weapon(self):
        self.entity.weapon = Weapon("Axe", 20, 0.5)
        self.assertTrue(self.entity.has_weapon())

    def test_doesnt_have_weapon(self):
        self.assertFalse(self.entity.has_weapon())

    def test_equip_weapon(self):
        old_weapon = Weapon("Axe", 20, 0.5)
        self.entity.equip_weapon(old_weapon)
        self.assertTrue(self.entity.has_weapon())
        self.assertEqual(old_weapon, self.entity.weapon)

    def test_equip_new_weapon(self):
        old_weapon = Weapon("Axe", 20, 0.5)
        self.entity.equip_weapon(old_weapon)
        new_weapon = Weapon("Sopa", 30, 0.8)
        self.entity.equip_weapon(new_weapon)
        self.assertEqual(new_weapon, self.entity.weapon)

    def test_equip_invalid_weapon(self):
        with self.assertRaises(TypeError):
            self.entity.equip_weapon(set())

    def test_attack_with_weapon(self):
        weapon = Weapon("Axe", 20, 0.5)
        self.entity.equip_weapon(weapon)
        self.assertEqual(20, self.entity.attack())

    def test_attack_without_weapon(self):
        self.assertEqual(0, self.entity.attack())
class EntityTests(unittest.TestCase):
    def setUp(self):
        self.the_entity = Entity("Spiridon", 99.9)

    def test_entity_init(self):
        self.assertEqual("Spiridon", self.the_entity.name)
        self.assertEqual(99.9, self.the_entity.health)

    def test_get_health(self):
        self.assertEqual(99.9, self.the_entity.get_health())

    def test_is_alive(self):
        self.assertTrue(self.the_entity.is_alive())

    def test_is_alive_dead(self):
        self.the_entity.health = 0
        self.assertFalse(self.the_entity.is_alive())

    def test_take_damage(self):
        self.the_entity.take_damage(20)
        self.assertEqual(79.9, self.the_entity.get_health())

    def test_take_damage_more_than_health(self):
        self.the_entity.take_damage(129)
        self.assertEqual(0, self.the_entity.get_health())

    def test_take_healing_dead_entity(self):
        self.the_entity.health = 0
        self.assertFalse(self.the_entity.take_healing(20))

    def test_take_healing_is_possible(self):
        self.the_entity.take_damage(59.9)
        self.assertTrue(self.the_entity.take_healing(30))
        self.assertEqual(70, self.the_entity.get_health())

    def test_take_healing_more_than_max_health(self):
        # the maximum remains
        self.the_entity.take_damage(20)
        self.assertTrue(self.the_entity.take_healing(30))
        self.assertEqual(99.9, self.the_entity.get_health())

    def test_has_weapon_false(self):
        self.assertFalse(self.the_entity.has_weapon())

    def test_has_weapon_true(self):
        self.the_entity.weapon = Weapon("daggers", 16, 0.5)
        self.assertTrue(self.the_entity.has_weapon())

    def test_equip_weapon(self):
        weapon1 = Weapon("daggers", 16, 0.5)
        weapon2 = Weapon("spoon", 2, 0.7)
        self.the_entity.weapon = weapon1
        self.the_entity.equip_weapon(weapon2)
        self.assertNotEqual(weapon1, self.the_entity.weapon)
        self.assertEqual(weapon2, self.the_entity.weapon)

    def test_equip_weapon_value_error(self):
        with self.assertRaises(ValueError):
            self.the_entity.equip_weapon("pancake")

    def test_attack_no_weapon(self):
        self.assertEqual(0, self.the_entity.attack())

    # fix this test later; self.assertIn
    def test_attack(self):
        weapon = Weapon("spoon", 2, 0.7)
        self.the_entity.equip_weapon(weapon)
        critical = False
        normal = False
        for i in range(0, 1000):
            critical = critical or (4 == self.the_entity.attack())
            normal = normal or (2 == self.the_entity.attack())
        self.assertTrue(critical)
        self.assertTrue(normal)
Ejemplo n.º 23
0
class TestEntity(unittest.TestCase):

    def setUp(self):
        self.test_entity = Entity("Bron", 100)

    def test_entity_init(self):
        self.assertEqual("Bron", self.test_entity.name)
        self.assertEqual(100, self.test_entity.health)

    def test_get_health(self):
        self.assertEqual(100, self.test_entity.get_health())

    def test_is_alive(self):
        self.assertTrue(self.test_entity.is_alive())

    def test_is_dead(self):
        self.test_entity.health = 0
        self.assertFalse(self.test_entity.is_alive())

    def test_take_dmg_still_alive(self):
        self.test_entity.take_damage(30)
        self.assertEqual(70, self.test_entity.get_health())

    def test_take_dmg_until_zero_health(self):
        self.test_entity.take_damage(100)
        self.assertEqual(0, self.test_entity.get_health())
        self.assertFalse(self.test_entity.is_alive())

    def test_take_dmg_more_than_health(self):
        self.test_entity.take_damage(200)
        self.assertEqual(0, self.test_entity.get_health())
        self.assertFalse(self.test_entity.is_alive())

    def test_take_healing(self):
        self.test_entity.take_damage(50)
        self.test_entity.take_healing(20)
        self.assertEqual(70, self.test_entity.get_health())

    def test_healing_dead_hero(self):
        self.test_entity.take_damage(100)
        self.assertFalse(self.test_entity.take_healing(50))
        self.assertEqual(0, self.test_entity.get_health())

    def test_over_healing_not_allowed(self):
        self.test_entity.take_damage(30)
        self.assertTrue(self.test_entity.take_healing(50))
        self.assertEqual(self.test_entity.get_health(), 100)

    def test_equip_weapon(self):
        wep = Weapon("Durvo", 50, 0.5)
        self.test_entity.equip_weapon(wep)
        self.assertTrue(self.test_entity.has_weapon())

    def test_no_weapon(self):
        self.assertFalse(self.test_entity.has_weapon())

    def test_attack_with_no_weapon(self):
        self.assertEqual(self.test_entity.attack(), 0)

    def test_attack(self):
        wep = Weapon("Durvo", 50, 0)
        self.test_entity.equip_weapon(wep)
        self.assertEqual(self.test_entity.attack(), 50)

    def test_attack_crit(self):
        wep = Weapon("Durvo", 50, 0.9)
        self.test_entity.equip_weapon(wep)
        dmg_taken = []
        for i in range(100):
            dmg_taken.append(self.test_entity.attack())
        self.assertIn(50, dmg_taken)
        self.assertIn(100, dmg_taken)
class EntityTests(unittest.TestCase):

    def setUp(self):
        self.the_entity = Entity("Spiridon", 99.9)

    def test_entity_init(self):
        self.assertEqual("Spiridon", self.the_entity.name)
        self.assertEqual(99.9, self.the_entity.health)

    def test_get_health(self):
        self.assertEqual(99.9, self.the_entity.get_health())

    def test_is_alive(self):
        self.assertTrue(self.the_entity.is_alive())

    def test_is_alive_dead(self):
        self.the_entity.health = 0
        self.assertFalse(self.the_entity.is_alive())

    def test_take_damage(self):
        self.the_entity.take_damage(20)
        self.assertEqual(79.9, self.the_entity.get_health())

    def test_take_damage_more_than_health(self):
        self.the_entity.take_damage(129)
        self.assertEqual(0, self.the_entity.get_health())

    def test_take_healing_dead_entity(self):
        self.the_entity.health = 0
        self.assertFalse(self.the_entity.take_healing(20))

    def test_take_healing_is_possible(self):
        self.the_entity.take_damage(59.9)
        self.assertTrue(self.the_entity.take_healing(30))
        self.assertEqual(70, self.the_entity.get_health())

    def test_take_healing_more_than_max_health(self):
        # the maximum remains
        self.the_entity.take_damage(20)
        self.assertTrue(self.the_entity.take_healing(30))
        self.assertEqual(99.9, self.the_entity.get_health())

    def test_has_weapon_false(self):
        self.assertFalse(self.the_entity.has_weapon())

    def test_has_weapon_true(self):
        self.the_entity.weapon = Weapon("daggers", 16, 0.5)
        self.assertTrue(self.the_entity.has_weapon())

    def test_equip_weapon(self):
        weapon1 = Weapon("daggers", 16, 0.5)
        weapon2 = Weapon("spoon", 2, 0.7)
        self.the_entity.weapon = weapon1
        self.the_entity.equip_weapon(weapon2)
        self.assertNotEqual(weapon1, self.the_entity.weapon)
        self.assertEqual(weapon2, self.the_entity.weapon)

    def test_equip_weapon_value_error(self):
        with self.assertRaises(ValueError):
            self.the_entity.equip_weapon("pancake")

    def test_attack_no_weapon(self):
        self.assertEqual(0, self.the_entity.attack())

    # fix this test later; self.assertIn
    def test_attack(self):
        weapon = Weapon("spoon", 2, 0.7)
        self.the_entity.equip_weapon(weapon)
        critical = False
        normal = False
        for i in range(0, 1000):
            critical = critical or (4 == self.the_entity.attack())
            normal = normal or (2 == self.the_entity.attack())
        self.assertTrue(critical)
        self.assertTrue(normal)
Ejemplo n.º 25
0
class EntityTest(unittest.TestCase):

    def setUp(self):
        self.entity = Entity("Arthas", 200)
        self.entity.weapon = Weapon("Frostmourne", 35, 0.7)

    def test_init(self):
        self.assertEqual(self.entity.name, "Arthas")
        self.assertEqual(self.entity.health, 200)

    def test_get_health(self):
        self.assertEqual(self.entity.get_health(), 200)

    def test_is_alive_when_alive(self):
        self.assertTrue(self.entity.is_alive())

    def test_is_alive_when_dead(self):
        self.entity.health = 0
        self.assertFalse(self.entity.is_alive())

    def test_take_damage_common(self):
        self.entity.take_damage(150)
        self.assertTrue(self.entity.is_alive())
        self.assertEqual(self.entity.get_health(), 50)

    def test_take_damage_full(self):
        self.entity.take_damage(350)
        self.assertFalse(self.entity.is_alive())
        self.assertEqual(self.entity.get_health(), 0)

    def test_take_healing_common(self):
        self.entity.health = 50
        self.entity.take_healing(50)
        self.assertEqual(self.entity.get_health(), 100)

    def test_take_healing_full(self):
        self.entity.take_healing(350)
        self.assertEqual(self.entity.get_health(), 200)

    def test_take_healing_when_dead(self):
        self.entity.health = 0
        self.entity.take_healing(100)
        self.assertEqual(self.entity.health, 0)

    def test_has_weapon_when_present(self):
        self.assertEqual(self.entity.has_weapon(), True)

    def test_has_weapon_when_not_present(self):
        self.entity.weapon = None
        self.assertEqual(self.entity.has_weapon(), False)

    def test_equip_stronger_weapon(self):
        test_weapon = Weapon("Stick", 500, 0.1)
        self.entity.equip_weapon(test_weapon)
        self.assertEqual(self.entity.weapon, test_weapon)

    def test_equip_weaker_weapon(self):
        test_weapon = Weapon("Stick", 5, 0.1)
        self.entity.equip_weapon(test_weapon)
        self.assertNotEqual(self.entity.weapon, test_weapon)

    def test_equip_weapon_when_not_armed(self):
        test_weapon = Weapon("Stick", 5, 0.1)
        self.entity.weapon = None
        self.entity.equip_weapon(test_weapon)
        self.assertEqual(self.entity.weapon, test_weapon)

    def test_attack_when_no_weapon_is_equipped(self):
        self.entity.weapon = None
        self.assertEqual(self.entity.attack(), 0)

    def test_attack_when_weapon_is_equipped(self):
        self.assertIn(self.entity.attack(), [35, 70])
Ejemplo n.º 26
0
class TestEntity(unittest.TestCase):
    def setUp(self):
        self.entity = Entity("Entity", 100)

    def test_entity_init(self):
        self.assertEqual(self.entity.name, "Entity")
        self.assertEqual(self.entity.health, 100)

    def test_get_health(self):
        self.assertEqual(self.entity.get_health(), 100)

    def test_is_alive(self):
        self.assertTrue(self.entity.is_alive())

    def test_is_not_alive(self):
        self.entity.health = 0
        self.assertFalse(self.entity.is_alive())

    def test_take_damage(self):
        self.entity.take_damage(60)
        self.assertEqual(40, self.entity.get_health())
        self.entity.take_damage(14.5)
        self.assertEqual(25.5, self.entity.get_health())

    def test_take_too_much_damage(self):
        self.entity.take_damage(250.3)
        self.assertEqual(0, self.entity.get_health())

    def test_take_healing_alive(self):
        self.entity.take_damage(40)        # entity should be at 60
        self.assertEqual(60, self.entity.get_health())
        self.assertTrue(self.entity.take_healing(15))
        self.assertEqual(75, self.entity.get_health())

    def test_take_healing_overheal(self):
        self.assertTrue(self.entity.take_healing(24))
        self.assertEqual(100, self.entity.get_health())

    def test_take_healing_max_health(self):
        self.entity.health = 50
        self.assertTrue(self.entity.take_healing(70))
        self.assertEqual(100, self.entity.health)

    def test_take_healing_dead(self):
        self.entity.take_damage(100)        # entity is dead now
        self.assertFalse(self.entity.is_alive())
        self.assertFalse(self.entity.take_healing(90))
        self.assertEqual(0, self.entity.get_health())

    def test_has_weapon(self):
        self.entity.weapon = Weapon("Axe", 20, 0.5)
        self.assertTrue(self.entity.has_weapon())

    def test_doesnt_have_weapon(self):
        self.assertFalse(self.entity.has_weapon())

    def test_equip_weapon(self):
        old_weapon = Weapon("Axe", 20, 0.5)
        self.entity.equip_weapon(old_weapon)
        self.assertTrue(self.entity.has_weapon())
        self.assertEqual(old_weapon, self.entity.weapon)

    def test_equip_new_weapon(self):
        old_weapon = Weapon("Axe", 20, 0.5)
        self.entity.equip_weapon(old_weapon)
        new_weapon = Weapon("Sopa", 30, 0.8)
        self.entity.equip_weapon(new_weapon)
        self.assertEqual(new_weapon, self.entity.weapon)

    def test_equip_invalid_weapon(self):
        with self.assertRaises(TypeError):
            self.entity.equip_weapon(set())

    def test_attack_with_weapon(self):
        weapon = Weapon("Axe", 20, 0.5)
        self.entity.equip_weapon(weapon)
        self.assertEqual(20, self.entity.attack())

    def test_attack_without_weapon(self):
        self.assertEqual(0, self.entity.attack())
Ejemplo n.º 27
0
 def test_has_weapon_with_equipped(self):
     axe = Weapon("Axe", 20, 0.4)
     weaponed_entity = Entity("Pro", 100)
     weaponed_entity.equip_weapon(axe)
     self.assertTrue(weaponed_entity.has_weapon())
Ejemplo n.º 28
0
class TestEntity(unittest.TestCase):

    def setUp(self):
        self.entity = Entity("NewEntity", 100)
        self.axe = Weapon("Axe", 10, 0.2)

    def test_attributes(self):
        self.assertEqual("NewEntity", self.entity.name)
        self.assertEqual(100, self.entity.health)

    def test_get_health(self):
        self.entity.health = 80
        self.assertEqual(80, self.entity.get_health())

    def test_is_alive(self):
        self.entity.health = 80
        self.assertTrue(self.entity.is_alive())

    def test_is_dead(self):
        self.entity.health = 0
        self.assertFalse(self.entity.is_alive())

    def test_take_damage_survive(self):
        self.entity.health = 100
        self.entity.take_damage(30)
        self.assertEqual(70, self.entity.get_health())
        self.assertTrue(self.entity.is_alive())

    def test_take_damage_die(self):
        self.entity.health = 100
        self.entity.take_damage(110)
        self.assertEqual(0, self.entity.get_health())
        self.assertFalse(self.entity.is_alive())

    def test_take_damage_die_exact(self):
        self.entity.health = 50
        self.entity.take_damage(50)
        self.assertEqual(0, self.entity.get_health())
        self.assertFalse(self.entity.is_alive())

    def test_take_healing_regular(self):
        self.entity.health = 40
        self.entity.take_healing(20)
        self.assertEqual(60, self.entity.get_health())
        self.assertTrue(self.entity.is_alive())

    def test_take_healing_overheal(self):
        self.entity.health = 90
        self.assertTrue(self.entity.take_healing(20))
        self.assertEqual(100, self.entity.get_health())
        self.assertTrue(self.entity.is_alive())

    def test_take_healing_overheal_exact(self):
        self.entity.health = 90
        self.assertTrue(self.entity.take_healing(10))
        self.assertEqual(100, self.entity.get_health())
        self.assertTrue(self.entity.is_alive())

    def test_take_healing_dead(self):
        self.entity.health = 0
        self.assertFalse(self.entity.take_healing(20))
        self.assertEqual(0, self.entity.get_health())
        self.assertFalse(self.entity.is_alive())

    def test_has_weapon_not(self):
        self.assertFalse(self.entity.has_weapon())

    def test_equip_weapon(self):
        self.entity.equip_weapon(self.axe)
        self.assertTrue(self.entity.has_weapon())

    def test_attack(self):
        self.entity.equip_weapon(self.axe)
        self.assertEqual(10, self.entity.attack())

    def test_attack_no_weapon(self):
        self.assertEqual(0, self.entity.attack())
Ejemplo n.º 29
0
class TestEntity(unittest.TestCase): 
    def setUp(self):
        self.new_Entity = Entity("Bron", 100)

    def test_Entity_name(self):
        self.assertEqual("Bron", self.new_Entity.name)

    def test_Entity_health(self):
        self.assertEqual(100,self.new_Entity.health)

    def test_get_health(self):
        new_Entity1 = Entity("Bron", 90)
        self.assertEqual(90,new_Entity1.get_health())

    def test_is_alive_true(self):
        self.assertTrue(self.new_Entity.is_alive())

    def test_is_alive_false(self):
        new_dead_Entity = Entity("Bron", 0)
        self.assertFalse(new_dead_Entity.is_alive())

    def test_take_damage(self):
        self.assertEqual(90,self.new_Entity.take_damage(10))

    def test_take_damage_zero(self):
        self.assertEqual(0, self.new_Entity.take_damage(110))

    def test_take_healing_false(self):
        new_healing_Entity = Entity("Bron", 0,)
        result = new_healing_Entity.take_healing(10)
        self.assertEqual(0,new_healing_Entity.health)
        self.assertFalse(result)

    def test_take_healing_true(self):
        new_healing_Entity = Entity("Bron", 100)
        new_healing_Entity.take_damage(30)
        result = new_healing_Entity.take_healing(30)
        self.assertEqual(100,new_healing_Entity.health)
        self.assertTrue(result)

    def test_take_healing_above_max_health(self):
        new_healing_Entity = Entity("Bron", 100)
        result = new_healing_Entity.take_healing(20)
        self.assertEqual(100, new_healing_Entity.health)
        self.assertTrue(result)

    def test_has_weapon(self):
        weapon = Weapon("Axe", 34, 0.5)
        self.new_Entity.equip_weapon(weapon)
        self.assertTrue(self.new_Entity.has_weapon())

    def test_equip_1_weapon(self):
        weapon = Weapon("Axe", 34, 0.5)
        self.new_Entity.equip_weapon(weapon)
        self.assertEqual("Axe", self.new_Entity.weapon.type)

    def test_equip_new_weapon_and_the_old_one_is_discarded(self):
        weapon1 = Weapon("Axe", 34, 0.5)
        weapon2 = Weapon("Sword", 34, 0.5)
        self.new_Entity.equip_weapon(weapon1)
        self.new_Entity.equip_weapon(weapon2)
        self.assertEqual("Sword", self.new_Entity.weapon.type)

    def test_attack_zero(self):
        self.assertEqual(0, self.new_Entity.attack())

    def test_attack_not_zero(self):
        weapon = Weapon("Axe", 34, 0.5)
        self.new_Entity.equip_weapon(weapon)
        self.assertEqual(34, self.new_Entity.attack())
Ejemplo n.º 30
0
class EntityTest (unittest.TestCase):
    def setUp(self):
        self.entity = Entity("Samy", 100)
        self._MAX_HEALTH = 100

    def test_hero_init(self):

        self.assertEqual(self.entity.name, "Samy")
        self.assertEqual(self.entity.health, 100)

    def test_get_health(self):

        self.assertEqual(self.entity.get_health(), 100)

    def test_is_alive_return_false(self):

        self.entity.health = 0
        self.assertFalse(self.entity.is_alive())

    def test_is_alive(self):
        self.assertTrue(self.entity.is_alive())

    def test_take_damage(self):

        self.assertEqual(80, self.entity.take_damage(20))

    def test_take_damage_more_than_health(self):
        self.assertEqual(0, self.entity.take_damage(120))

    def test_take_healing_to_dead_person(self):
        self.entity.health = 0
        self.assertFalse(self.entity.take_healing(20))

    def test_take_healing_more_than_full_health(self):
        self.entity.health = 90
        self.entity.take_healing(40)
        self.assertTrue(self.entity.take_healing(self._MAX_HEALTH))

    def test_take_healing_true(self):
        self.entity.health = 40

    def test_it_entity_has_no_weapon(self):
        self.assertFalse(self.entity.has_weapon())

    def test_if_entity_has_weapon(self):
        weapon = Weapon("Mighty Axe", 25, 0.2)
        self.entity.equip_weapon(weapon)
        self.assertTrue(self.entity.has_weapon())

    def test_equip_weapon(self):
        weapon = Weapon("Mighty Axe", 25, 0.2)
        self.assertEqual(self.entity.equip_weapon(weapon),
                         {'Weaponn': {'type': 'Mighty Axe', 'damage': 25, 'csp': 0.2}})

    def test_equip_with_another_weapon(self):
        weapon = Weapon("Mighty Axe", 25, 0.2)
        self.entity.equip_weapon(weapon)
        weapon = Weapon("Magic Sword", 20, 0.3)
        self.assertEqual(self.entity.equip_weapon(weapon),
                         {'weapon': {'type': 'Magic Sword', 'damage': 20, 'csp': 0.3}})

    def test_attack_with_no_weapon(self):
        self.assertEqual(self.entity.attack(), 0)

    def test_attack_with_weapon(self):
        weapon = Weapon("Mighty Axe", 25, 0.2)
        self.entity.equip_weapon(weapon)
        self.assertEqual(self.entity.attack(), 25)
Ejemplo n.º 31
0
 def test_Entity_has_weapon(self):
     my_weapon = Weapon("Axe", 31, 0.2)
     my_Entity = Entity("Ivan", 100)
     my_Entity.equip_weapon(my_weapon)
     self.assertTrue(my_Entity.has_weapon())
Ejemplo n.º 32
0
 def test_equip_weapon(self):
     new_entity = Entity("equip", 100)
     axe = Weapon("skullsplitter", 10, 1.2)
     new_entity.equip_weapon(axe)
     self.assertTrue(new_entity.has_weapon())
Ejemplo n.º 33
0
class TestEntity(unittest.TestCase):
    def setUp(self):
        self.character = Entity("Arthas", 100)
        self.char = Entity("Gancho", 100)
        self.character.weapon = Weapon("Frostmourne", 100, 0.9)
        self.weapon = Weapon("Stick", 5, 0.1)

    def test_hero_init(self):
        self.assertEqual(self.character.name, "Arthas")
        self.assertEqual(self.character.health, 100)
        self.assertEqual(self.character.weapon.name, "Frostmourne")

    def test_get_health(self):
        self.assertEqual(100, self.character.get_health())

    def test_is_alive(self):
        self.assertTrue(self.character.is_alive())

    def test_is_not_alive(self):
        self.character.health = 0
        self.assertFalse(self.character.is_alive())

    def test_damage_deal_if_player_is_alive(self):
        self.character.take_damage(30)
        self.assertEqual(70, self.character.health)

    def test_damage_deal_if_player_is_dead(self):
        self.character.health = 70
        self.character.take_damage(70)
        self.assertEqual(0, self.character.health)

    def test_regular_heal(self):
        self.character.health = 50
        self.character.take_healing(20)
        self.assertEqual(70, self.character.health)

    def test_healing_if_dead(self):
        self.character.health = 0
        self.character.take_healing(20)
        self.assertEqual(0, self.character.health)

    def test_healing_if_full(self):
        self.character.health = self.character._MAX_HEALTH
        self.character.take_healing(20)
        self.assertEqual(100, self.character.health)

    def test_if_entity_has_weapon(self):
        self.assertTrue(self.character.has_weapon())

    def test_if_entity_is_unarmed(self):
        self.assertFalse(self.char.has_weapon())

    def test_if_equips_unarmed_person(self):
        self.char.equip_weapon(self.weapon)
        self.assertEqual(self.weapon, self.char.weapon)

    def test_if_equips_new_weapon(self):
        self.character.equip_weapon(self.weapon)
        self.assertEqual(self.weapon, self.character.weapon)

    def test_damage_of_entity_with_weapon(self):
        self.assertEqual(self.character.attack(), 100)

    def test_damage_of_entity_without_weapon(self):
        self.assertEqual(self.char.attack(), 0)
class TestEntity(unittest.TestCase):
    def setUp(self):
        self.bron_entity = Entity("Bron", 100)

    def test_entity_init(self):
        self.assertEqual(self.bron_entity.name, "Bron")
        self.assertEqual(self.bron_entity.health, 100)

    def test_get_health(self):
        self.assertEqual(self.bron_entity.get_health(), 100)

    def test_is_alive(self):
        self.assertTrue(self.bron_entity.is_alive())

    def test_is_not_alive(self):
        self.bron_entity.health = 0
        self.assertFalse(self.bron_entity.is_alive())

    def test_take_damage(self):
        self.bron_entity.take_damage(30)
        self.assertEqual(self.bron_entity.health, 70)

    def test_take_damage_more_than_hp(self):
        self.bron_entity.take_damage(120)
        self.assertEqual(self.bron_entity.health, 0)

    def test_take_healing(self):
        self.bron_entity.health = 70
        temp_heal = self.bron_entity.take_healing(20)
        self.assertTrue(self.bron_entity.take_healing(20))
        self.assertTrue(temp_heal)

    def test_take_healing_on_dead_hero(self):
        self.bron_entity.health = 0
        self.assertFalse(self.bron_entity.take_healing(50))

    def test_take_healing_over_max_hp(self):
        self.bron_entity.health = 70
        temp_heal = self.bron_entity.take_healing(50)
        self.assertTrue(self.bron_entity.take_healing(50))
        self.assertTrue(temp_heal)

    def test_has_weapon_when_dont_have(self):
        self.assertFalse(self.bron_entity.has_weapon())

    def test_has_weapon_when_have(self):
        axe = Weapon("Mighty Axe", 25, 0.2)
        self.bron_entity.equip_weapon(axe)
        self.assertTrue(self.bron_entity.has_weapon())

    def test_equip_weapon(self):
        axe = Weapon("Mighty Axe", 25, 0.2)
        self.bron_entity.equip_weapon(axe)
        self.assertEqual(self.bron_entity.weapon, axe)

    def test_attack_when_entity_dont_have_weapon(self):
        self.assertEqual(self.bron_entity.damage, 0)

    def test_attack_when_entity_have_weapon(self):
        axe = Weapon("Mighty Axe", 25, 0.2)
        self.bron_entity.equip_weapon(axe)
Ejemplo n.º 35
0
 def test_has_weapon_with_equipped(self):
     axe = Weapon("Axe", 20, 0.4)
     weaponed_entity = Entity("Pro", 100)
     weaponed_entity.equip_weapon(axe)
     self.assertTrue(weaponed_entity.has_weapon())