本文整理汇总了Python中animal.Animal.grow方法的典型用法代码示例。如果您正苦于以下问题:Python Animal.grow方法的具体用法?Python Animal.grow怎么用?Python Animal.grow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类animal.Animal
的用法示例。
在下文中一共展示了Animal.grow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestAnimal
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import grow [as 别名]
class TestAnimal(unittest.TestCase):
def setUp(self):
self.animal = Animal('Snake', 'Pypy', 12, 'male', 63)
def test_animal_init(self):
self.assertEqual(self.animal.species, 'Snake')
self.assertEqual(self.animal.name, 'Pypy')
self.assertEqual(self.animal.age, 12)
self.assertEqual(self.animal.weight, 63)
def test_animal_eat(self):
self.animal.eat()
self.assertEqual(self.animal.weight, 66.15)
def test_animal_grow(self):
self.animal.grow()
self.assertEqual(self.animal.age, 13)
self.assertEqual(self.animal.weight, 64.26)
def test_animal_dies(self):
result = []
for i in range(100):
result.append(self.animal.is_dead())
self.assertIn(True, result)
self.assertIn(False, result)
示例2: Animal_test
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import grow [as 别名]
class Animal_test(unittest.TestCase):
def setUp(self):
self.my_animal = Animal("bear", 5, "puh", "m", 150, 10)
def test_init(self):
self.assertEqual(self.my_animal.species, "bear")
self.assertEqual(self.my_animal.age, 5)
self.assertEqual(self.my_animal.name, "puh")
self.assertEqual(self.my_animal.gender, "m")
self.assertEqual(self.my_animal.weight, 150)
self.assertTrue(self.my_animal.alive)
self.assertEqual(self.my_animal.life_expectancy, 10)
def test_grow(self):
self.my_animal.grow()
self.assertEqual(self.my_animal.age, 6)
self.assertEqual(self.my_animal.weight, 151)
def test_eat(self):
self.my_animal.eat()
self.assertEqual(self.my_animal.weight, 151)
def test_should_die(self):
flag_die = False
flag_alive = False
for i in range(0, 100):
self.my_animal.should_die()
if not self.my_animal.alive:
flag_die = True
else:
flag_alive = True
self.assertTrue(flag_die and flag_alive)
示例3: TestAnimal
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import grow [as 别名]
class TestAnimal(unittest.TestCase):
def setUp(self):
self.animal = Animal("tiger", 10, "Tig", "male", 175)
def test_properties(self):
self.assertEqual(self.animal.specie, "tiger")
self.assertEqual(self.animal.age, 10)
self.assertEqual(self.animal.name, "Tig")
self.assertEqual(self.animal.gender, "male")
self.assertEqual(self.animal.weight, 175)
def test_grow(self):
self.animal.grow(250, 15.1)
self.assertEqual(11, self.animal.age)
self.assertEqual(190.1, self.animal.weight)
def test_grow_again(self):
self.animal.grow(175, 2)
self.assertEqual(11, self.animal.age)
self.assertEqual(175, self.animal.weight)
def test_eat(self):
self.assertEqual(17.5, self.animal.eat(0.1))
def test_die(self):
is_dead = self.animal.die(3)
self.assertEqual(False, is_dead)
示例4: TestAnimal
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import grow [as 别名]
class TestAnimal(unittest.TestCase):
def setUp(self):
self.my_animal = Animal("cat", 5, "Cattie", "female", 4, 15, True, 9)
def test_init(self):
self.assertEqual(self.my_animal.species, "cat")
self.assertEqual(self.my_animal.age, 5)
self.assertEqual(self.my_animal.name, "Cattie")
self.assertEqual(self.my_animal.gender, "female")
self.assertEqual(self.my_animal.weight, 4)
self.assertEqual(self.my_animal.life_expectancy, 15)
self.assertTrue(self.my_animal.is_vegetarian)
def test_grow(self):
self.my_animal.grow(2, 2)
self.assertEqual(self.my_animal.age, 7)
self.assertEqual(self.my_animal.weight, 6)
def test_eat(self):
self.my_animal.eat(5000)
self.assertEqual(self.my_animal.weight, 5004)
示例5: TestAnimals
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import grow [as 别名]
class TestAnimals(unittest.TestCase):
def setUp(self):
self.animal = Animal("tiger", 30, "Kumcho", "male", 60)
def test_init(self):
animal = Animal("Tiger", 20, "Dingo", "male", 90)
self.assertEqual(animal.species, "Tiger")
self.assertEqual(animal.age, 20)
self.assertEqual(animal.name, "Dingo")
self.assertEqual(animal.gender, "male")
self.assertEqual(animal.weight, 90)
def test_load_json_invalid_file(self):
with self.assertRaises(FileNotFoundError):
self.animal.load_json(str(uuid4()))
def test_load_json_success(self):
self.animal.load_json("database.json")
self.assertEqual(self.animal.life_expectancy, 20.0)
self.assertEqual(self.animal.food_type, "meat")
def test_load_json_invalid_species(self):
test_animal = Animal(str(uuid4()), 10, "TEST", "male", 15)
with self.assertRaises(ValueError):
test_animal.load_json("database.json")
def test_get_current_animal_year(self):
self.assertEqual(self.animal.get_current_animal_year(), 3)
def test_get_chance_of_dying_valid_life_expectancy(self):
self.animal.load_json("database.json")
self.assertEqual(self.animal.get_chance_of_dying(), 0.15)
def test_grow(self):
self.animal.load_json("database.json")
self.animal.grow()
self.assertEqual(self.animal.age, 31)
self.assertEqual(self.animal.weight, 60.8)
def test_eat(self):
self.animal.load_json("database.json")
self.animal.eat()
self.assertEqual(self.animal.weight, 60.6)
def test_is_alive(self):
self.animal.load_json("database.json")
dead_or_alive = set()
for i in range(100):
status = self.animal.is_alive()
dead_or_alive.add(status)
self.assertEqual(len(dead_or_alive), 2)
示例6: test_grow
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import grow [as 别名]
def test_grow(self):
self.puh_panda.grow(5)
self.assertEqual(self.puh_panda.age, 25)
self.assertEqual(self.puh_panda.weight, 101.5)
self.assertEqual(self.puh_panda.relax_period, 25)
self.assertEqual(self.puh_panda.gestination_period, 0)
yana_tiger = Animal("tiger", 5, "Yana", "female", 30)
yana_tiger.is_pregnant = True
yana_tiger.grow(5)
self.assertEqual(yana_tiger.relax_period, 0)
ivo_tiger = Animal("tiger", 5, "Ivo", "female", 101)
ivo_tiger.grow(5)
#cannot get bigger anymore, it is fat enough
self.assertEqual(ivo_tiger.weight, 101)
示例7: TestAnimal
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import grow [as 别名]
class TestAnimal(unittest.TestCase):
def setUp(self):
self.testAnimal = Animal("Tiger", 2, "Name", "Male", 50)
self.femaleAnimal = Animal('Tiger', 3, 'Penka', "Female", 5)
def tearDown(self):
Animal.NAMES = {}
def test_init(self):
self.assertEqual(self.testAnimal.species, "Tiger")
self.assertEqual(self.testAnimal.age, 2)
self.assertEqual(self.testAnimal.name, "Name")
self.assertEqual(self.testAnimal.gender, "Male")
self.assertEqual(self.testAnimal.weight, 50)
def test_equal_names_raises_error(self):
with self.assertRaises(NameError):
self.testAnimal2 = Animal("Tiger", 2, "Name", "Female", 50)
def test_grow_older(self):
self.testAnimal.grow()
self.assertEqual(self.testAnimal.age, 3)
def test_gestation(self):
self.femaleAnimal.in_gestation = True
self.femaleAnimal.grow()
self.assertEqual(self.femaleAnimal.gestation, 209)
def test_eating_price_for_carnivore(self):
result = self.testAnimal.eating_price()
self.assertEqual(result, 200*0.3)
def test_eating_price_for_herbivore(self):
self.testAnimal2 = Animal("Rabbit", 1, "Zaek", "Male", 15)
result = self.testAnimal2.eating_price()
self.assertEqual(result, 30*0.1)
def test_is_dead_when_already_dead(self):
self.testAnimal.is_alive = False
result = self.testAnimal.is_dead()
self.assertTrue(result)
def test_is_dead_when_not_dead(self):
result = self.testAnimal.is_dead()
for i in range(0, 100):
self.assertIn(result, [True, False])
示例8: AnimalTests
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import grow [as 别名]
class AnimalTests(unittest.TestCase):
def setUp(self):
self.animal = Animal("tiger", 144, "DiviaLud", "male", 300)
def test_init(self):
self.assertEqual(self.animal.species, "tiger")
self.assertEqual(self.animal.age, 144)
self.assertEqual(self.animal.name, "DiviaLud")
self.assertEqual(self.animal.gender, "male")
self.assertEqual(self.animal.weight, 300)
def test_grow(self):
self.animal.grow(2, 50)
self.assertEqual(self.animal.age, 146)
self.assertEqual(self.animal.weight, 350)
def test_eat_meat(self):
self.animal.eat("meat", 4)
self.assertGreater(self.animal.weight, 12)
self.assertEqual(self.animal.meat_eaten, 4)
#self.assertEqual(self.animal.Zoo.available_meat, 296)
self.animal.eat("meat", 4)
self.assertGreater(self.animal.weight, 16)
self.assertEqual(self.animal.meat_eaten, 8)
#self.assertEqual(self.animal.Zoo.available_meat, 292)
def test_eat_grass(self):
self.animal.eat("grass", 4)
self.assertGreater(self.animal.weight, 12)
self.assertEqual(self.animal.grass_eaten, 4)
#self.assertEqual(self.animal.Zoo.available_grass, 196)
self.animal.eat("grass", 4)
self.assertGreater(self.animal.weight, 16)
self.assertEqual(self.animal.grass_eaten, 8)
#self.assertEqual(self.animal.Zoo.available_grass, 192)
def test_die(self):
died_or_not = []
for i in range(100):
died_or_not.append(self.animal.die(180))
self.assertIn(True, died_or_not)
self.assertIn(False, died_or_not)
示例9: AnimalTests
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import grow [as 别名]
class AnimalTests(unittest.TestCase):
def setUp(self):
self.test_animal = Animal("Tiger", 5, "Gencho", "male", 350, 10, "carnivore",
50, 400, 25, (1, 50))
def test_animal_grow(self):
self.test_animal.grow(2)
self.assertEqual(self.test_animal.weight, 400)
self.assertEqual(self.test_animal.age, 7)
def test_animal_consume(self):
self.assertEqual(self.test_animal.consume(), 7)
def test_animal_is_alive(self):
self.assertTrue(self.test_animal.is_alive)
for x in range(0, 10):
self.test_animal.should_die()
self.assertFalse(self.test_animal.is_alive)
示例10: TestAnimal
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import grow [as 别名]
class TestAnimal(unittest.TestCase):
def setUp(self):
self.cat_animal = Animal("cat", 365, "Pena", "Female", 5, 5475)
def test_animal_init(self):
self.assertEqual("cat", self.cat_animal.species)
self.assertEqual(365, self.cat_animal.age)
self.assertEqual("Pena", self.cat_animal.name)
self.assertEqual("Female", self.cat_animal.gender)
self.assertEqual(5, self.cat_animal.weight)
self.assertEqual(5475, self.cat_animal.life_expectancy)
def test_grow(self):
self.cat_animal.grow(2, 1)
self.assertEqual(366, self.cat_animal.age)
self.assertEqual(7, self.cat_animal.weight)
def test_eat(self):
self.cat_animal.eat(2)
self.assertEqual(7, self.cat_animal.weight)
def test_dying(self):
self.assertFalse(self.cat_animal.dying())
示例11: test_grow_bear
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import grow [as 别名]
def test_grow_bear(self):
animal = Animal("bear", 2, "MecoPug", "male", 300)
animal.grow()
self.assertEqual(animal.age, 3)
self.assertEqual(animal.weight, 305)
示例12: test_grow_tiger
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import grow [as 别名]
def test_grow_tiger(self):
animal = Animal("tiger", 2, "TegavTiger", "male", 300)
animal.grow()
self.assertEqual(animal.age, 3)
self.assertEqual(animal.weight, 305)
示例13: test_grow_panda
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import grow [as 别名]
def test_grow_panda(self):
animal = Animal("panda", 1, "Ivo", "male", 300)
animal.grow()
self.assertEqual(animal.age, 2)
self.assertEqual(animal.weight, 304)
示例14: AnimalTests
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import grow [as 别名]
class AnimalTests(unittest.TestCase):
def test__init(self):
self.animal = Animal("bear", 14, "Poll 1", 'male', 10.0)
self.assertEqual("bear", self.animal.species)
self.assertEqual(14, self.animal.age_in_months)
self.assertEqual("Poll 1", self.animal.name)
self.assertEqual('male', self.animal.gender)
self.assertEqual(10.0, self.animal.kilos_weight)
self.assertEqual({"bear": ["Poll 1"]}, self.animal.SPECIES_NAMES)
self.assertEqual({"life_expectancy": 12,
"food_type": "meat",
"gestation_period": 6,
"newborn_weight": 20,
"average_weight": 100,
"weight_age_ratio": 9,
"food_weight_ratio": 0.2},
self.animal.json_species_data)
# Трябва ли да тествам невалидни Animal обекти,
# ако тествам set методите за данните?
def test_set_species(self):
self.animal = Animal("bear", 14, "Poll 2", 'male', 10.0)
self.assertEqual("bear", self.animal._Animal__set_species("bear"))
def test_set_species_no_such_species_in_database_value_error(self):
self.animal = Animal("bear", 14, "Poll 3", 'male', 10.0)
self.animal.json_species_data = None
with self.assertRaises(ValueError):
self.animal._Animal__set_species("seagull")
def test_set_name(self):
self.animal = Animal("bear", 14, "Poll 4", 'male', 10.0)
self.assertEqual("Mark", self.animal._Animal__set_name("Mark"))
def test_set_name_already_exists_value_error(self):
self.animal = Animal("bear", 14, "Poll 5", 'male', 10.0)
with self.assertRaises(ValueError):
self.animal._Animal__set_name("Poll 5")
def test_set_gender(self):
self.animal = Animal("bear", 14, "Poll 6", 'male', 10.0)
self.assertEqual("female", self.animal._Animal__set_gender("female"))
def test_set_gender_value_error(self):
self.animal = Animal("bear", 14, "Poll 7", 'male', 10.0)
with self.assertRaises(ValueError):
self.animal._Animal__set_gender("tomato")
def test_set_kilos_weight_passed_argument(self):
self.animal = Animal("bear", 14, "Poll 8", 'male', 10.0)
self.assertEqual(42, self.animal._Animal__set_kilos_weight(42))
def test_set_kilos_weight_no_passed_argument_take_newborn_weight(self):
self.animal = Animal("bear", 14, "Poll 9", 'male', 2)
self.assertEqual(self.animal.json_species_data['newborn_weight'],
self.animal._Animal__set_kilos_weight(None))
def test_set_json_species_data_species_not_in_database(self):
self.animal = Animal("bear", 14, "Poll 10", 'male', 10.0)
self.assertEqual(None, self.animal._Animal__set_json_species_data(
"database.json", "seagull"))
def test_grow(self):
self.animal_male = Animal("bear", 3, "Poll 11", 'male', 10.0)
self.animal_male.grow(3)
self.assertEqual(54, self.animal_male.kilos_weight)
self.assertEqual(6, self.animal_male.age_in_months)
def test_weight_simulated_time_average_weight_reached(self):
self.animal = Animal("bear", 3, "Poll 12", 'male', 10.0)
self.animal.grow(10)
self.assertEqual(100, self.animal.kilos_weight)
def test_pregnancy_simulated_time_pregnant_female(self):
self.animal_female = Animal("bear", 13, "Pollinka 1", 'female', 10.0)
self.animal_female.pregnant_period = 4
self.animal_female.non_pregnant_period = None
self.animal_female.grow(3)
self.assertEqual(6, self.animal_female.pregnant_period)
self.assertEqual(None, self.animal_female.non_pregnant_period)
def test_pregnancy_simulated_time_non_pregnant_female(self):
self.animal_female = Animal("bear", 13, "Pollinka 2", 'female', 10.0)
self.animal_female.non_pregnant_period = 7
self.animal_female.grow(3)
self.assertEqual(6, self.animal_female.non_pregnant_period)
self.assertEqual(None, self.animal_female.pregnant_period)
def test_eat(self):
self.animal = Animal("bear", 3, "Poll 13", 'male', 10.0)
self.assertEqual(2, self.animal.eat())
def test_die(self):
# I don't know how to test this function
# because it interacts with the global dictionary of names in Animal
# and that brings some limitations
pass
#.........这里部分代码省略.........
示例15: TestAnimal
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import grow [as 别名]
class TestAnimal(unittest.TestCase):
def setUp(self):
self.tiger = Animal('tiggy', 'tiger', 'male', 1, 5)
self.hippo = Animal('hippy', 'hippo', 'female', 1, 50)
def test_get_name(self):
self.assertEqual('tiggy', self.tiger.get_name())
self.assertEqual('hippy', self.hippo.get_name())
def test_get_species(self):
self.assertEqual('tiger', self.tiger.get_species())
self.assertEqual('hippo', self.hippo.get_species())
def test_get_gender(self):
self.assertEqual('male', self.tiger.get_gender())
self.assertEqual('female', self.hippo.get_gender())
def test_get_weight(self):
self.assertEqual(5, self.tiger.get_weight())
self.assertEqual(50, self.hippo.get_weight())
def test_Get_age(self):
self.assertEqual(0, self.tiger.get_age())
self.assertEqual(0, self.hippo.get_age())
def test_grow_by_age(self):
self.tiger.grow(365, cursor)
self.hippo.grow(365, cursor)
self.assertEqual(1, self.tiger.get_age())
self.assertEqual(1, self.hippo.get_age())
def test_grow_by_weight(self):
self.tiger.grow(1*32, cursor)
self.hippo.grow(1*32, cursor)
self.assertEqual(17, int(self.tiger.get_weight()))
self.assertEqual(52, int(self.hippo.get_weight()))
def test_grow_when_average_weight_is_reached(self):
self.tiger.grow(10000, cursor)
self.assertEqual(250, self.tiger.get_weight())
def get_food_type(self):
self.assertEqual('carnivore', self.tiger.get_food_type())
self.assertEqual('herbivore', self.hippo.get_food_type())
def test_get_food_weight_ratio(self):
self.assertEqual(25, self.hippo.get_food_weight_ratio())
self.assertEqual(0.06, self.tiger.get_food_weight_ratio())
def test_eat(self):
self.assertEqual(1.2, self.tiger.eat(1))#amount of food eaten in 1 day
self.assertEqual(2500, self.hippo.eat(1))# hippoes are expensive
def test_get_gestation_period(self):
self.assertEqual(4, self.tiger.get_gestation_period())
self.assertEqual(8, self.hippo.get_gestation_period())
def test_death_when_age_is_above_average(self):
self.tiger.grow(10000, cursor)
self.assertTrue(self.tiger.die())