def test_remove_animal(self): jungle = Jungle() dog = Predator(power=10, speed=70) jungle.add_animal(dog) self.assertDictEqual(jungle.animals, {dog.id: dog}) jungle.remove_animal(dog) self.assertDictEqual(jungle.animals, {})
def test_jungle_is_iterable(self): jungle = Jungle() animals = [Predator(power=10, speed=70), Predator(power=5, speed=40)] for animal in animals: jungle.add_animal(animal) try: animals_from_jungle = [a for a in jungle] self.assertEqual(animals, animals_from_jungle) except TypeError: self.assertTrue(False, "Jungle is not iterable")
from jungle import Jungle import pygame as pg import time run = True timeLimit = int(input("Enter snake speed (try 100): ")) keyHit = False #change me...use wasd for first snake #rows, cols, size, number of snakes, length of snakes, number of apples, number added on contact with apple jungle = Jungle() pg.init() while run: jungle.screen.fill((0, 0, 0)) for event in pg.event.get(): if event.type == pg.QUIT: run = False if event.type == pg.KEYDOWN and event.key in jungle.keys: tuple = jungle.keys[event.key] snake = jungle.snakes[tuple[0]] snake.changeDir(tuple[1]) jungle.moveSnakes() pg.display.update() time.sleep(timeLimit / 5000)
def setUp(self): self.jungle = Jungle()