コード例 #1
0
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)
コード例 #2
0
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)
コード例 #3
0
ファイル: weapon_test.py プロジェクト: dsspasov/HackBulgaria
 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)
コード例 #4
0
ファイル: dnp_tests.py プロジェクト: didoman/prog101tasks
 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)
コード例 #5
0
ファイル: test_weapon.py プロジェクト: mihail-nikolov/hackBG
 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)
コード例 #6
0
ファイル: dnp_tests.py プロジェクト: didoman/prog101tasks
 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)
コード例 #7
0
ファイル: weapon_test.py プロジェクト: stoilov/Programming101
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)
コード例 #8
0
ファイル: dnp_tests.py プロジェクト: didoman/prog101tasks
 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)
コード例 #9
0
ファイル: test_weapon.py プロジェクト: mihail-nikolov/hackBG
 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)
コード例 #10
0
ファイル: dnp_tests.py プロジェクト: didoman/prog101tasks
 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)
コード例 #11
0
 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)
コード例 #12
0
 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)
コード例 #13
0
 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)
コード例 #14
0
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())
コード例 #15
0
ファイル: test_weapon.py プロジェクト: kalpak44/Program101
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())
コード例 #16
0
ファイル: test_weapon.py プロジェクト: kkashev/hackbulgaria
 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)
コード例 #17
0
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)
コード例 #18
0
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)
コード例 #19
0
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())
コード例 #20
0
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)
コード例 #21
0
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)
コード例 #22
0
ファイル: weapon_test.py プロジェクト: vparkov/HackBulgaria
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())
コード例 #23
0
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)
コード例 #24
0
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)
コード例 #25
0
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)))
コード例 #26
0
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)
コード例 #27
0
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)
コード例 #28
0
ファイル: entity.py プロジェクト: skdls-/Python
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
コード例 #29
0
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
コード例 #30
0
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))
コード例 #31
0
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)
コード例 #32
0
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))
コード例 #33
0
ファイル: test_all.py プロジェクト: sslavov93/TreasureDungeon
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])
コード例 #34
0
ファイル: weapon_test.py プロジェクト: scdekov/hackbg
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)
コード例 #35
0
ファイル: weapon-test.py プロジェクト: kal0ian/HackBulgaria
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
コード例 #36
0
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)))
コード例 #37
0
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)
コード例 #38
0
ファイル: test_weapon.py プロジェクト: skdls-/Python
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)
コード例 #39
0
ファイル: weapon-test.py プロジェクト: kal0ian/HackBulgaria
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
コード例 #40
0
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)
コード例 #41
0
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)
コード例 #42
0
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)
コード例 #43
0
 def test_Weapon_critical_hit(self):
     my_weapon = Weapon("Axe", 31, 1)
     self.assertTrue(my_weapon.critical_hit())
コード例 #44
0
ファイル: weapon_test.py プロジェクト: betrakiss/HackBulgaria
 def test_critical_hit_false(self):
     another_warglaive = Weapon("Sword (again)", 10, 0)
     self.assertFalse(another_warglaive.critical_hit())
コード例 #45
0
ファイル: weapon_test.py プロジェクト: betrakiss/HackBulgaria
 def test_critical_hit_true(self):
     warglaive = Weapon("Sword", 11, 1)
     self.assertTrue(warglaive.critical_hit())
コード例 #46
0
 def test_Weapon_critical_hit(self):
     my_weapon = Weapon("Axe", 31, 1)
     self.assertTrue(my_weapon.critical_hit())
コード例 #47
0
 def test_critical_hit_false(self):
     another_warglaive = Weapon("Sword (again)", 10, 0)
     self.assertFalse(another_warglaive.critical_hit())
コード例 #48
0
 def test_critical_hit_true(self):
     warglaive = Weapon("Sword", 11, 1)
     self.assertTrue(warglaive.critical_hit())