def testSquadValidation(self): self.squad = pyBBSquad.BBSquad(self.teamparser, "Amazonen") p1 = pyBBPlayer.BBPlayer("Heino", "Chaos", "Tiermensch", self.teamparser, self.skillparser) p2 = pyBBPlayer.BBPlayer("Ludwig", "Chaoszwerge", "Hobgoblin", self.teamparser, self.skillparser) p3 = pyBBPlayer.BBPlayer("Rudi", "Amazonen", "Werfer", self.teamparser, self.skillparser) self.assertEqual(self.squad.isValidPlayer(p1), False, "Player should not be valid") self.assertEqual(self.squad.isValidPlayer(p2), False, "Player should not be valid") self.assertEqual(self.squad.isValidPlayer(p3), True, "Player should be valid")
def testSquadSize(self): self.squad = pyBBSquad.BBSquad(self.teamparser, "Amazonen") p1 = pyBBPlayer.BBPlayer("Heino", "Amazonen", "Blitzer", self.teamparser, self.skillparser) p2 = pyBBPlayer.BBPlayer("Ludwig", "Amazonen", "Werfer", self.teamparser, self.skillparser) p3 = pyBBPlayer.BBPlayer("Rudi", "Amazonen", "Werfer", self.teamparser, self.skillparser) self.squad.addPlayer(1, p1) self.squad[2] = p2 self.failUnless(len(self.squad) == 2, "Wrong number of squad members") self.squad.removePlayer(2) self.failUnless(len(self.squad) == 1, "Wrong number of squad members") self.squad.addPlayer(1, p3) self.failUnless(len(self.squad) == 1, "Wrong number of squad members") self.squad.removePlayer(1) self.failUnless(len(self.squad) == 0, "Wrong number of squad members")
def testSquadGetPlayers(self): self.squad = pyBBSquad.BBSquad(self.teamparser, "Amazonen") p1 = pyBBPlayer.BBPlayer("Lara", "Amazonen", "Feldspieler", self.teamparser, self.skillparser) p2 = pyBBPlayer.BBPlayer("Tara", "Amazonen", "Feldspieler", self.teamparser, self.skillparser) p3 = pyBBPlayer.BBPlayer("Mara", "Amazonen", "Werfer", self.teamparser, self.skillparser) self.squad.addPlayer(1, p1) self.squad.addPlayer(3, p2) self.squad.addPlayer(5, p3) playersdict = self.squad.getPlayers() self.failUnless( type(playersdict) == type({}), "Method getPlayers() should return a dictionary") self.failUnless(playersdict.has_key(1), "Player dictionary should contain no 1") self.failUnless(playersdict.has_key(3), "Player dictionary should contain no 3") self.failUnless(playersdict.has_key(5), "Player dictionary should contain no 5") self.failIf(playersdict.has_key(2), "Player dictionary should not contain no 2")
"""-> dict Return all players in a dictionary. See pyBBPlayer.BBPlayer.""" return self.players def __len__(self): """-> int Return size of the squad.""" return len(self.players) def __repr__(self): """String representation of the squad.""" repr = "<BBTeam %s at %s>" % (self.max, hex(id(self))) return repr if __name__ == "__main__": teamparser = pyBBParser.BBTeamParser() skillparser = pyBBParser.BBSkillParser() s = BBSquad(teamparser, "Amazonen") p1 = pyBBPlayer.BBPlayer("Heino", "Amazonen", "Blitzer", teamparser, skillparser) p2 = pyBBPlayer.BBPlayer("Ludwig", "Amazonen", "Werfer", teamparser, skillparser) p3 = pyBBPlayer.BBPlayer("Rudi", "Amazonen", "Werfer", teamparser, skillparser) s.addPlayer(1, p1) s[2] = p2 print s.getPlayers() print len(s) s.removePlayer(2) print s.getPlayers() print len(s) s[4] = p2
Returns a tuple of teamproperties (Teamname, Coach, Cheerleader, etc).""" props = (self.teamname, self.team, self.coach, self.fanfactor, self.cheerleader, self.apothecary) return props def getSquad(self): """-> list Returns all players in a list. See pyBBPlayer.py and BBPlayer.""" return self.squad def __delitem__(self, index): """Remove a player from the team rooster at a given index.""" self.squad.removePlayer(index) def __repr__(self): """String representation of the team.""" repr = "<BBTeam %s %s>" % (self.teamname, hex(id(self))) return repr if __name__ == "__main__": team = BBTeam("Rippers", "Chaos", "Borak Killer", 4, 3) player1 = pyBBPlayer.BBPlayer("Hugo Schwarzhuf", "Chaos", unicode("Tiermensch", "latin-1")) player2 = pyBBPlayer.BBPlayer("Benni Schwarzhuf", "Chaos", unicode("Tiermensch", "latin-1")) team.buyPlayer(player1, 1) team.buyPlayer(player2, 2) team.buyCheerleaders(2) team.buyRerolls(2) print team.__repr__().encode("latin-1")