def addTeam(self, name, numberOfSnails, gravity_direction): """ Add a team to the game @param name: The name of the team @param numberOfSnails: The amount of snails the team has @param gravity_direction: The gravity direction of the team """ team = Team(name) team.setGravity(gravity_direction) team.addSnails(numberOfSnails) team.setTeamImage((gravity_direction+1)) self.teams.append(team)
class TestTeam(unittest.TestCase): """ A test class for the Team module. """ def setUp(self): """ set up data used in the tests. setUp is called before each test function execution. """ self.maxSnails = 3 self.team1 = Team("team1") self.team2 = Team("team2") self.team1.setGravity(Direction.UP) self.team2.setGravity(Direction.DOWN) def testInitialized(self): """ Test if init goes good """ self.assertEqual(self.team1.name, "team1") self.assertEqual(self.team1.hasTurn, False) def testAddSnails(self): self.team1.addSnails(self.maxSnails) self.assertEquals(self.team1.currentSnailWithTurn, self.team1.orderedSnailList[0]) self.assertEqual(len(self.team1.sprites()), self.maxSnails) self.assertEqual(len(self.team1.orderedSnailList), self.maxSnails) self.assertEqual(self.team1.orderedSnailList[0].hasTurn, True) for i in range(0, len(self.team1.orderedSnailList)): if i == 0: self.assertEqual(self.team1.orderedSnailList[i].hasTurn, True) else: self.assertEqual(self.team1.orderedSnailList[i].hasTurn, False) def testNextSnailTurn(self): """ Test if the next time get's the turn """ # test if the currentSnailTurn is 0 self.team1.addSnails(self.maxSnails) # Check when all the snails had the turn, if the first snail gets turn again for i in range(0, self.maxSnails): print i self.assertEqual(self.team1.orderedSnailList[i].hasTurn, True) self.team1.nextSnailTurn() self.assertEqual(self.team1.orderedSnailList[i].hasTurn, False) # check if the first snail in the list has the turn again self.assertEqual(self.team1.orderedSnailList[0].hasTurn, True)
class testSnail(unittest.TestCase): """ A test class for the Snail module. """ def setUp(self): """ set up data used in the tests. setUp is called before each test function execution. """ pygame.init() pygame.display.set_mode([Settings.SCREEN_WIDTH, Settings.SCREEN_HEIGHT]) self.input = Input() self.terrain = Terrain() self.teamName = "EJteam" self.team = Team(self.teamName) self.team.setGravity(Direction.DOWN) self.team.hasTurn = True TurnManager().status = TurnStatus.CURRENTTURN TurnManager().teams = [] TurnManager().teams.append(self.team) self.snail = Snail(self.team) self.snail.hasTurn = True def testInitialized(self): self.assertEqual(self.snail.team.name, self.teamName) # self.assertEqual(self.snail.hasTurn, False) def testFollowMouse(self): self.input.mouse_x = 100 self.input.mouse_y = 100 self.snail.update(self.input, self.terrain) self.assertEqual(self.snail.rect.centerx, 100) self.assertEqual(self.snail.rect.centery, 100) self.input.mouse_x = 150 self.input.mouse_y = 150 self.terrain.addBlock(150, 150) self.snail.update(self.input, self.terrain) self.assertNotEqual(self.snail.rect.centerx, 150) self.assertNotEqual(self.snail.rect.centery, 150) def testSnailPlaceSnailCorrect(self): self.input.mouse_x = 100 self.input.mouse_y = 100 self.input.mouse_left = True self.input.mouse_left_click = True self.snail.update(self.input, self.terrain) self.assertTrue(self.snail.isPlaced) def testSnailPlaceSnailWrong(self): self.input.mouse_x = 150 self.input.mouse_y = 150 self.terrain.addBlock(150, 150) self.input.mouse_left = True self.snail.update(self.input, self.terrain) self.assertFalse(self.snail.isPlaced) def testGravityDown(self): self.testSnailPlaceSnailCorrect() self.team.setGravity(Direction.DOWN) old_y = self.snail.rect.centery for i in range(0,10): self.snail.update(self.input, self.terrain) self.assertTrue(self.snail.rect.centery > old_y) def testGravityDownSpeed(self): self.testSnailPlaceSnailCorrect() self.assertEqual(self.snail.direction['jump'], 0) self.snail.updateGravity() self.assertEqual(self.snail.direction['jump'], self.snail.speed['fall']) waitTurns = 5 / self.snail.speed['fall'] for i in range(0, waitTurns + 5): self.snail.updateGravity() self.assertEqual(self.snail.direction['jump'], 5) def testGravityUp(self): self.testSnailPlaceSnailCorrect() self.snail.gravity_direction = Direction.UP old_y = self.snail.rect.centery for i in range(0,10): self.snail.update(self.input, self.terrain) self.assertTrue(self.snail.rect.centery < old_y) def testGravityRight(self): self.testSnailPlaceSnailCorrect() self.snail.gravity_direction = Direction.RIGHT old_x = self.snail.rect.centerx for i in range(0,10): self.snail.update(self.input, self.terrain) self.assertTrue(self.snail.rect.centerx > old_x) def testGravityLeft(self): self.testSnailPlaceSnailCorrect() self.snail.gravity_direction = Direction.LEFT old_x = self.snail.rect.centerx for i in range(0,10): self.snail.update(self.input, self.terrain) self.assertTrue(self.snail.rect.centerx < old_x) def testAiming(self): pass def testShooting(self): pass def testMoving(self): pass def testJumping(self): pass def testDie(self): self.assertEquals(self.snail.hitpoints, 100) def testCollision(self): pass def testTouchingSalt(self): pass