class TestPlant(unittest.TestCase): def setUp(self): self.plant = Plant(100, 10, 910) def test_plant_atributes(self): self.assertEqual(100, self.plant.up_speed) self.assertEqual(10, self.plant.down_speed) self.assertEqual(910, self.plant.desired_height) def test_check_is_true(self): self.assertTrue(self.plant.up_speed) self.assertTrue(self.plant.down_speed) self.assertTrue(self.plant.desired_height) def test_speed_must_be_greater_than_5_or_less_than_1(self): with pytest.raises(ValueError) as ex: self.plant_exception = Plant(101, 10, 910) self.assertEqual(str(ex.value), 'Up Speed Invalid! Acima de 5 ou abaixo de 100') def test_speed_must_be_less_than_2_or_greater_than_speed_up(self): with pytest.raises(ValueError) as ex: self.plant_exception = Plant(100, 102, 910) self.assertEqual(str(ex.value), 'Down Speed Invalid! Acima de 2 ou abaixo do Up Speed!') def test_desired_height_must_be_greater_than_4_or_less_than_1000(self): with pytest.raises(ValueError) as ex: self.plant_exception = Plant(100, 10, 3) self.assertEqual(str(ex.value), 'Desired Height Invalid! Acima de 4 ou abaixo de 1000 apenas!') def test_is_arraived_in_desired_height_is_false(self): self.assertFalse(self.plant.is_arraived_in_desired_height())
def setUp(self): self.plant = Plant(100, 10, 910)
def test_desired_height_must_be_greater_than_4_or_less_than_1000(self): with pytest.raises(ValueError) as ex: self.plant_exception = Plant(100, 10, 3) self.assertEqual(str(ex.value), 'Desired Height Invalid! Acima de 4 ou abaixo de 1000 apenas!')
def test_speed_must_be_greater_than_5_or_less_than_1(self): with pytest.raises(ValueError) as ex: self.plant_exception = Plant(101, 10, 910) self.assertEqual(str(ex.value), 'Up Speed Invalid! Acima de 5 ou abaixo de 100')
def test_speed_must_be_less_than_2_or_greater_than_speed_up(self): with pytest.raises(ValueError) as ex: self.plant_exception = Plant(100, 102, 910) self.assertEqual(str(ex.value), 'Down Speed Invalid! Acima de 2 ou abaixo do Up Speed!')
from Plant.app.plant import Plant class Garden: def __init__(self, plant: Plant): self.plant = plant self.days = 0 def growing_up(self): while True: self.plant.grow_up() self.days += 1 if self.plant.is_arraived_in_desired_height(): break else: self.plant.grow_down() return self.days p = Plant(10,9,4) g = Garden(p) print(g.growing_up())
def test_growing_up_return_10(self): p = Plant(100, 10, 910) g = Garden(p) self.assertEqual(10, g.growing_up())
def test_growing_up_return_26(self): p = Plant(50, 15, 900) g = Garden(p) self.assertEqual(26, g.growing_up())
def test_growing_up_return_8(self): p = Plant(90, 30, 500) g = Garden(p) self.assertEqual(8, g.growing_up())
def test_growing_up_return_1(self): p = Plant(10, 9, 4) g = Garden(p) self.assertEqual(1, g.growing_up())