示例#1
0
 def check_existences(self):
     try:
         zoo.Animal("")
     except NameError:
         self.assertTrue(False, _("Does the class `Animal` exist?"))
     try:
         zoo.Lion("")
     except NameError:
         self.assertTrue(False, _("Does the class `Lion` exist?"))
     try:
         zoo.Owl("")
     except NameError:
         self.assertTrue(False, _("Does the class `Owl` exist?"))
     try:
         zoo.Giraffe("", 1.0)
     except NameError:
         self.assertTrue(False, _("Does the class `Giraffe` exist?"))
     animal = zoo.Animal("")
     self.assertTrue(hasattr(animal, "name"), _("Your class `Animal` does not have an attribute `name`."))
     self.assertTrue(hasattr(animal, "diurnal"), _("Your class `Animal` does not have an attribute `diurnal`."))
     self.assertTrue(hasattr(animal, "nb_legs"), _("Your class `Animal` does not have an attribute `nb_legs`."))
     self.assertTrue(hasattr(animal, "asleep"), _("Your class `Animal` does not have an attribute `asleep`."))
     try:
         my_zoo = zoo.Zoo()
         self.assertTrue(hasattr(my_zoo, "animals"), _("Your class `Zoo` does not have an attribute `animals`."))
         self.assertTrue(hasattr(my_zoo, "add_animal"), _("Your class `Zoo` does not have a method "
                                                          "named `add_animal`."))
         self.assertTrue(hasattr(zoo, "create_my_zoo"), _("Does the class `create_my_zoo()` exists?"))
     except NameError:
         self.assertTrue(False, _("Does the class `Zoo` exist?"))
示例#2
0
def two():
    id = 2
    name = 'Africa Live'
    animal = zoo.Animal('Lion', 'roar', 'whatever it wants', 'dry, arid land')
    neighbors = {}
    neighbors['ne'] = 1
    neighbors['se'] = 9
    neighbors['s'] = 3
    allowExit = False
    return {id: zoo.Location(id, name, animal, neighbors, allowExit)}
示例#3
0
 def test_Animal_constructor(self):
     self.check_existences()
     name = "Pablo"
     animal = zoo.Animal(name)
     self.assertEqual(name, animal.name, _("The name passed to the constructor of `Animal` does not get stored in "
                                           "the attribute `name`."))
     self.assertEqual(None, animal.diurnal, _("The attribute `diurnal` of `Animal` is not set to `None` "
                                              "by default."))
     self.assertEqual(None, animal.nb_legs, _("The attribute `nb_legs` of `Animal` is not set to `None` "
                                              "by default."))
     self.assertFalse(animal.asleep, _("The attribute `asleep` of `Animal` is not set to `False` by default."))
示例#4
0
def seven():
    id = 7
    name = 'Deep Sea'
    animal = zoo.Animal('Sea Serpent', 'ssssssss', 'you',
                        'salt water, preferably 1000 meters deep')
    neighbors = {}
    neighbors['s'] = 6
    neighbors['n'] = 8
    neighbors['w'] = 9
    allowExit = False
    return {id: zoo.Location(id, name, animal, neighbors, allowExit)}
示例#5
0
def five():
    id = 5
    name = 'Elbonia'
    animal = zoo.Animal('Hippophant', 'Moo', 'humans, unicorns',
                        'filthy water, with bugs in it')
    neighbors = {}
    neighbors['n'] = 9
    neighbors['e'] = 4
    neighbors['w'] = 6
    allowExit = False
    return {id: zoo.Location(id, name, animal, neighbors, allowExit)}
示例#6
0
def four():
    id = 4
    name = 'Bird House'
    animal = zoo.Animal('Maquaw', 'squawk, squawk', 'nuts, berries, insects',
                        'clean crisp air')
    neighbors = {}
    neighbors['n'] = 3
    neighbors['e'] = 5
    neighbors['ne'] = 9
    allowExit = False
    return {id: zoo.Location(id, name, animal, neighbors, allowExit)}
示例#7
0
def three():
    id = 3
    name = 'Antarctica'
    animal = zoo.Animal('Penguin', 'silence', 'fish',
                        'cold air with lots of water')
    neighbors = {}
    neighbors['n'] = 2
    neighbors['e'] = 9
    neighbors['s'] = 4
    allowExit = False
    return {id: zoo.Location(id, name, animal, neighbors, allowExit)}
