def test_attack_human(self): playerAux = HumanPlayers("Pepe", 35, "orange", []) expectedOrigin = "Europa del sur" expectedDestiny = "Europa del norte" attacked = playerAux.attack("Europa del sur", "Europa del norte", 3) self.assertEqual(expectedOrigin, attacked[0]) self.assertEqual(expectedDestiny, attacked[1])
def test_phaseonecomplete(self): p1 = HumanPlayers("Pepe", initBattalions, "orange", []) p2 = HumanPlayers("Ana", initBattalions, "red", []) p3 = HumanPlayers("Yo", initBattalions, "blue", []) playersExpected = [p1, p2, p3] tidyrolls = [3, 5, 2] game = Game() game.initboard() firstPlayer = game.firstplayer(tidyrolls, playersExpected) orderedPlayers = ArrayPlayers().orderplayers(playersExpected, firstPlayer) self.assertEqual(orderedPlayers[0].isequal(playersExpected[1]), True) self.assertEqual(orderedPlayers[1].isequal(playersExpected[0]), True) self.assertEqual(orderedPlayers[2].isequal(playersExpected[2]), True) game.initphaseplayers(3, orderedPlayers) players = game.getplayers() world = game.getcountries() game.initallconquers() usedBattalions = int(len(world) / len(players)) for player in players: usedBattalionsAux = player.getusedbattalions() self.assertEqual(usedBattalions, usedBattalionsAux) player.distributebatallions() usedBeforeBattalions = player.getusedbattalions() self.assertEqual(usedBeforeBattalions, 35)
def test_movebattalions2(self): player = HumanPlayers("Pepe", 38, "orange", []) origCountry = Country("Europa del norte", player) destCountry = Country("Europa del sur", player) player.addconqueredcountry(origCountry) player.addconqueredcountry(destCountry) origCountry.changebattalions(5) numBattalions = 4 expected = True self.assertEqual( expected, player.movebattalions(origCountry, destCountry, numBattalions))
def test_movebattalions2(self): player = HumanPlayers("Pepe", 5, "orange", []) origCountry = Country("Europa del norte", player) destCountry = Country("Europa del sur", player) player.addconqueredcountry(origCountry) player.addconqueredcountry(destCountry) origCountry.changebattalions(5) numBattalions = 5 expected = False #Numero tropas incorrecto self.assertEqual( expected, GameRules.movebattalions(player, origCountry, destCountry, numBattalions))
def test_orderrolls(self): p1 = HumanPlayers("Pepe", initBattalions, "orange", []) p2 = HumanPlayers("Ana", initBattalions, "red", []) p3 = HumanPlayers("Yo", initBattalions, "blue", []) playersExpected = [p1, p2, p3] tidyrolls = [3, 5, 2] game = Game() game.initboard() firstPlayer = game.firstplayer(tidyrolls, playersExpected) orderedPlayers = ArrayPlayers().orderplayers(playersExpected, firstPlayer) self.assertEqual(orderedPlayers[0].isequal(playersExpected[1]), True) self.assertEqual(orderedPlayers[1].isequal(playersExpected[0]), True) self.assertEqual(orderedPlayers[2].isequal(playersExpected[2]), True)
def test_reorderbattalions(self): p1 = HumanPlayers("Pepe", 35, "orange", []) c1 = Country('Europa del norte', p1) c1.changebattalions(3) c2 = Country('América central', p1) c2.changebattalions(7) p1.addconqueredcountry(c1) p2.addconqueredcountry(c1) playersExpected = [p1] game = Game() game.initplayers(playersExpected) game.reorderbattalions(p1, c2, c1, 5) self.assertEqual(8, c1.getbattalions()) self.assertEqual(2, c2.getbattalions())
def test_changebattalions(self): paux = HumanPlayers("Pepe", 0, "orange", []) paux.changebattalions(-1) newbattalions = paux.getbattalions() self.assertEqual(-1, newbattalions) paux.changebattalions(5) newbattalions = paux.getbattalions() self.assertEqual(4, newbattalions)
def test_initallworldconquered(self): p1 = HumanPlayers("Pepe", initBattalions, "orange", []) p2 = HumanPlayers("Ana", initBattalions, "red", []) p3 = HumanPlayers("Yo", initBattalions, "blue", []) playersExpected = [p1, p2, p3] tidyrolls = [3, 5, 2] game = Game() game.initboard() game.initphaseplayers(3, playersExpected) game.initallconquers() world = game.getcountries() players = game.getplayers() game.initallworldconquered() for player in players: usedBeforeBattalions = player.getusedbattalions() self.assertEqual(usedBeforeBattalions, 35)
def test_movebattalions5(self): player = HumanPlayers("Pepe", 38, "orange", []) origCountry = Country("Europa del norte", player) otherCountry = Country("Europa del sur", player) anotherCountry = Country("África del norte", player) destCountry = Country("Brasil", player) player.addconqueredcountry(origCountry) player.addconqueredcountry(otherCountry) player.addconqueredcountry(anotherCountry) player.addconqueredcountry(destCountry) origCountry.changebattalions(5) numBattalions = 1 expected = True #hay camino entre vecinos self.assertEqual( expected, GameRules.movebattalions(player, origCountry, destCountry, numBattalions))
def test_initfirstphasecompletewithoutIA(self): p1 = HumanPlayers("Pepe", initBattalions, "orange", []) p2 = HumanPlayers("Ana", initBattalions, "red", []) p3 = HumanPlayers("Yo", initBattalions, "blue", []) playersExpected = [p1, p2, p3] game = Game() game.initboard() game.initphaseplayers(3, playersExpected) players = game.getplayers() world = game.getcountries() game.initallconquers() usedBattalions = int(len(world) / len(players)) for player in players: usedBattalionsAux = player.getusedbattalions() self.assertEqual(usedBattalions, usedBattalionsAux) player.distributebatallions() usedBeforeBattalions = player.getusedbattalions() self.assertEqual(usedBeforeBattalions, 35)
def test_distributebattalions(self): paux = HumanPlayers("Pepe", 35, "orange", []) country1 = Country("Europa del sur", paux) country2 = Country("Francia", paux) country3 = Country("Italia", paux) country1.changebattalions(7) country2.changebattalions(1) country3.changebattalions(5) paux.addconqueredcountry(country1) paux.addconqueredcountry(country2) paux.addconqueredcountry(country3) paux.distributebatallions() self.assertEqual(paux.getusedbattalions(), 35) conqueredCountries = paux.getconqueredcountries() self.assertEqual(conqueredCountries[0].tostring(), "Europa del sur 15:Pepe 35 orange") self.assertEqual(conqueredCountries[1].tostring(), "Francia 8:Pepe 35 orange") self.assertEqual(conqueredCountries[2].tostring(), "Italia 12:Pepe 35 orange")
def test_usedbattalions(self): paux = HumanPlayers("Pepe", 35, "orange", []) country1 = Country("Europa del sur", paux) country2 = Country("Francia", paux) country3 = Country("Italia", paux) country1.changebattalions(7) country2.changebattalions(1) country3.changebattalions(5) paux.addconqueredcountry(country1) paux.addconqueredcountry(country2) paux.addconqueredcountry(country3) self.assertEqual(paux.getusedbattalions(), 13)
def test_processresult(self): p1 = HumanPlayers("Pepe", initBattalions, "orange", []) p2 = HumanPlayers("Ana", initBattalions, "red", []) c1 = Country('Europa del norte', p1) c1.changebattalions(3) c2 = Country('América central', p2) c2.changebattalions(7) p1.addconqueredcountry(c1) p2.addconqueredcountry(c2) playersExpected = [p1, p2] game = Game() game.initplayers(playersExpected) rollResult = [0, -1] result = [rollResult, c1, c2] game.processresult(result) self.assertEqual(2, c1.getbattalions()) self.assertEqual(6, c2.getbattalions()) rollResult = [0, 0] result = [rollResult, c2, c1] game.processresult(result) self.assertEqual(1, c1.getbattalions()) self.assertEqual(p2.isequal(c1.getconqueror()), True)
def test_movebattalions3(self): player = HumanPlayers("Pepe", 38, "orange", []) origCountry = Country("Europa del norte", player) otherCountry = Country("Europa del sur", player) player.addconqueredcountry(origCountry) player.addconqueredcountry(otherCountry) origCountry.changebattalions(5) player2 = HumanPlayers("Nerea", 38, "red", []) destCountry = Country("Islandia", player2) numBattalions = 1 expected = False #no son vecinos ni hay camino self.assertEqual( expected, GameRules.movebattalions(player, origCountry, destCountry, numBattalions))
def test_movebattalions1(self): player = HumanPlayers("Pepe", 10, "Orange", []) origCountry = Country("Europa del norte", player) origCountry.changebattalions(10) player.addconqueredcountry(origCountry) destCountry = Country("Europa del sur", player) player.addconqueredcountry(destCountry) numBattalions = 5 expected = True #vecinos directos self.assertEqual( expected, GameRules.movebattalions(player, origCountry, destCountry, numBattalions))
def test_whoattack(self): p1 = HumanPlayers("Pepe", 0, "orange", []) print("Si no se introduce 'España' fallará el test") countryToAttack = p1.whoattack() self.assertEqual(countryToAttack, "España")
def test_howmanydeffend(self): p1 = HumanPlayers("Pepe", 0, "orange", []) print("Si no se introduce '1' fallará el test") battalionsToDeffend = p1.howmanydeffend() self.assertEqual(battalionsToDeffend, str(1))
def test_howmanyattack(self): p1 = HumanPlayers("Pepe", 0, "orange", []) print("Si no se introduce '3' fallará el test") battalionsToAttack = p1.howmanyattack() self.assertEqual(battalionsToAttack, str(3))
def test_phasetwocomplete(self): p1 = HumanPlayers("Pepe", initBattalions, "orange", []) p2 = HumanPlayers("Ana", initBattalions, "red", []) p3 = HumanPlayers("Yo", initBattalions, "blue", []) playersExpected = [p1, p2, p3] game = Game() game.initboard() game.initphaseplayers(3, playersExpected) game.initallconquers() game.initallworldconquered() players = game.getplayers() world = game.getcountries() Battalions = 35 for player in players: roundPlayer = game.roundplayerphasetworoll(player) if (roundPlayer == None): continue game.processresult(roundPlayer) BeforeBattalions = player.getbattalions() roll = roundPlayer[0] for r in roll: if (r < 0): Battalions += -1 self.assertEqual(Battalions, BeforeBattalions) countries = player.getconqueredcountries() originIndex = randint(0, len(countries) - 1) origin = countries[originIndex] destinyIndex = randint(0, len(countries) - 1) destiny = countries[originIndex] originBattalions = origin.getbattalions() reorderbattalions = randint(1, originBattalions - 1) originBattalions += -reorderbattalions destinyBattalions = destiny.getbattalions() + reorderbattalions game.reorderbattalions(player, origin, destiny, reorderbattalions) self.assertEqual(origin.getbattalions(), originBattalions) self.assertEqual(destiny.getbattalions(), destinyBattalions) def test_algo_attack(self): #el que va a atacar playerAuxAtak = IAPlayers("Eva", 35, "orange", []) countryA1 = Country("Europa del norte", playerAuxAtak) countryA1.changebattalions(6) playerAuxAtak.addconqueredcountry(countryA1) countryA2 = Country("Europa del sur", playerAuxAtak) countryA2.changebattalions(8) playerAuxAtak.addconqueredcountry(countryA2) countryA3 = Country("África del norte", playerAuxAtak) countryA3.changebattalions(6) playerAuxAtak.addconqueredcountry(countryA3) #necesito tener un jugador al que atacar playerAuxDeff = IAPlayers("Nerea", 35, "blue", []) countryA4 = Country("Egipto", playerAuxDeff) countryA4.changebattalions(3) playerAuxDeff.addconqueredcountry(countryA4) countryA5 = Country("Europa occidental", playerAuxDeff) countryA5.changebattalions(2) playerAuxDeff.addconqueredcountry(countryA5) players = [playerAuxAtak, playerAuxDeff] players = ArrayPlayers().orderplayers(players, playerAuxAtak) expected = True out = playerAuxAtak.algoattack(playerAuxAtak, players) self.assertEqual(out, expected)
def test_removeconqueredcountry(self): paux = HumanPlayers("Pepe", 35, "orange", []) c1 = Country("Europa del sur", paux) c2 = Country("Francia", paux) c3 = Country("Italia", paux) paux.addconqueredcountry(c1) conqueredCountries = paux.getconqueredcountries() paux.addconqueredcountry(c2) conqueredCountries = paux.getconqueredcountries() paux.addconqueredcountry(c3) conqueredCountries = paux.getconqueredcountries() paux.removeconqueredcountry(c2) conqueredCountries = paux.getconqueredcountries() self.assertEqual(c1.isequal(conqueredCountries[0]), True) self.assertEqual(c3.isequal(conqueredCountries[1]), True)
def test_deffend_human(self): playerAux = HumanPlayers("Pepe", 35, "orange", []) countryAux = Country("Europa del norte", playerAux) expected = "Europa del norte" deffended = playerAux.deffend("Europa del norte", 2) self.assertEqual(expected, deffended[0])
def test_zerocardsok(self): player = HumanPlayers("Pepe", 0, "orange", []) expected = True self.assertEqual(expected, GameRules.checkcardsnum(player))
def test_fourcardsok(self): cards = [Cards(), Infantry(), Chivalry(), Artillery()] player = HumanPlayers("Pepe", 0, "orange", cards) expected = True self.assertEqual(expected, GameRules.checkcardsnum(player))
class GameTest(unittest.TestCase): global playersExpected global p1 global p2 global p3 global initBattalions initBattalions = GameRules.getinitialbattalions(3) p1 = HumanPlayers("Pepe", initBattalions, "orange", []) p2 = HumanPlayers("Ana", initBattalions, "red", []) p3 = HumanPlayers("Yo", initBattalions, "blue", []) playersExpected = [p1, p2, p3] #check the number of cards left def test_getjockercardsleft(self): game = Game() expected = 2 self.assertEqual(expected, game.getjokernum()) def test_getinfantrycardsleft(self): game = Game() expected = 14 self.assertEqual(expected, game.getinfantrynum()) def test_getchivalrycardsleft(self): game = Game() expected = 14 self.assertEqual(expected, game.getchivalrynum()) def test_getartillerycardsleft(self): game = Game() expected = 14 self.assertEqual(expected, game.getartillerynum()) def test_initemptygame(self): g1 = Game() self.assertEqual(None, g1.getcountries()) self.assertEqual(None, g1.getplayers()) def test_initboard(self): game = Game() game.initboard() world = game.getcountries() countries = CoreVariables().countries for (country, wCountry) in zip(countries, world): self.assertEqual(country, wCountry.getname()) def test_initplayers(self): game = Game() game.initplayers(playersExpected) players = game.getplayers() for (pE, p) in zip(playersExpected, players): self.assertEqual(True, pE.isequal(p)) def test_initphaseplayerswithIA(self): playersInitExpected = playersExpected game = Game() numPlayersExpected = 5 game.initphaseplayers(5, playersExpected) self.assertEqual(numPlayersExpected, len(game.getplayers())) IA1 = IAPlayers("1", 0, "green", []) IA2 = IAPlayers("2", 0, "white", []) playersInitExpected.append(IA1) playersInitExpected.append(IA2) players = game.getplayers() for (pE, p) in zip(playersInitExpected, players): self.assertEqual(True, pE.isequal(p)) def test_initphaseplayerswithoutIA(self): playersInitExpected = playersExpected game = Game() game.initboard() numPlayersExpected = len(playersExpected) game.initphaseplayers(3, playersExpected) self.assertEqual(numPlayersExpected, len(game.getplayers())) players = game.getplayers() world = game.getcountries() for (pE, p) in zip(playersInitExpected, players): self.assertEqual(True, pE.isequal(p)) def test_initconquer(self): game = Game() game.initboard() game.initphaseplayers(3, playersExpected) players = game.getplayers() world = game.getcountries() for country in world: index = world.index(country) if (index != 0): index = index % len(players) player = players[index] game.initconquers(country, player) self.assertEqual(1, country.getbattalions()) self.assertEqual(player, country.getconqueror()) def test_initfirstphasecompletewithoutIA(self): p1 = HumanPlayers("Pepe", initBattalions, "orange", []) p2 = HumanPlayers("Ana", initBattalions, "red", []) p3 = HumanPlayers("Yo", initBattalions, "blue", []) playersExpected = [p1, p2, p3] game = Game() game.initboard() game.initphaseplayers(3, playersExpected) players = game.getplayers() world = game.getcountries() game.initallconquers() usedBattalions = int(len(world) / len(players)) for player in players: usedBattalionsAux = player.getusedbattalions() self.assertEqual(usedBattalions, usedBattalionsAux) player.distributebatallions() usedBeforeBattalions = player.getusedbattalions() self.assertEqual(usedBeforeBattalions, 35) def test_orderrolls(self): p1 = HumanPlayers("Pepe", initBattalions, "orange", []) p2 = HumanPlayers("Ana", initBattalions, "red", []) p3 = HumanPlayers("Yo", initBattalions, "blue", []) playersExpected = [p1, p2, p3] tidyrolls = [3, 5, 2] game = Game() game.initboard() firstPlayer = game.firstplayer(tidyrolls, playersExpected) orderedPlayers = ArrayPlayers().orderplayers(playersExpected, firstPlayer) self.assertEqual(orderedPlayers[0].isequal(playersExpected[1]), True) self.assertEqual(orderedPlayers[1].isequal(playersExpected[0]), True) self.assertEqual(orderedPlayers[2].isequal(playersExpected[2]), True) def test_allconquers(self): p1 = HumanPlayers("Pepe", initBattalions, "orange", []) p2 = HumanPlayers("Ana", initBattalions, "red", []) p3 = HumanPlayers("Yo", initBattalions, "blue", []) playersExpected = [p1, p2, p3] tidyrolls = [3, 5, 2] game = Game() game.initboard() game.initphaseplayers(3, playersExpected) game.initallconquers() players = game.getplayers() world = game.getcountries() usedBattalions = int(len(world) / len(players)) for player in players: usedBattalionsAux = player.getusedbattalions() self.assertEqual(usedBattalions, usedBattalionsAux) def test_initallworldconquered(self): p1 = HumanPlayers("Pepe", initBattalions, "orange", []) p2 = HumanPlayers("Ana", initBattalions, "red", []) p3 = HumanPlayers("Yo", initBattalions, "blue", []) playersExpected = [p1, p2, p3] tidyrolls = [3, 5, 2] game = Game() game.initboard() game.initphaseplayers(3, playersExpected) game.initallconquers() world = game.getcountries() players = game.getplayers() game.initallworldconquered() for player in players: usedBeforeBattalions = player.getusedbattalions() self.assertEqual(usedBeforeBattalions, 35) def test_processresult(self): p1 = HumanPlayers("Pepe", initBattalions, "orange", []) p2 = HumanPlayers("Ana", initBattalions, "red", []) c1 = Country('Europa del norte', p1) c1.changebattalions(3) c2 = Country('América central', p2) c2.changebattalions(7) p1.addconqueredcountry(c1) p2.addconqueredcountry(c2) playersExpected = [p1, p2] game = Game() game.initplayers(playersExpected) rollResult = [0, -1] result = [rollResult, c1, c2] game.processresult(result) self.assertEqual(2, c1.getbattalions()) self.assertEqual(6, c2.getbattalions()) rollResult = [0, 0] result = [rollResult, c2, c1] game.processresult(result) self.assertEqual(1, c1.getbattalions()) self.assertEqual(p2.isequal(c1.getconqueror()), True) def test_reorderbattalions(self): p1 = HumanPlayers("Pepe", 35, "orange", []) c1 = Country('Europa del norte', p1) c1.changebattalions(3) c2 = Country('América central', p1) c2.changebattalions(7) p1.addconqueredcountry(c1) p2.addconqueredcountry(c1) playersExpected = [p1] game = Game() game.initplayers(playersExpected) game.reorderbattalions(p1, c2, c1, 5) self.assertEqual(8, c1.getbattalions()) self.assertEqual(2, c2.getbattalions()) def test_phaseonecomplete(self): p1 = HumanPlayers("Pepe", initBattalions, "orange", []) p2 = HumanPlayers("Ana", initBattalions, "red", []) p3 = HumanPlayers("Yo", initBattalions, "blue", []) playersExpected = [p1, p2, p3] tidyrolls = [3, 5, 2] game = Game() game.initboard() firstPlayer = game.firstplayer(tidyrolls, playersExpected) orderedPlayers = ArrayPlayers().orderplayers(playersExpected, firstPlayer) self.assertEqual(orderedPlayers[0].isequal(playersExpected[1]), True) self.assertEqual(orderedPlayers[1].isequal(playersExpected[0]), True) self.assertEqual(orderedPlayers[2].isequal(playersExpected[2]), True) game.initphaseplayers(3, orderedPlayers) players = game.getplayers() world = game.getcountries() game.initallconquers() usedBattalions = int(len(world) / len(players)) for player in players: usedBattalionsAux = player.getusedbattalions() self.assertEqual(usedBattalions, usedBattalionsAux) player.distributebatallions() usedBeforeBattalions = player.getusedbattalions() self.assertEqual(usedBeforeBattalions, 35) def test_phasetwocomplete(self): p1 = HumanPlayers("Pepe", initBattalions, "orange", []) p2 = HumanPlayers("Ana", initBattalions, "red", []) p3 = HumanPlayers("Yo", initBattalions, "blue", []) playersExpected = [p1, p2, p3] game = Game() game.initboard() game.initphaseplayers(3, playersExpected) game.initallconquers() game.initallworldconquered() players = game.getplayers() world = game.getcountries() Battalions = 35 for player in players: roundPlayer = game.roundplayerphasetworoll(player) if (roundPlayer == None): continue game.processresult(roundPlayer) BeforeBattalions = player.getbattalions() roll = roundPlayer[0] for r in roll: if (r < 0): Battalions += -1 self.assertEqual(Battalions, BeforeBattalions) countries = player.getconqueredcountries() originIndex = randint(0, len(countries) - 1) origin = countries[originIndex] destinyIndex = randint(0, len(countries) - 1) destiny = countries[originIndex] originBattalions = origin.getbattalions() reorderbattalions = randint(1, originBattalions - 1) originBattalions += -reorderbattalions destinyBattalions = destiny.getbattalions() + reorderbattalions game.reorderbattalions(player, origin, destiny, reorderbattalions) self.assertEqual(origin.getbattalions(), originBattalions) self.assertEqual(destiny.getbattalions(), destinyBattalions) def test_algo_attack(self): #el que va a atacar playerAuxAtak = IAPlayers("Eva", 35, "orange", []) countryA1 = Country("Europa del norte", playerAuxAtak) countryA1.changebattalions(6) playerAuxAtak.addconqueredcountry(countryA1) countryA2 = Country("Europa del sur", playerAuxAtak) countryA2.changebattalions(8) playerAuxAtak.addconqueredcountry(countryA2) countryA3 = Country("África del norte", playerAuxAtak) countryA3.changebattalions(6) playerAuxAtak.addconqueredcountry(countryA3) #necesito tener un jugador al que atacar playerAuxDeff = IAPlayers("Nerea", 35, "blue", []) countryA4 = Country("Egipto", playerAuxDeff) countryA4.changebattalions(3) playerAuxDeff.addconqueredcountry(countryA4) countryA5 = Country("Europa occidental", playerAuxDeff) countryA5.changebattalions(2) playerAuxDeff.addconqueredcountry(countryA5) players = [playerAuxAtak, playerAuxDeff] players = ArrayPlayers().orderplayers(players, playerAuxAtak) expected = True out = playerAuxAtak.algoattack(playerAuxAtak, players) self.assertEqual(out, expected)
class PlayersTest(unittest.TestCase): # expected values global expectedNameEmpty global expectedName global expectedBattalionsEmpty global expectedBattalions global expectedColourIdEmpty global expectedColourId global expectedCardsEmpty global expectedCards global expectedCardsEmptyNum global expectedCardsNum global expectedSubclasses global numPlayers expectedNameEmpty = None expectedName = "Pepe" expectedBattalionsEmpty = 0 expectedBattalions = 7 expectedColourIdEmpty = None expectedColourId = "Orange" expectedCardsEmpty = [] expectedCards = [Cards(), Infantry(), Chivalry(), Artillery()] expectedCardsEmptyNum = 0 expectedCardsNum = 4 expectedSubclasses = ['HumanPlayers', 'IAPlayers'] numPlayers = 3 # Players global player global humanPlayer global iaPlayer global arrayPlayer global p1 global p2 global p3 player = Players(expectedNameEmpty, expectedBattalionsEmpty, expectedColourIdEmpty, expectedCardsEmpty) humanPlayer = HumanPlayers(expectedName, expectedBattalions, expectedColourId, expectedCards) iaPlayer = IAPlayers(expectedName, expectedBattalions, expectedColourId, expectedCards) arrayPlayer = ArrayPlayers() p1 = HumanPlayers("Pepe", 0, "orange", []) p2 = HumanPlayers("Ana", 0, "red", expectedCards) p3 = HumanPlayers("Yo", 0, "blue", []) #testing def test_getname(self): self.assertEqual(expectedNameEmpty, player.getname()) def test_getbattalion(self): self.assertEqual(expectedBattalionsEmpty, player.getbattalions()) def test_getcolourid(self): self.assertEqual(expectedColourIdEmpty, player.getcolourid()) def test_getcards(self): self.assertEqual(expectedCardsEmpty, player.getcards()) def test_getcardsnumber(self): self.assertEqual(expectedCardsEmptyNum, player.getcardsnumber()) def test_subclasses(self): for (cls, scls) in zip(globals()['Players'].__subclasses__(), expectedSubclasses): self.assertEqual(cls.__name__, scls) def test_humanplayername(self): self.assertEqual(expectedName, humanPlayer.getname()) def test_humanplayerbattalions(self): self.assertEqual(expectedBattalions, humanPlayer.getbattalions()) def test_humanplayercolourid(self): self.assertEqual(expectedColourId, humanPlayer.getcolourid()) def test_humanplayercards(self): self.assertEqual(expectedCards, humanPlayer.getcards()) def test_humancardsnumber(self): self.assertEqual(expectedCardsNum, humanPlayer.getcardsnumber()) def test_iaplayername(self): iaName = expectedName + "IA" self.assertEqual(iaName, iaPlayer.getname()) def test_iaplayerbattalions(self): self.assertEqual(expectedBattalions, iaPlayer.getbattalions()) def test_iaplayercolourid(self): self.assertEqual(expectedColourId, iaPlayer.getcolourid()) def test_iaplayercards(self): self.assertEqual(expectedCards, iaPlayer.getcards()) def test_changebattalions(self): paux = HumanPlayers("Pepe", 0, "orange", []) paux.changebattalions(-1) newbattalions = paux.getbattalions() self.assertEqual(-1, newbattalions) paux.changebattalions(5) newbattalions = paux.getbattalions() self.assertEqual(4, newbattalions) def test_compareplayers(self): self.assertEqual(True, humanPlayer.isequal(humanPlayer)) self.assertEqual(False, humanPlayer.isequal(iaPlayer)) def test_removeplayer(self): players = [p1, p2, p3] ArrayPlayers().removeplayer(players, p2) self.assertEqual(True, players[0].isequal(p1)) self.assertEqual(True, players[1].isequal(p3)) def test_arrayplayerorderfisrt(self): players = [p1, p2, p3] nplayers = ArrayPlayers().orderplayers(players, p1) self.assertEqual(True, nplayers[0].isequal(p1)) self.assertEqual(True, nplayers[1].isequal(p2)) self.assertEqual(True, nplayers[2].isequal(p3)) def test_arrayplayerorderlast(self): players = [p1, p2, p3] nplayers = ArrayPlayers().orderplayers(players, p3) self.assertEqual(True, nplayers[0].isequal(p3)) self.assertEqual(True, nplayers[1].isequal(p2)) self.assertEqual(True, nplayers[2].isequal(p1)) def test_arrayplayerordermiddle(self): players = [p1, p2, p3] nplayers = ArrayPlayers().orderplayers(players, p2) self.assertEqual(True, nplayers[0].isequal(p2)) self.assertEqual(True, nplayers[1].isequal(p1)) self.assertEqual(True, nplayers[2].isequal(p3)) def test_turndiceroll(self): roll = p1.diceroll() self.assertIn(roll, range(1, 7)) def test_agroupofrolls(self): rolls = p1.rolls(2) for roll in rolls: self.assertIn(roll, range(1, 7)) def test_addconqueredcountry(self): country = Country("Europa del sur", p1) p1.addconqueredcountry(country) conqueredCountries = p1.getconqueredcountries() for c in conqueredCountries: self.assertEqual(c.getname(), country.getname()) def test_removeconqueredcountry(self): paux = HumanPlayers("Pepe", 35, "orange", []) c1 = Country("Europa del sur", paux) c2 = Country("Francia", paux) c3 = Country("Italia", paux) paux.addconqueredcountry(c1) conqueredCountries = paux.getconqueredcountries() paux.addconqueredcountry(c2) conqueredCountries = paux.getconqueredcountries() paux.addconqueredcountry(c3) conqueredCountries = paux.getconqueredcountries() paux.removeconqueredcountry(c2) conqueredCountries = paux.getconqueredcountries() self.assertEqual(c1.isequal(conqueredCountries[0]), True) self.assertEqual(c3.isequal(conqueredCountries[1]), True) def test_usedbattalions(self): paux = HumanPlayers("Pepe", 35, "orange", []) country1 = Country("Europa del sur", paux) country2 = Country("Francia", paux) country3 = Country("Italia", paux) country1.changebattalions(7) country2.changebattalions(1) country3.changebattalions(5) paux.addconqueredcountry(country1) paux.addconqueredcountry(country2) paux.addconqueredcountry(country3) self.assertEqual(paux.getusedbattalions(), 13) def test_distributebattalions(self): paux = HumanPlayers("Pepe", 35, "orange", []) country1 = Country("Europa del sur", paux) country2 = Country("Francia", paux) country3 = Country("Italia", paux) country1.changebattalions(7) country2.changebattalions(1) country3.changebattalions(5) paux.addconqueredcountry(country1) paux.addconqueredcountry(country2) paux.addconqueredcountry(country3) paux.distributebatallions() self.assertEqual(paux.getusedbattalions(), 35) conqueredCountries = paux.getconqueredcountries() self.assertEqual(conqueredCountries[0].tostring(), "Europa del sur 15:Pepe 35 orange") self.assertEqual(conqueredCountries[1].tostring(), "Francia 8:Pepe 35 orange") self.assertEqual(conqueredCountries[2].tostring(), "Italia 12:Pepe 35 orange") #returns the total num of cards the player has after adding def test_addcards(self): expected = 4 self.assertEqual(expected, p1.addcards(expectedCards)) #returns the total num of cards the player has after deleting def test_delcards(self): cards = [ Infantry(), Artillery(), Infantry(), Cards(), Infantry(), Chivalry() ] playerAux = IAPlayers("Pepe", 35, "orange", cards) expected = 3 self.assertEqual(expected, playerAux.delcards("infantry", 3)) #metodos "propios" de jugadores (humanos e IA) def test_attack_human(self): playerAux = HumanPlayers("Pepe", 35, "orange", []) expectedOrigin = "Europa del sur" expectedDestiny = "Europa del norte" attacked = playerAux.attack("Europa del sur", "Europa del norte", 3) self.assertEqual(expectedOrigin, attacked[0]) self.assertEqual(expectedDestiny, attacked[1]) #no se puede hacer assertEqual de la tirada PORQUE ES ALEATORIA. Siempre va a salir diferente. def test_attack_IA_1(self): playerAux = IAPlayers("Pepe", 35, "orange", []) countryAux = Country("Europa del sur", playerAux) playerAux.addconqueredcountry(countryAux) expectedOrigin = None expectedDestiny = None expectedRoll = None attacked = playerAux.attack("Europa del sur", "Europa del norte") self.assertEqual(expectedOrigin, attacked[0]) self.assertEqual(expectedDestiny, attacked[1]) self.assertEqual(expectedRoll, attacked[2]) #no se puede hacer assertEqual de la tirada PORQUE ES ALEATORIA. Siempre va a salir diferente. def test_attack_IA_2(self): playerAux = IAPlayers("Pepe", 35, "orange", []) countryAux = Country("Europa del sur", playerAux) countryAux.changebattalions(6) playerAux.addconqueredcountry(countryAux) expectedOrigin = "Europa del sur" expectedDestiny = "Europa del norte" attacked = playerAux.attack("Europa del sur", "Europa del norte") self.assertEqual(expectedOrigin, attacked[0]) self.assertEqual(expectedDestiny, attacked[1]) #no se puede hacer assertEqual de la tirada PORQUE ES ALEATORIA. Siempre va a salir diferente. def test_deffend_human(self): playerAux = HumanPlayers("Pepe", 35, "orange", []) countryAux = Country("Europa del norte", playerAux) expected = "Europa del norte" deffended = playerAux.deffend("Europa del norte", 2) self.assertEqual(expected, deffended[0]) #no se puede hacer assertEqual de la tirada PORQUE ES ALEATORIA. Siempre va a salir diferente. def test_deffend_IA(self): playerAux = IAPlayers("Pepe", 35, "orange", []) countryAux = Country("Europa del norte", playerAux) countryAux.changebattalions(6) playerAux.addconqueredcountry(countryAux) deffended = playerAux.deffend("Europa del norte") expectedCountry = "Europa del norte" self.assertEqual(expectedCountry, deffended[0]) #no se puede hacer assertEqual de la tirada PORQUE ES ALEATORIA. Siempre va a salir diferente. #checks if a player can pic an aleatory card def test_humanplayerpicsacard(self): playerAux = IAPlayers("Pepe", 35, "orange", []) expected = 1 self.assertEqual(expected, playerAux.picacard()) def test_Iplayerpicsacard(self): playerAux = IAPlayers("Pepe", 35, "orange", [Infantry()]) expected = 2 self.assertEqual(expected, playerAux.picacard()) def test_changecards_1(self): playerAux = Players("Pepe", 35, "orange", []) card1 = Infantry() card2 = Infantry() card3 = Infantry() card4 = Infantry() card5 = Infantry() cards = [card1, card2, card3, card4, card5] expected = 2 playerAux.addcards(cards) cardsleft = playerAux.changecards() self.assertEqual(expected, cardsleft) def test_changecards_2(self): playerAux = Players("Pepe", 35, "orange", []) card1 = Chivalry() card2 = Chivalry() card3 = Chivalry() card4 = Chivalry() card5 = Chivalry() cards = [card1, card2, card3, card4, card5] expected = 2 playerAux.addcards(cards) cardsleft = playerAux.changecards() self.assertEqual(expected, cardsleft) def test_changecards_3(self): playerAux = Players("Pepe", 35, "orange", []) card1 = Artillery() card2 = Artillery() card3 = Artillery() card4 = Artillery() card5 = Artillery() cards = [card1, card2, card3, card4, card5] expected = 2 playerAux.addcards(cards) cardsleft = playerAux.changecards() self.assertEqual(expected, cardsleft) def test_changecards_4(self): playerAux = Players("Pepe", 35, "orange", []) card1 = Artillery() card2 = Infantry() card3 = Chivalry() cards = [card1, card2, card3] expected = 0 playerAux.addcards(cards) cardsleft = playerAux.changecards() self.assertEqual(expected, cardsleft) def test_changecards_5(self): playerAux = Players("Pepe", 35, "orange", []) card1 = Artillery() card2 = Cards() card3 = Cards() cards = [card1, card2, card3] expected = 0 playerAux.addcards(cards) cardsleft = playerAux.changecards() self.assertEqual(expected, cardsleft) def test_changecards_6(self): playerAux = Players("Pepe", 35, "orange", []) card1 = Infantry() card2 = Cards() card3 = Cards() cards = [card1, card2, card3] expected = 0 playerAux.addcards(cards) cardsleft = playerAux.changecards() self.assertEqual(expected, cardsleft) def test_changecards_7(self): playerAux = Players("Pepe", 35, "orange", []) card1 = Chivalry() card2 = Cards() card3 = Cards() cards = [card1, card2, card3] expected = 0 playerAux.addcards(cards) cardsleft = playerAux.changecards() self.assertEqual(expected, cardsleft) def test_changecards_8(self): playerAux = Players("Pepe", 35, "orange", []) card1 = Chivalry() card2 = Chivalry() card3 = Cards() cards = [card1, card2, card3] expected = 0 playerAux.addcards(cards) cardsleft = playerAux.changecards() self.assertEqual(expected, cardsleft) def test_changecards_9(self): playerAux = Players("Pepe", 35, "orange", []) card1 = Infantry() card2 = Infantry() card3 = Cards() cards = [card1, card2, card3] expected = 0 playerAux.addcards(cards) cardsleft = playerAux.changecards() self.assertEqual(expected, cardsleft) def test_changecards_10(self): playerAux = Players("Pepe", 35, "orange", []) card1 = Artillery() card2 = Artillery() card3 = Cards() cards = [card1, card2, card3] expected = 0 playerAux.addcards(cards) cardsleft = playerAux.changecards() self.assertEqual(expected, cardsleft) #checks if a player can move battalions def test_movebattalions1(self): player = HumanPlayers("Pepe", 38, "orange", []) origCountry = Country("Europa del norte", player) destCountry = Country("Brasil", player) player.addconqueredcountry(origCountry) player.addconqueredcountry(destCountry) origCountry.changebattalions(5) numBattalions = 1 expected = True self.assertEqual( expected, player.movebattalions(origCountry, destCountry, numBattalions)) def test_movebattalions2(self): player = HumanPlayers("Pepe", 38, "orange", []) origCountry = Country("Europa del norte", player) destCountry = Country("Europa del sur", player) player.addconqueredcountry(origCountry) player.addconqueredcountry(destCountry) origCountry.changebattalions(5) numBattalions = 4 expected = True self.assertEqual( expected, player.movebattalions(origCountry, destCountry, numBattalions))