def testAddRandom(self): fish = animals.Fish() self.river.cells = [ animals.Bear(), animals.Bear(), None, animals.Fish() ] self.river.addRandom(fish) self.assertIsInstance(self.river.cells[2], animals.Fish)
def testNumEmpty(self): self.river.cells = [None, animals.Bear(), None, animals.Fish()] self.assertEqual(self.river.numEmpty(), 2) self.river.cells = [None, None, None, None] self.assertEqual(self.river.numEmpty(), 4) self.river.cells = [ animals.Bear(), animals.Bear(), animals.Fish(), animals.Fish() ] self.assertEqual(self.river.numEmpty(), 0)
def __init__(self, args, seed=None): ''' Constructor @type args: str @param args: input file name. @type args: int @param args: length of the river @type seed: int @param seed: rng seed to update river ''' if seed is not None: self.setSeed(seed) if (isinstance(args, str)): try: file = open(args, "r") file.close() except IOError as err: print(err) elif (isinstance(args, int)): self.cells = [None] * args self.length = args for i in range(self.length): rand = random.choice([None, animals.Bear(), animals.Fish()]) self.cells[i] = rand
import animals #Create an object of Mammals class and call a mathod of it myMammal = animals.Mammals() myMammal.printMembers() #Create an object of Birds class and call a mathod of it myBird = animals.Birds() myBird.printMembers() myFish = animals.Fish() myFish.printMembers()
# Import classes from your brand new package #from animals import Mammals #from animals import Birds #import animals # Create an object of Mammals class & call a method of it #myMammal = animals.Mammals() #myMammal.printMembers() # Create an object of Birds class & call a method of it #myBird = animals.Birds() #myBird.printMembers() import animals m = animals.Mammals() m.printMembers() b = animals.Birds() b.printMembers() f = animals.Fish() f.printMembers()
import animals m = animals.Mammals() m.printMembers() """ b = animals.Birds() b.printMembers() f = animals.Fish() f.printMembers() """ harmless_birds = animals.Birds() harmless_birds.printMembers() dangerous_fish = animals.Fish() dangerous_fish.printMembers()
def testRepr(self): self.river.cells = [ None, animals.Bear(0, "M"), None, animals.Fish(3, "F") ] self.assertEqual(repr(self.river), "——— BM0 ——— FF3")