Fix: Building0Test, BuildingCardTest. Getter method tested
This commit is contained in:
@@ -47,8 +47,8 @@ public class Building0 extends BuildingCard {
|
|||||||
numSet=player.getNType(type);
|
numSet=player.getNType(type);
|
||||||
}
|
}
|
||||||
purchased = true;
|
purchased = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BuildingCard clone() {
|
public BuildingCard clone() {
|
||||||
return new Building0(getEra(),getPrice(),getPrestigeValue());
|
return new Building0(getEra(),getPrice(),getPrestigeValue());
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
|
|||||||
this.effectType=EffectType.ON_EVENT;
|
this.effectType=EffectType.ON_EVENT;
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
this.effectType=EffectType.ON_ROUND_END;
|
this.effectType=EffectType.ON_ROUND_END;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
|
|||||||
@@ -1,13 +1,66 @@
|
|||||||
package it.polimi.ingsw.gc14.Model.Cards.Building.Effects;
|
package it.polimi.ingsw.gc14.Model.Cards.Building.Effects;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.*;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.*;
|
||||||
import it.polimi.ingsw.gc14.Model.Player;
|
import it.polimi.ingsw.gc14.Model.Player;
|
||||||
|
import jdk.jshell.spi.SPIResolutionException;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
class Building0Test {
|
class Building0Test {
|
||||||
|
@Test
|
||||||
|
@DisplayName("Testing constructor")
|
||||||
|
void testConstructor() {
|
||||||
|
|
||||||
|
int era = 1;
|
||||||
|
int price = 10;
|
||||||
|
int prestigeValue = 5;
|
||||||
|
|
||||||
|
Building0 b0 = new Building0(era, price, prestigeValue);
|
||||||
|
|
||||||
|
// Gli attributi di BuildingCard era, price e prestigeValue vengono testati in BuildingCardTest
|
||||||
|
|
||||||
|
// Attributi di Building0
|
||||||
|
assertEquals(EffectType.CARD_SET, b0.getEffectType());
|
||||||
|
assertEquals(0, b0.getEffectId());
|
||||||
|
|
||||||
|
// Gli attributi purchased e numSet non possono essere testati singolarmente in quanto non hanno metodi getter
|
||||||
|
// Ne viene testato il corretto funzionamento indirettamente attraverso applyEffect.
|
||||||
|
|
||||||
|
// Lo stesso vale per il metodo initialize
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Testing buy method")
|
||||||
|
void testBuy() {
|
||||||
|
Player p1 = new Player("test1");
|
||||||
|
Player p2 = new Player("test2");
|
||||||
|
Building0 b0 = new Building0(1,1,1);
|
||||||
|
|
||||||
|
p1.addFood(10);
|
||||||
|
p2.addFood(10);
|
||||||
|
|
||||||
|
assertEquals(true, b0.buy(p1));
|
||||||
|
assertEquals(false, b0.buy(p1));
|
||||||
|
assertEquals(false, b0.buy(p2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Testing clone method")
|
||||||
|
void testClone() {
|
||||||
|
int era = 1;
|
||||||
|
int price = 1;
|
||||||
|
int prestigeValue = 1;
|
||||||
|
Building0 b0 = new Building0(era, price,prestigeValue);
|
||||||
|
|
||||||
|
Building0 b1 = (Building0) b0.clone();
|
||||||
|
|
||||||
|
assertEquals(era, b1.getEra());
|
||||||
|
assertEquals(price, b1.getPrice());
|
||||||
|
assertEquals(prestigeValue, b1.getPrestigeValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Set Obtained After Effect")
|
@DisplayName("Set Obtained After Effect")
|
||||||
@@ -87,4 +140,8 @@ class Building0Test {
|
|||||||
b0.buy(p1);
|
b0.buy(p1);
|
||||||
assertFalse(b0.buy(p2));
|
assertFalse(b0.buy(p2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
package it.polimi.ingsw.gc14.Model.Cards;
|
package it.polimi.ingsw.gc14.Model.Cards;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
|
||||||
|
import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.Building0;
|
||||||
|
import it.polimi.ingsw.gc14.Model.Player;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
@@ -31,4 +35,117 @@ class BuildingCardTest {
|
|||||||
new BuildingCard(1, 1,-1);
|
new BuildingCard(1, 1,-1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Testing the first constructor (3 parameters)")
|
||||||
|
void testBuildingCard1() {
|
||||||
|
// Testing correct initialization
|
||||||
|
int era0 = 1;
|
||||||
|
int price0 = 5; // Testing wrong price and prestigeValue
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(1, 0,-1);});
|
||||||
|
int prestigeValue0 = 10;
|
||||||
|
BuildingCard bc0 = new BuildingCard(era0,price0,prestigeValue0);
|
||||||
|
|
||||||
|
assertEquals(era0, bc0.getEra());
|
||||||
|
assertEquals(price0, bc0.getPrice());
|
||||||
|
assertEquals(prestigeValue0, bc0.getPrestigeValue());
|
||||||
|
|
||||||
|
// Testing edge case for prestigeValue and price
|
||||||
|
assertDoesNotThrow(() -> {new BuildingCard(1, 1,0);});
|
||||||
|
|
||||||
|
// Testing wrong price
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(1, 0,1);});
|
||||||
|
|
||||||
|
// Testing wrong prestigeValue
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(1, 1,-1);});
|
||||||
|
|
||||||
|
// Testing wrong price and prestigeValue
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(1, 0,-1);});
|
||||||
|
|
||||||
|
// The attribute era is tested in PlayableCardTest
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Testing the second constructor (4 parameters)")
|
||||||
|
void testBuildingCard2() {}{
|
||||||
|
// Testing right parameters
|
||||||
|
BuildingCard bc2 = new BuildingCard(2,1,1,1);
|
||||||
|
BuildingCard bc3 = new BuildingCard(3,1,1,1);
|
||||||
|
BuildingCard bc5 = new BuildingCard(5,1,1,1);
|
||||||
|
BuildingCard bc6 = new BuildingCard(6,1,1,1);
|
||||||
|
BuildingCard bc7 = new BuildingCard(7,1,1,1);
|
||||||
|
BuildingCard bc9 = new BuildingCard(9,1,1,1);
|
||||||
|
BuildingCard bc12 = new BuildingCard(12,1,1,1);
|
||||||
|
|
||||||
|
assertEquals(EffectType.ON_EVENT, bc2.getEffectType());
|
||||||
|
assertEquals(EffectType.ON_END_TURN, bc3.getEffectType());
|
||||||
|
assertEquals(EffectType.ON_EVENT, bc5.getEffectType());
|
||||||
|
assertEquals(EffectType.ON_EVENT, bc6.getEffectType());
|
||||||
|
assertEquals(EffectType.ON_EVENT, bc7.getEffectType());
|
||||||
|
assertEquals(EffectType.ON_EVENT, bc9.getEffectType());
|
||||||
|
assertEquals(EffectType.ON_ROUND_END, bc12.getEffectType());
|
||||||
|
|
||||||
|
// Testing wrong parameters
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(0,1,1,1);});
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(1,1,1,1);});
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(4,1,1,1);});
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(8,1,1,1);});
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(10,1,1,1);});
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(11,1,1,1);});
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(13,1,1,1);});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Testing the getters for price, prestigeValue, effectID, effectType")
|
||||||
|
void testGetters() {
|
||||||
|
int effectID = 2;
|
||||||
|
EffectType effectType = EffectType.ON_EVENT;
|
||||||
|
int era = 1;
|
||||||
|
int price = 1;
|
||||||
|
int prestigeValue = 1;
|
||||||
|
|
||||||
|
BuildingCard bc0 = new BuildingCard(effectID,era,price,prestigeValue);
|
||||||
|
|
||||||
|
assertEquals(effectID, bc0.getEffectId());
|
||||||
|
assertEquals(effectType, bc0.getEffectType());
|
||||||
|
assertEquals(era, bc0.getEra());
|
||||||
|
assertEquals(price, bc0.getPrice());
|
||||||
|
assertEquals(prestigeValue, bc0.getPrestigeValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Testing the clone method")
|
||||||
|
void testClone() {
|
||||||
|
int effectID = 2;
|
||||||
|
EffectType effectType = EffectType.ON_EVENT;
|
||||||
|
int era = 1;
|
||||||
|
int price = 1;
|
||||||
|
int prestigeValue = 1;
|
||||||
|
|
||||||
|
BuildingCard bc0 = new BuildingCard(effectID, era, price, prestigeValue);
|
||||||
|
BuildingCard bc1 = bc0.clone();
|
||||||
|
|
||||||
|
assertEquals(effectID, bc1.getEffectId());
|
||||||
|
assertEquals(effectType, bc1.getEffectType());
|
||||||
|
assertEquals(era, bc1.getEra());
|
||||||
|
assertEquals(price, bc1.getPrice());
|
||||||
|
assertEquals(prestigeValue, bc1.getPrestigeValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Testing the buy method")
|
||||||
|
void testBuy() {
|
||||||
|
Player p1 = new Player("test1");
|
||||||
|
Player p2 = new Player("test2");
|
||||||
|
p1.addFood(10);
|
||||||
|
p2.addFood(10);
|
||||||
|
|
||||||
|
BuildingCard bc0 = new BuildingCard(2, 1,1,1);
|
||||||
|
|
||||||
|
assertEquals(true, bc0.buy(p1));
|
||||||
|
assertEquals(false, bc0.buy(p1));
|
||||||
|
assertEquals(false, bc0.buy(p2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user