Ejemplo n.º 1
0
 def test_changeconqueror(self):
     Aux = Players("Luis", 0, "red", [])
     Aux2 = Players("Pepe", 0, "red", [])
     countryAux = Country("Islandia", Aux)
     countryAux.changeconqueror(Aux2)
     expected = "Pepe"
     self.assertEqual(expected, countryAux.conqueror.getname())
Ejemplo n.º 2
0
 def test_theyallhaveneighbourhood(self):
     expected = True
     absolutes = CoreVariables()
     lenght = len(absolutes.countries)
     for i in range(lenght):
         countryAux = Country(absolutes.countries[i], None)
         self.assertEqual(expected, countryAux.ithasneighbourhood())
Ejemplo n.º 3
0
 def test_canredattackred(self):
     pAux1 = Players("Pepe", 0, "orange", [])
     countryAtt = Country("Islandia", pAux1)
     countryDef = Country("Groenlandia", pAux1)
     expected = False
     self.assertEqual(
         expected,
         GameRules.countriesokforthebattle(countryAtt, countryDef))
Ejemplo n.º 4
0
 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])
Ejemplo n.º 5
0
 def test_canislandattackbrazil(self):
     pAux1 = Players("Pepe", 0, "orange", [])
     pAux2 = Players("Nerea", 0, "blue", [])
     countryAtt = Country("Islandia", pAux1)
     countryDef = Country("Brasil", pAux2)
     expected = False
     self.assertEqual(
         expected,
         GameRules.countriesokforthebattle(countryAtt, countryDef))
Ejemplo n.º 6
0
    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])
Ejemplo n.º 7
0
 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))
Ejemplo n.º 8
0
 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))
Ejemplo n.º 9
0
 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))
Ejemplo n.º 10
0
 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())
Ejemplo n.º 11
0
 def test_existepais(self):
     expectedName = None
     expectedBattalions = 0
     expectedNeighbours = []
     paisAux = Country(None, None)
     self.assertEqual(expectedName, paisAux.name)
     self.assertEqual(expectedBattalions, paisAux.battalions)
     neighbourAux = Neighbours(None)
     self.assertEqual(expectedNeighbours, neighbourAux.getarray())
Ejemplo n.º 12
0
 def test_filledcountry (self):
     #estan todas las cosas de un pais (pais tonto)
     expectedName = None
     expectedBattalions = 0
     expectedNeighbours = []
     expectedConqueror = None
     paisAux = Country(None, None)
     self.assertEqual(expectedName, paisAux.name)
     self.assertEqual(expectedBattalions, paisAux.battalions)
     self.assertEqual(expectedConqueror, paisAux.conqueror)
     neighbourAux = Neighbours(None)
     self.assertEqual(expectedNeighbours, neighbourAux.getarray())
Ejemplo n.º 13
0
    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])
Ejemplo n.º 14
0
 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)
Ejemplo n.º 15
0
 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))
Ejemplo n.º 16
0
 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))
Ejemplo n.º 17
0
 def battalionstoattackok(self, attackingCountry, numBattalions):
     totalBattalions = Country.getbattalions(attackingCountry)
     if numBattalions > 0 and numBattalions <= 3 and (totalBattalions -
                                                      numBattalions) >= 1:
         return True
     return False
Ejemplo n.º 18
0
 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)
Ejemplo n.º 19
0
 def test_ithasneigh (self):
     absolutes = CoreVariables()
     playerAux = Players("Pepe",35,"orange",[])
     countryAux = Country("Islandia", playerAux)
     expected = absolutes.neighboursIsl
     self.assertEqual(expected, countryAux.neighbours.getarray())
Ejemplo n.º 20
0
 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)
Ejemplo n.º 21
0
 def test_are2battalionstoattackok(self):
     pAux = Players("Pepe", 0, "orange", [])
     country = Country("Islandia", pAux)
     country.changebattalions(25)  #25 battalions
     expected = True
     self.assertEqual(expected, GameRules.battalionstoattackok(country, 2))
Ejemplo n.º 22
0
 def test_namevalid (self):
     expected = True
     paisAux = Country('Europa del norte', None)
     self.assertEqual(expected, paisAux.nameok())
Ejemplo n.º 23
0
 def test_namecountry (self):
     expected = None
     self.assertEqual(expected, Country(None, None).name)
Ejemplo n.º 24
0
 def test_battalion (self):
     expected = 0
     self.assertEqual(expected, Country(None, None).getbattalions())
Ejemplo n.º 25
0
 def test_getplayer (self):
     expectedConqueror = None
     self.assertEqual(expectedConqueror, Country(None, None).getconqueror())
Ejemplo n.º 26
0
 def test_are0battalionstodefendok(self):
     pAux = Players("Pepe", 0, "orange", [])
     country = Country("Groenlandia", pAux)
     country.changebattalions(1)  #1 battalion
     expected = False
     self.assertEqual(expected, GameRules.battalionstodefendok(country, 0))
Ejemplo n.º 27
0
 def test_getbattalions (self):
     expectedBattalions = 0
     self.assertEqual(expectedBattalions, Country(None, None).getbattalions())
Ejemplo n.º 28
0
 def battalionstodefendok(self, defendingCountry, numBattalions):
     totalBattalions = Country.getbattalions(defendingCountry)
     if numBattalions > 0 and numBattalions <= 2 and (totalBattalions -
                                                      numBattalions) >= 0:
         return True
     return False
Ejemplo n.º 29
0
 def countriesokforthebattle(self, countryAtt, countryDef):
     if (countryAtt.conqueror != countryDef.conqueror):
         return Country.areneighbours(countryAtt, countryDef)
     return False
Ejemplo n.º 30
0
 def test_is1battaliontodefendok(self):
     pAux = Players("Pepe", 0, "orange", [])
     country = Country("Groenlandia", pAux)
     country.changebattalions(4)  #4 battalions
     expected = True
     self.assertEqual(expected, GameRules.battalionstodefendok(country, 1))