Add: Building tests for image id, clone and effect behavior
This commit is contained in:
@@ -41,23 +41,26 @@ class Building0Test {
|
||||
p1.addFood(10);
|
||||
p2.addFood(10);
|
||||
|
||||
assertEquals(true, b0.buy(p1));
|
||||
assertEquals(false, b0.buy(p1));
|
||||
assertEquals(false, b0.buy(p2));
|
||||
assertTrue(b0.buy(p1));
|
||||
assertFalse(b0.buy(p1));
|
||||
assertFalse(b0.buy(p2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Testing clone method")
|
||||
void testClone() {
|
||||
String idImage = "building0.png";
|
||||
int effectID = 0;
|
||||
EffectType effectType = EffectType.CARD_SET;
|
||||
int era = 1;
|
||||
int price = 1;
|
||||
int prestigeValue = 1;
|
||||
Building0 b0 = new Building0(era, price,prestigeValue);
|
||||
|
||||
Building0 b0 = new Building0(idImage, era, price, prestigeValue);
|
||||
|
||||
Building0 b1 = (Building0) b0.clone();
|
||||
|
||||
assertEquals(idImage, b1.getIdIMG());
|
||||
assertEquals(effectID, b1.getEffectId());
|
||||
assertEquals(effectType, b1.getEffectType());
|
||||
assertEquals(era, b1.getEra());
|
||||
@@ -140,7 +143,74 @@ class Building0Test {
|
||||
Player p2 = new Player("test2");
|
||||
p1.addFood(b0.getPrice());
|
||||
p2.addFood(b0.getPrice());
|
||||
b0.buy(p1);
|
||||
assertTrue(b0.buy(p1));
|
||||
assertFalse(b0.buy(p2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Testing constructor with idImage")
|
||||
void testConstructorWithIdImage() {
|
||||
String idImage = "building0.png";
|
||||
int era = 1;
|
||||
int price = 10;
|
||||
int prestigeValue = 5;
|
||||
|
||||
Building0 b0 = new Building0(idImage, era, price, prestigeValue);
|
||||
|
||||
assertEquals(idImage, b0.getIdIMG());
|
||||
assertEquals(era, b0.getEra());
|
||||
assertEquals(price, b0.getPrice());
|
||||
assertEquals(prestigeValue, b0.getPrestigeValue());
|
||||
assertEquals(EffectType.CARD_SET, b0.getEffectType());
|
||||
assertEquals(0, b0.getEffectId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Effect should not reward the same set twice")
|
||||
void applyEffectShouldNotRewardSameSetTwice() {
|
||||
int era = 1;
|
||||
Building0 b0 = new Building0(1, 1, 1);
|
||||
Player p = new Player("test");
|
||||
|
||||
p.addFood(b0.getPrice());
|
||||
assertTrue(b0.buy(p));
|
||||
|
||||
p.artists.add(new Artist(era));
|
||||
p.builders.add(new Builder(era, 0, 0));
|
||||
p.gatherers.add(new Gatherer(era));
|
||||
p.hunters.add(new Hunter(era, true));
|
||||
p.inventors.add(new Inventor(era, 1));
|
||||
p.shamans.add(new Shaman(era, 1));
|
||||
|
||||
b0.applyEffect(p);
|
||||
assertEquals(5, p.getFoodValue());
|
||||
|
||||
b0.applyEffect(p);
|
||||
assertEquals(5, p.getFoodValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Effect should reward multiple new sets")
|
||||
void applyEffectShouldRewardMultipleNewSets() {
|
||||
int era = 1;
|
||||
Building0 b0 = new Building0(1, 1, 1);
|
||||
Player p = new Player("test");
|
||||
|
||||
p.addFood(b0.getPrice());
|
||||
assertTrue(b0.buy(p));
|
||||
|
||||
for (int k = 0; k < 2; k++) {
|
||||
p.artists.add(new Artist(era));
|
||||
p.builders.add(new Builder(era, 0, 0));
|
||||
p.gatherers.add(new Gatherer(era));
|
||||
p.hunters.add(new Hunter(era, true));
|
||||
p.inventors.add(new Inventor(era, 1));
|
||||
p.shamans.add(new Shaman(era, 1));
|
||||
}
|
||||
|
||||
b0.applyEffect(p);
|
||||
|
||||
assertEquals(10, p.getFoodValue());
|
||||
}
|
||||
|
||||
}
|
||||
+66
-30
@@ -6,8 +6,6 @@ import it.polimi.ingsw.gc14.Model.Player;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class Building10Test {
|
||||
@@ -28,15 +26,18 @@ class Building10Test {
|
||||
@Test
|
||||
@DisplayName("Testing clone method")
|
||||
void testClone() {
|
||||
String idIMG = "building10.png";
|
||||
int effectID = 10;
|
||||
EffectType effectType = EffectType.FINAL;
|
||||
int era = 1;
|
||||
int price = 1;
|
||||
int prestigeValue = 1;
|
||||
Building10 b0 = new Building10(era, price, prestigeValue);
|
||||
|
||||
Building10 b0 = new Building10(idIMG, era, price, prestigeValue);
|
||||
|
||||
Building10 b1 = (Building10) b0.clone();
|
||||
|
||||
assertEquals(idIMG, b1.getIdIMG());
|
||||
assertEquals(effectID, b1.getEffectId());
|
||||
assertEquals(effectType, b1.getEffectType());
|
||||
assertEquals(era, b1.getEra());
|
||||
@@ -45,40 +46,29 @@ class Building10Test {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Apply effect should add 6 prestige points for each complete character set")
|
||||
void applyEffect() {
|
||||
Building10 b10 = new Building10(1, 1, 1);
|
||||
Player p = new Player("test");
|
||||
|
||||
p.addFood(b10.getPrice());
|
||||
b10.buy(p);
|
||||
assertTrue(b10.buy(p));
|
||||
|
||||
int Era = 1;
|
||||
int Nset = 2;
|
||||
int era = 1;
|
||||
int nSet = 2;
|
||||
|
||||
ArrayList<Artist> Artists = new ArrayList<>();
|
||||
ArrayList<Builder> Builders = new ArrayList<>();
|
||||
ArrayList<Gatherer> Gatherers = new ArrayList<>();
|
||||
ArrayList<Hunter> Hunters = new ArrayList<>();
|
||||
ArrayList<Inventor> Inventors = new ArrayList<>();
|
||||
ArrayList<Shaman> Shamans = new ArrayList<>();
|
||||
|
||||
for(int i = 0; i < Nset; i++) {
|
||||
Artists.add(new Artist(Era));
|
||||
Builders.add(new Builder(Era, 0, 0));
|
||||
Gatherers.add(new Gatherer(Era));
|
||||
Hunters.add(new Hunter(Era, true));
|
||||
Inventors.add(new Inventor(Era, 1));
|
||||
Shamans.add(new Shaman(Era, 1));
|
||||
for (int i = 0; i < nSet; i++) {
|
||||
p.artists.add(new Artist(era));
|
||||
p.builders.add(new Builder(era, 0, 0));
|
||||
p.gatherers.add(new Gatherer(era));
|
||||
p.hunters.add(new Hunter(era, true));
|
||||
p.inventors.add(new Inventor(era, 1));
|
||||
p.shamans.add(new Shaman(era, 1));
|
||||
}
|
||||
|
||||
p.artists.addAll(Artists);
|
||||
p.builders.addAll(Builders);
|
||||
p.gatherers.addAll(Gatherers);
|
||||
p.hunters.addAll(Hunters);
|
||||
p.inventors.addAll(Inventors);
|
||||
p.shamans.addAll(Shamans);
|
||||
|
||||
b10.applyEffect(p);
|
||||
assertEquals(Nset * 6, p.getPrestigeValue());
|
||||
|
||||
assertEquals(nSet * 6, p.getPrestigeValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,11 +81,57 @@ class Building10Test {
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyEffectMultiplePlayerException() {
|
||||
@DisplayName("Buying same card by two different players")
|
||||
void buyShouldRejectSameCardForDifferentPlayers() {
|
||||
Building10 b10 = new Building10(1, 1, 1);
|
||||
Player p1 = new Player("test1");
|
||||
Player p2 = new Player("test2");
|
||||
b10.buy(p1);
|
||||
|
||||
p1.addFood(b10.getPrice());
|
||||
p2.addFood(b10.getPrice());
|
||||
|
||||
assertTrue(b10.buy(p1));
|
||||
assertFalse(b10.buy(p2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Testing constructor with idIMG")
|
||||
void testConstructorWithIdIMG() {
|
||||
String idIMG = "building10.png";
|
||||
int era = 1;
|
||||
int price = 10;
|
||||
int prestigeValue = 5;
|
||||
|
||||
Building10 b10 = new Building10(idIMG, era, price, prestigeValue);
|
||||
|
||||
assertEquals(idIMG, b10.getIdIMG());
|
||||
assertEquals(era, b10.getEra());
|
||||
assertEquals(price, b10.getPrice());
|
||||
assertEquals(prestigeValue, b10.getPrestigeValue());
|
||||
assertEquals(EffectType.FINAL, b10.getEffectType());
|
||||
assertEquals(10, b10.getEffectId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Apply effect should not add prestige without complete character sets")
|
||||
void applyEffectShouldNotAddPrestigeWithoutCompleteSets() {
|
||||
Building10 b10 = new Building10(1, 1, 1);
|
||||
Player p = new Player("test");
|
||||
|
||||
p.addFood(b10.getPrice());
|
||||
assertTrue(b10.buy(p));
|
||||
|
||||
int era = 1;
|
||||
|
||||
p.artists.add(new Artist(era));
|
||||
p.builders.add(new Builder(era, 0, 0));
|
||||
p.gatherers.add(new Gatherer(era));
|
||||
p.hunters.add(new Hunter(era, true));
|
||||
p.inventors.add(new Inventor(era, 1));
|
||||
// Manca lo Shaman, quindi non c'è un set completo.
|
||||
|
||||
b10.applyEffect(p);
|
||||
|
||||
assertEquals(0, p.getPrestigeValue());
|
||||
}
|
||||
}
|
||||
+62
-12
@@ -24,6 +24,9 @@ class Building11Test {
|
||||
|
||||
Building11 b0 = new Building11(era, price, prestigeValue, ct, pm);
|
||||
|
||||
assertEquals(era, b0.getEra());
|
||||
assertEquals(price, b0.getPrice());
|
||||
assertEquals(prestigeValue, b0.getPrestigeValue());
|
||||
assertEquals(EffectType.FINAL, b0.getEffectType());
|
||||
assertEquals(11, b0.getEffectId());
|
||||
assertEquals(ct, b0.getIcon());
|
||||
@@ -33,6 +36,7 @@ class Building11Test {
|
||||
@Test
|
||||
@DisplayName("Testing clone method")
|
||||
void testClone() {
|
||||
String idIMG = "building11.png";
|
||||
int effectID = 11;
|
||||
EffectType effectType = EffectType.FINAL;
|
||||
int era = 1;
|
||||
@@ -40,51 +44,59 @@ class Building11Test {
|
||||
int prestigeValue = 1;
|
||||
CharacterType ct = CharacterType.ARTIST;
|
||||
int pm = 5;
|
||||
Building11 b0 = new Building11(era, price, prestigeValue, ct, pm);
|
||||
|
||||
Building11 b0 = new Building11(idIMG, era, price, prestigeValue, ct, pm);
|
||||
|
||||
Building11 b1 = (Building11) b0.clone();
|
||||
|
||||
assertEquals(idIMG, b1.getIdIMG());
|
||||
assertEquals(effectID, b1.getEffectId());
|
||||
assertEquals(effectType, b1.getEffectType());
|
||||
assertEquals(era, b1.getEra());
|
||||
assertEquals(price, b1.getPrice());
|
||||
assertEquals(prestigeValue, b1.getPrestigeValue());
|
||||
assertEquals(ct, b0.getIcon());
|
||||
assertEquals(pm, b0.getPrestigeMul());
|
||||
assertEquals(ct, b1.getIcon());
|
||||
assertEquals(pm, b1.getPrestigeMul());
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyEffectBuyWithoutFood() {
|
||||
|
||||
@DisplayName("Apply effect should throw if card was not bought due to missing food")
|
||||
void applyEffectShouldThrowIfBuyFailed() {
|
||||
Player p1 = new Player("Xiaomi");
|
||||
Building11 b1 = new Building11(2, 10, 1, ARTIST, -3);
|
||||
Artist a1 = new Artist(2);
|
||||
b1.buy(p1);
|
||||
|
||||
assertFalse(b1.buy(p1));
|
||||
|
||||
p1.artists.add(a1);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
b1.applyEffect(p1);
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> b1.applyEffect(p1));
|
||||
|
||||
p1.addFood(b1.getPrice());
|
||||
b1.buy(p1);
|
||||
assertTrue(b1.buy(p1));
|
||||
|
||||
b1.applyEffect(p1);
|
||||
|
||||
assertEquals(-3, p1.getPrestigeValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Apply effect should add prestige for two cards of the required type")
|
||||
void applyEffectWithTwoCards() {
|
||||
Player p2 = new Player("Giacomo");
|
||||
Building11 b2 = new Building11(2, 10, 1, ARTIST, 4);
|
||||
|
||||
Artist a2 = new Artist(2);
|
||||
Artist a3 = new Artist(2);
|
||||
|
||||
p2.addFood(b2.getPrice());
|
||||
b2.buy(p2);
|
||||
assertTrue(b2.buy(p2));
|
||||
|
||||
p2.artists.add(a2);
|
||||
p2.artists.add(a3);
|
||||
|
||||
|
||||
b2.applyEffect(p2);
|
||||
|
||||
assertEquals(8, p2.getPrestigeValue());
|
||||
}
|
||||
|
||||
@@ -142,4 +154,42 @@ class Building11Test {
|
||||
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
||||
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Testing constructor with idIMG")
|
||||
void testConstructorWithIdIMG() {
|
||||
String idIMG = "building11.png";
|
||||
int era = 1;
|
||||
int price = 10;
|
||||
int prestigeValue = 5;
|
||||
CharacterType ct = CharacterType.ARTIST;
|
||||
int pm = 5;
|
||||
|
||||
Building11 b11 = new Building11(idIMG, era, price, prestigeValue, ct, pm);
|
||||
|
||||
assertEquals(idIMG, b11.getIdIMG());
|
||||
assertEquals(era, b11.getEra());
|
||||
assertEquals(price, b11.getPrice());
|
||||
assertEquals(prestigeValue, b11.getPrestigeValue());
|
||||
assertEquals(EffectType.FINAL, b11.getEffectType());
|
||||
assertEquals(11, b11.getEffectId());
|
||||
assertEquals(ct, b11.getIcon());
|
||||
assertEquals(pm, b11.getPrestigeMul());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Apply effect should add zero prestige if player has no cards of the required type")
|
||||
void applyEffectShouldAddZeroPrestigeWithoutRequiredCards() {
|
||||
Player p = new Player("test");
|
||||
Building11 b11 = new Building11(1, 1, 1, ARTIST, 4);
|
||||
|
||||
p.addFood(b11.getPrice());
|
||||
assertTrue(b11.buy(p));
|
||||
|
||||
b11.applyEffect(p);
|
||||
|
||||
assertEquals(0, p.getPrestigeValue());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+41
-7
@@ -18,6 +18,9 @@ class Building13Test {
|
||||
|
||||
Building13 b0 = new Building13(era, price, prestigeValue);
|
||||
|
||||
assertEquals(era, b0.getEra());
|
||||
assertEquals(price, b0.getPrice());
|
||||
assertEquals(prestigeValue, b0.getPrestigeValue());
|
||||
assertEquals(EffectType.FINAL, b0.getEffectType());
|
||||
assertEquals(13, b0.getEffectId());
|
||||
}
|
||||
@@ -25,15 +28,18 @@ class Building13Test {
|
||||
@Test
|
||||
@DisplayName("Testing clone method")
|
||||
void testClone() {
|
||||
String idIMG = "building13.png";
|
||||
int effectID = 13;
|
||||
EffectType effectType = EffectType.FINAL;
|
||||
int era = 1;
|
||||
int price = 1;
|
||||
int prestigeValue = 1;
|
||||
Building13 b0 = new Building13(era, price,prestigeValue);
|
||||
|
||||
Building13 b0 = new Building13(idIMG, era, price, prestigeValue);
|
||||
|
||||
Building13 b1 = (Building13) b0.clone();
|
||||
|
||||
assertEquals(idIMG, b1.getIdIMG());
|
||||
assertEquals(effectID, b1.getEffectId());
|
||||
assertEquals(effectType, b1.getEffectType());
|
||||
assertEquals(era, b1.getEra());
|
||||
@@ -42,14 +48,18 @@ class Building13Test {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Apply effect should add 25 prestige points")
|
||||
void applyEffect() {
|
||||
Player p1 = new Player("gigi");
|
||||
p1.addPrestige(10);
|
||||
Building13 b1 = new Building13(1, 10, 1);
|
||||
p1.addFood(b1.getPrice());
|
||||
b1.buy(p1);
|
||||
|
||||
b1.applyEffect(p1);
|
||||
Building13 b13 = new Building13(1, 10, 1);
|
||||
|
||||
p1.addFood(b13.getPrice());
|
||||
assertTrue(b13.buy(p1));
|
||||
|
||||
b13.applyEffect(p1);
|
||||
|
||||
assertEquals(35, p1.getPrestigeValue());
|
||||
}
|
||||
|
||||
@@ -61,12 +71,36 @@ class Building13Test {
|
||||
b13.applyEffect(p);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyEffectMultiplePlayerException() {
|
||||
@DisplayName("Buying same card by two different players")
|
||||
void buyShouldRejectSameCardForDifferentPlayers() {
|
||||
Building13 b13 = new Building13(1, 10, 1);
|
||||
Player p1 = new Player("test1");
|
||||
Player p2 = new Player("test2");
|
||||
b13.buy(p1);
|
||||
|
||||
p1.addFood(b13.getPrice());
|
||||
p2.addFood(b13.getPrice());
|
||||
|
||||
assertTrue(b13.buy(p1));
|
||||
assertFalse(b13.buy(p2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Testing constructor with idIMG")
|
||||
void testConstructorWithIdIMG() {
|
||||
String idIMG = "building13.png";
|
||||
int era = 1;
|
||||
int price = 10;
|
||||
int prestigeValue = 5;
|
||||
|
||||
Building13 b13 = new Building13(idIMG, era, price, prestigeValue);
|
||||
|
||||
assertEquals(idIMG, b13.getIdIMG());
|
||||
assertEquals(era, b13.getEra());
|
||||
assertEquals(price, b13.getPrice());
|
||||
assertEquals(prestigeValue, b13.getPrestigeValue());
|
||||
assertEquals(EffectType.FINAL, b13.getEffectType());
|
||||
assertEquals(13, b13.getEffectId());
|
||||
}
|
||||
}
|
||||
+39
-10
@@ -5,6 +5,7 @@ import it.polimi.ingsw.gc14.Model.Player;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -52,19 +53,28 @@ class Building1Test {
|
||||
|
||||
@Test
|
||||
@DisplayName("Clone")
|
||||
void Clone(){
|
||||
int Era = 1;
|
||||
int Price = 2;
|
||||
int Prestige = 3;
|
||||
void testClone() {
|
||||
String idIMG = "building1.png";
|
||||
int era = 1;
|
||||
int price = 2;
|
||||
int prestigeValue = 3;
|
||||
CharacterType ct = CharacterType.INVENTOR;
|
||||
Building1 b0 = new Building1(Era,Price,Prestige, ct);
|
||||
|
||||
Building1 b0 = new Building1(idIMG, era, price, prestigeValue, ct);
|
||||
|
||||
BuildingCard bClone = b0.clone();
|
||||
|
||||
assertEquals(Era,b0.getEra());
|
||||
assertEquals(Price,b0.getPrice());
|
||||
assertEquals(Prestige, bClone.getPrestigeValue());
|
||||
assertEquals(ct, b0.getIcon());
|
||||
assertTrue(bClone instanceof Building1);
|
||||
|
||||
Building1 clonedBuilding = (Building1) bClone;
|
||||
|
||||
assertEquals(idIMG, clonedBuilding.getIdIMG());
|
||||
assertEquals(era, clonedBuilding.getEra());
|
||||
assertEquals(price, clonedBuilding.getPrice());
|
||||
assertEquals(prestigeValue, clonedBuilding.getPrestigeValue());
|
||||
assertEquals(ct, clonedBuilding.getIcon());
|
||||
assertEquals(EffectType.ON_EVENT, clonedBuilding.getEffectType());
|
||||
assertEquals(1, clonedBuilding.getEffectId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,7 +85,6 @@ class Building1Test {
|
||||
int price = 1;
|
||||
int prestigeValue = 3;
|
||||
CharacterType ct = CharacterType.ARTIST;
|
||||
int pm = 5;
|
||||
|
||||
Building1 b1 = new Building1(era, price, prestigeValue, ct);
|
||||
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString());
|
||||
@@ -100,4 +109,24 @@ class Building1Test {
|
||||
b1 = new Building1(era, price, prestigeValue, ct);
|
||||
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Testing constructor with idIMG")
|
||||
void testConstructorWithIdIMG() {
|
||||
String idIMG = "building1.png";
|
||||
int era = 1;
|
||||
int price = 2;
|
||||
int prestigeValue = 3;
|
||||
CharacterType icon = CharacterType.INVENTOR;
|
||||
|
||||
Building1 b1 = new Building1(idIMG, era, price, prestigeValue, icon);
|
||||
|
||||
assertEquals(idIMG, b1.getIdIMG());
|
||||
assertEquals(era, b1.getEra());
|
||||
assertEquals(price, b1.getPrice());
|
||||
assertEquals(prestigeValue, b1.getPrestigeValue());
|
||||
assertEquals(icon, b1.getIcon());
|
||||
assertEquals(EffectType.ON_EVENT, b1.getEffectType());
|
||||
assertEquals(1, b1.getEffectId());
|
||||
}
|
||||
}
|
||||
@@ -43,15 +43,18 @@ class Building4Test {
|
||||
@Test
|
||||
@DisplayName("Testing clone method")
|
||||
void testClone() {
|
||||
String idIMG = "building4.png";
|
||||
int effectID = 4;
|
||||
EffectType effectType = EffectType.INVENTOR_PAIR;
|
||||
int era = 1;
|
||||
int price = 1;
|
||||
int prestigeValue = 1;
|
||||
Building4 b0 = new Building4(era, price,prestigeValue);
|
||||
|
||||
Building4 b0 = new Building4(idIMG, era, price, prestigeValue);
|
||||
|
||||
Building4 b1 = (Building4) b0.clone();
|
||||
|
||||
assertEquals(idIMG, b1.getIdIMG());
|
||||
assertEquals(effectID, b1.getEffectId());
|
||||
assertEquals(effectType, b1.getEffectType());
|
||||
assertEquals(era, b1.getEra());
|
||||
@@ -100,4 +103,55 @@ class Building4Test {
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> b4.applyEffect(p));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Testing constructor with idIMG")
|
||||
void testConstructorWithIdIMG() {
|
||||
String idIMG = "building4.png";
|
||||
int era = 1;
|
||||
int price = 10;
|
||||
int prestigeValue = 5;
|
||||
|
||||
Building4 b4 = new Building4(idIMG, era, price, prestigeValue);
|
||||
|
||||
assertEquals(idIMG, b4.getIdIMG());
|
||||
assertEquals(era, b4.getEra());
|
||||
assertEquals(price, b4.getPrice());
|
||||
assertEquals(prestigeValue, b4.getPrestigeValue());
|
||||
assertEquals(EffectType.INVENTOR_PAIR, b4.getEffectType());
|
||||
assertEquals(4, b4.getEffectId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Buying same card by two different players")
|
||||
void buyShouldRejectSameCardForDifferentPlayers() {
|
||||
Building4 b4 = new Building4(1, 1, 1);
|
||||
Player p1 = new Player("test1");
|
||||
Player p2 = new Player("test2");
|
||||
|
||||
p1.addFood(b4.getPrice());
|
||||
p2.addFood(b4.getPrice());
|
||||
|
||||
assertTrue(b4.buy(p1));
|
||||
assertFalse(b4.buy(p2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Effect should reward multiple pairs of same inventor")
|
||||
void applyEffectShouldRewardMultiplePairsOfSameInventor() {
|
||||
Player p = new Player("test");
|
||||
Building4 b4 = new Building4(1, 1, 1);
|
||||
|
||||
p.addFood(b4.getPrice());
|
||||
assertTrue(b4.buy(p));
|
||||
|
||||
new Inventor(1, 1).insert(p);
|
||||
new Inventor(1, 1).insert(p);
|
||||
new Inventor(1, 1).insert(p);
|
||||
new Inventor(1, 1).insert(p);
|
||||
|
||||
b4.applyEffect(p);
|
||||
|
||||
assertEquals(6, p.getFoodValue());
|
||||
}
|
||||
}
|
||||
|
||||
+35
-14
@@ -26,15 +26,18 @@ class Building8Test {
|
||||
@Test
|
||||
@DisplayName("Testing clone method")
|
||||
void testClone() {
|
||||
String idIMG = "building8.png";
|
||||
int effectID = 8;
|
||||
EffectType effectType = EffectType.FINAL;
|
||||
int era = 1;
|
||||
int price = 1;
|
||||
int prestigeValue = 1;
|
||||
Building8 b0 = new Building8(era, price,prestigeValue);
|
||||
|
||||
Building8 b0 = new Building8(idIMG, era, price, prestigeValue);
|
||||
|
||||
Building8 b1 = (Building8) b0.clone();
|
||||
|
||||
assertEquals(idIMG, b1.getIdIMG());
|
||||
assertEquals(effectID, b1.getEffectId());
|
||||
assertEquals(effectType, b1.getEffectType());
|
||||
assertEquals(era, b1.getEra());
|
||||
@@ -43,28 +46,25 @@ class Building8Test {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Apply effect should add prestige from builders")
|
||||
void applyEffect() {
|
||||
Building8 b8 = new Building8(1, 1, 1);
|
||||
Player p = new Player("test");
|
||||
|
||||
p.addFood(b8.getPrice());
|
||||
b8.buy(p);
|
||||
assertTrue(b8.buy(p));
|
||||
|
||||
int era = 1;
|
||||
|
||||
Builder builder1 = new Builder(era, 1, 2);
|
||||
Builder builder2 = new Builder(era, 1, 3);
|
||||
|
||||
int Era = 1;
|
||||
int PrestigeMul = 1;
|
||||
Builder builder1 = new Builder(Era, 1, PrestigeMul);
|
||||
p.builders.add(builder1);
|
||||
p.builders.add(builder2);
|
||||
|
||||
b8.applyEffect(p);
|
||||
|
||||
assertEquals(1, p.buildingCards.stream().filter(x -> x.getEffectId() == 8).count());
|
||||
assertEquals(PrestigeMul* p.buildingCards.stream().filter(x -> x.getEffectId() == 8).count(), p.getPrestigeValue());
|
||||
|
||||
p.removePrestige(p.getPrestigeValue());
|
||||
Builder b2 = new Builder(Era, 1, PrestigeMul);
|
||||
p.builders.add(b2);
|
||||
b8.applyEffect(p);
|
||||
|
||||
assertEquals(PrestigeMul * 2, p.getPrestigeValue());
|
||||
assertEquals(5, p.getPrestigeValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,4 +77,25 @@ class Building8Test {
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> b8.applyEffect(p));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Testing constructor with idIMG")
|
||||
void testConstructorWithIdIMG() {
|
||||
String idIMG = "building8.png";
|
||||
int era = 1;
|
||||
int price = 10;
|
||||
int prestigeValue = 5;
|
||||
|
||||
Building8 b8 = new Building8(idIMG, era, price, prestigeValue);
|
||||
|
||||
assertEquals(idIMG, b8.getIdIMG());
|
||||
assertEquals(era, b8.getEra());
|
||||
assertEquals(price, b8.getPrice());
|
||||
assertEquals(prestigeValue, b8.getPrestigeValue());
|
||||
assertEquals(EffectType.FINAL, b8.getEffectType());
|
||||
assertEquals(8, b8.getEffectId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user