示例#8
0
def getAllFoods():
  foundFoods = []
  file = open('food.csv', 'r')
  for line in file:
    fields = line.rstrip().split(',')
    if len(fields) == 3:
      foodKind = fields[1]
      foodPrice = fields[2]
      foundFoods.append(zoo.Animal(fields[0], foodKind, foodPrice))
  file.close()
  return foundFoods
示例#9
0
    def test_Animal_sleep(self):
        animal = zoo.Animal("Luke")
        animal.sleep()
        self.assertTrue(animal.asleep, _("Calling ``sleep()`` on your animals doesn't set their attribute ``asleep`` "
                                         "to ``True``"))
        animal.wake_up()
        self.assertFalse(animal.asleep, _("Calling ``wake_up()`` on your animals doesn't set their attribute ``asleep``"
                                          " to ``False``"))

        self.assertRaises(RuntimeError, animal.wake_up)
        animal.sleep()
        self.assertRaises(RuntimeError, animal.sleep)
示例#10
0
def six():
    id = 6
    name = 'Enchanted Wood'
    animal = zoo.Animal('Unicorn', 'Giggle Snort',
                        'magic seeds, magic grass, imaginary leaves',
                        'forest full of people who will believe anything')
    neighbors = {}
    neighbors['n'] = 7
    neighbors['w'] = 5
    neighbors['nw'] = 9
    allowExit = False
    return {id: zoo.Location(id, name, animal, neighbors, allowExit)}
示例#11
0
def eight():
    id = 8
    name = 'Cave Land'
    animal = zoo.Animal('Dragon', 'roaring growl',
                        'farm animals, humans, other dragons',
                        'dark caves, with water, and one entrance')
    neighbors = {}
    neighbors['nw'] = 1
    neighbors['sw'] = 9
    neighbors['s'] = 7
    allowExit = False
    return {id: zoo.Location(id, name, animal, neighbors, allowExit)}
示例#12
0
def getFood(foodID):
  foundFood = None
  file = open('animal.csv', 'r')
  for line in file:
    fields = line.rstrip().split(',')
    if len(fields) == 4:
      if foodID == fields[0]:
        animalKind = fields[1]
        animalSound = fields[2]
        animalInfo = fields[3]
        foundFood = zoo.Animal(animalKind, animalSound, animalInfo)
  file.close()
  return foundFood
示例#13
0
def nine():
    id = 9
    name = 'Aquarium'
    animal = zoo.Animal('Seal', 'barking', 'fish and penguins',
                        'water with some dry land')
    neighbors = {}
    neighbors['n'] = 1
    neighbors['nw'] = 2
    neighbors['ne'] = 8
    neighbors['w'] = 3
    neighbors['e'] = 7
    neighbors['sw'] = 4
    neighbors['se'] = 6
    neighbors['s'] = 5
    allowExit = False
    return {id: zoo.Location(id, name, animal, neighbors, allowExit)}
示例#14
0
 def test_Zoo(self):
     self.check_existences()
     my_zoo = zoo.Zoo()
     animal = zoo.Animal("Olga")
     my_zoo.add_animal(animal)
     lion = zoo.Lion("Alex")
     my_zoo.add_animal(lion)
     owl = zoo.Owl("Hedwige")
     my_zoo.add_animal(owl)
     giraffe = zoo.Giraffe("Melman", 2)
     my_zoo.add_animal(giraffe)
     self.assertIn(animal, my_zoo.animals, _("Calling `add_animal(animal)` did not add an animal in the list "
                                             "`animals`."))
     self.assertIn(lion, my_zoo.animals, _("Calling `add_animal(lion)` did not add a lion in the list `animals`."))
     self.assertIn(owl, my_zoo.animals, _("Calling `add_animal(owl)` did not add an owl in the list `animals`."))
     self.assertIn(giraffe, my_zoo.animals, _("Calling `add_animal(giraffe)` did not add a giraffe in the list "
                                              "`animals`."))
示例#15
0
import zoo

# Create an animal.
animal = zoo.Animal("dog")
# The Python object.
print(animal)
# Use the exposed method to show the address of the C++ object.
print("The C++ object is at 0x%016x" % animal.get_address())
# Use the exposed property accessor.
print("I see a \"%s\"" % animal.name)
animal.name = "cat"
print("I see a \"%s\"" % animal.name)
示例#16
0
 def test_Animal_name(self):
     names = ["John", "Jack", "William", "Averell", ""]
     for name in names:
         animal = zoo.Animal(name)
         self.assertEqual(name, animal.name, _("The name passed to the constructor of `Animal` is not stored in "
                                               "the attribute `name`."))