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 TestTimer(unittest.TestCase): """ A test class for the Timer module. """ def setUp(self): """ set up data used in the tests. setUp is called before each test function execution. """ self.teams= [] self.team1 = Team("team1") self.team2 = Team("team2") pygame.init() self.team1.addSnails(2) self.team2.addSnails(3) self.teams.append(self.team1) self.teams.append(self.team2) self.turnManager = TurnManager() self.turnManager.setTeams(self.teams) # def testInitialized(self): # """ # Test if init goes good # """ # self.assertEqual(self.turnManager.teams, self.teams) # self.assertEqual(self.turnManager.teams[0], self.team1) # self.assertEqual(self.turnManager.teams[1], self.team2) # # self.assertEqual(self.turnManager.status, TurnStatus.BREAK) # self.assertEqual(self.turnManager.startTime, Settings.TIMER_STARTTIME) # self.assertEqual(self.turnManager.size, Settings.TIMER_SIZE) # self.assertEqual(self.turnManager.position, Settings.TIMER_POSITION) # self.assertEqual(self.turnManager.font_size, Settings.TIMER_FONT_SIZE) def testSingleton(self): """ Test if the singleton works """ turnmanager2 = TurnManager() self.assertEqual(id(self.turnManager), id(turnmanager2))
class TestWeapon(unittest.TestCase): """ A test class for the Weapon module. """ def setUp(self): """ set up data used in the tests. setUp is called before each test function execution. """ self.turnManager = TurnManager() self.teams = [] self.team = Team("Akatsuki") self.team.addSnails(1) self.teams.append(self.team) self.turnManager.setTeams(self.teams) self.snail = None for snail in self.team.sprites(): self.snail = snail self.weapon = Weapon("Canon", 20) self.weapon.ammo = 5 def testInitialized(self): """ Test if init goes good """ self.assertEqual(self.weapon.name, "Canon") self.assertEqual(self.weapon.power, 20) self.assertEqual(self.weapon.ammo, 5) def testShoot(self): self.weapon.shoot() self.assertEqual(self.weapon.ammo, 4)
class TestTimer(unittest.TestCase): """ A test class for the Timer module. """ def setUp(self): """ set up data used in the tests. setUp is called before each test function execution. """ pygame.init() self.teams= [] self.team1 = Team("team1") self.team2 = Team("team2") self.team1.addSnails(3) self.team2.addSnails(3) self.teams.append(self.team1) self.teams.append(self.team2) self.turnManager = TurnManager() self.turnManager.setTeams(self.teams) def testInitialized(self): """ Test if init goes good """ self.assertEqual(self.turnManager.teams, self.teams) self.assertEqual(self.turnManager.teams[0], self.team1) self.assertEqual(self.turnManager.teams[1], self.team2) self.assertEqual(self.turnManager.status, TurnStatus.BREAK) self.assertEqual(self.turnManager.startTime, Settings.TIMER_STARTTIME) self.assertEqual(self.turnManager.size, Settings.TIMER_SIZE) self.assertEqual(self.turnManager.position, Settings.TIMER_POSITION) self.assertEqual(self.turnManager.font_size, Settings.TIMER_FONT_SIZE) def testSingleton(self): """ Test if the singleton works """ turnmanager2 = TurnManager() self.assertEqual(id(self.turnManager), id(turnmanager2)) self.assertEqual(self.turnManager._instance, turnmanager2._instance) def testTimer(self): """ Test if the turnManager's status switches from CurrentTurn to Break when counter is 0 """ self.assertEqual(self.turnManager.status, TurnStatus.BREAK) #print self.turnManager.started self.turnManager.startTimer() time.sleep(Settings.TIMER_BREAKTIME + 2) self.assertEqual(self.turnManager.status, TurnStatus.CURRENTTURN) time.sleep(Settings.TIMER_STARTTIME + 2) self.assertEqual(self.turnManager.status, TurnStatus.BREAK) self.turnManager.stopTimer() def testCurrentTurn(self): """ Test if the turnManager's status switches from Break to CurrentTurn when counter is 0 """ self.assertEqual(self.turnManager.status, TurnStatus.BREAK) #print self.turnManager.started self.turnManager.startTimer() time.sleep(Settings.TIMER_BREAKTIME + 1) self.assertEqual(self.turnManager.status, TurnStatus.CURRENTTURN) self.turnManager.stopTimer() def testChangeTurn(self): self.assertEqual(self.team1.hasTurn, True) self.turnManager.changeTurn() self.assertEqual(self.team1.hasTurn, False) self.assertEqual(self.team2.hasTurn, True) se def testChangeTurnTeam(self): """ Test if the next time get's the turn """ self.turnManager.startTimer() self.assertEqual(self.turnManager.teams[0].hasTurn, True) time.sleep(Settings.TIMER_BREAKTIME + Settings.TIMER_STARTTIME + 5) self.assertEqual(self.turnManager.teams[0].hasTurn, False) self.assertEqual(self.turnManager.teams[1].hasTurn, True) self.turnManager.stopTimer() def testChangeTurnSnail(self): """ Test if the next snail get's the turn """ a = 1 def testFirstTurnTeam(self): """ Test if the first team in the team list got the turn when the turnManager starts """ self.turnManager.startTimer() time.sleep(2) self.assertEqual(self.turnManager.teams[0].hasTurn, True) self.assertEqual(self.turnManager.teams[1].hasTurn, False) self.turnManager.stopTimer() def testFirstTurnSnail(self): """ Test if the first snail of the team who got the turn has the turn """ # the first snail who gets the turn is the first snail of team 1 firstSnailID = self.turnManager.teams[0].currentSnailTurn # the 2nd snail who gets the turn is the first snail of team 2 secondSnailID = self.turnManager.teams[1].currentSnailTurn self.turnManager.startTimer() self.assertEqual(self.turnManager.teams[0].hasTurn, True) self.assertEqual(self.turnManager.teams[0].currentSnailTurn, firstSnailID) # time.sleep(Settings.TIMER_BREAKTIME + Settings.TIMER_STARTTIME + 5) # # self.assertEqual(self.turnManager.teams[0].hasTurn, False) # self.assertEqual(self.turnManager.teams[1].hasTurn, True) # self.assertEqual(self.turnManager.teams[1].currentSnailTurn, secondSnailID) self.turnManager.stopTimer()