Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
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
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
# 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()

Ejemplo n.º 6
0
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()
Ejemplo n.º 7
0
 def testRepr(self):
     self.river.cells = [
         None, animals.Bear(0, "M"), None,
         animals.Fish(3, "F")
     ]
     self.assertEqual(repr(self.river), "——— BM0 ——— FF3")