def testAdd(self): # add single fish to tank aq = Aquarium() self.assertEqual(aq.fishes, []) aq.addFish(Tang("test", 1, 'red', False)) self.assertEqual(len(aq.fishes), 1) self.assertIsInstance(aq.fishes[0], Tang) # add list of fishes to tank aq = Aquarium() self.assertEqual(aq.fishes, []) aq.addFish([Tang("test", 1, 'red', False)]) self.assertEqual(len(aq.fishes), 1) self.assertIsInstance(aq.fishes[0], Tang) # add list with multiple elements to tank aq = Aquarium() self.assertEqual(aq.fishes, []) aq.addFish([ Tang("test", 1, 'red', False), Clownfish("test", 1, 'red', 'blue') ]) self.assertEqual(len(aq.fishes), 2) self.assertIsInstance(aq.fishes[1], Clownfish) # add multiple elements to a list with existing elements aq = Aquarium(Tang("test", 1, 'red', False)) aq.addFish([ Tang("test", 1, 'red', False), Clownfish("test", 1, 'red', 'blue') ]) self.assertEqual(len(aq.fishes), 3)
def testInit(self): # single element in list aq = Aquarium([Tang("test", 1, 'red', False)]) self.assertEqual(len(aq.fishes), 1) self.assertIsInstance(aq.fishes[0], Tang) # multiple elements in list aq = Aquarium([ Tang("test", 1, 'red', False), Clownfish("test", 1, 'red', 'blue') ]) self.assertEqual(len(aq.fishes), 2) self.assertIsInstance(aq.fishes[1], Clownfish) # empty list aq = Aquarium() self.assertEqual(aq.fishes, [])
def testgetstatus(self): # single element aq = Aquarium([Tang("test", 12, 'red', False)]) self.assertEqual( aq.getStatus(), "test, weight: 12, color: red, short-term memory loss: false") # empty list aq = Aquarium() self.assertEqual(aq.getStatus(), '') # two lists aq = Aquarium([ Tang("test", 1, 'red', False), Clownfish("test", 1, 'red', 'blue') ]) self.assertEqual( aq.getStatus(), "test, weight: 1, color: red, short-term memory loss: falsetest, weight: 1, color: red, stripes: blue" )
def testStatus(self): it = Clownfish("It", 5, "white", "red") self.assertEqual(it.status(), 'It, weight: 5, color: white, stripes: red')
def testFeed(self): it = Clownfish("It", 5, "white", "red") it.feed() self.assertEqual(it.weight, 6)
def testInit(self): it = Clownfish("It", 5, "white", "red") self.assertEqual(it.name, "It") self.assertEqual(it.weight, 5) self.assertEqual(it.color, "white") self.assertEqual(it.stripes, "red")
from Aquarium import Aquarium from Fish import Tang, Kong, Clownfish def printPretty(text): print() print(text) print("=" * len(text)) print() if __name__ == "__main__": printPretty("Adding four little fishes...") aq = Aquarium() aq.addFish(Tang("Lory", 10, "blue", False)) aq.addFish([Clownfish("Serge", 5, "white", "green")]) aq.addFish( [Clownfish("Tibald", 11, "blue", "green"), Kong("Georgie", 10, "red")]) aq.getStatus() printPretty("Feed those little fishes...") aq.feed() printPretty("Now let's remove the fat ones...") aq.removeFish() aq.getStatus()