def test_eat(self) -> None: # energy is full and try to eat human_prins = Human("Prins") self.assertEqual(human_prins.eat(20), 20, "Excess should be 20.") # energy is below 100 and eat more than required human_prins = Human("Prins", energy=90) self.assertEqual(human_prins.eat(20), 10, "Excess should 10.") # energy is below 100 and eat exactly what is required human_prins = Human("Prins", energy=80) self.assertEqual(human_prins.eat(20), 0, "Excess should be 0.") # energy is below 100 and eat less than required human_prins = Human("Prins", energy=70) self.assertEqual(human_prins.eat(20), -10, "Excess should be -10.")
def __repr__(self): return f"planet(humans={self.inhabitants['humans']}, robots={self.inhabitants['robots']})" if (__name__ == "__main__"): #------------------------ planet = Planet() human = Human() robot = Robot() #------------------------ print(planet.__repr__()) print(planet.__str__()) #------------------------ Will = Human("Will", 19) Will.move(30) planet.add_human(Will) Libby = Human("Libby", 11) Libby.move(10) Libby.eat(5) planet.add_human(Libby) #------------------------ Beep = Robot("Beep") Beep.move(60) Beep.eat(25) planet.add_robot(Beep) #------------------------ print("") print(planet.__repr__()) print(planet.__str__())