Merge pull request #68

tests-fix
This commit is contained in:
GabrieleRadice
2026-05-02 17:35:41 +02:00
committed by GitHub
8 changed files with 202 additions and 30 deletions
@@ -112,6 +112,7 @@ class Building11Test {
@Test
@DisplayName("toString")
void testToString(){
int ID = 11;
int era = 1;
int price = 1;
int prestigeValue = 3;
@@ -119,26 +120,26 @@ class Building11Test {
int pm = 5;
Building11 b11 = new Building11(era, price, prestigeValue, ct, pm);
assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
ct = CharacterType.BUILDER;
b11 = new Building11(era, price, prestigeValue, ct, pm);
assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
ct = CharacterType.GATHERER;
b11 = new Building11(era, price, prestigeValue, ct, pm);
assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
ct = CharacterType.HUNTER;
b11 = new Building11(era, price, prestigeValue, ct, pm);
assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
ct = CharacterType.INVENTOR;
b11 = new Building11(era, price, prestigeValue, ct, pm);
assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
ct = CharacterType.SHAMAN;
b11 = new Building11(era, price, prestigeValue, ct, pm);
assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
}
}
@@ -70,22 +70,34 @@ class Building1Test {
@Test
@DisplayName("toString")
void testToString(){
Building1 b1 = new Building1(1,2,3, CharacterType.INVENTOR);
assertEquals("Era:1 Price:2 Prestige:3 Icon: INVENTOR", b1.toString());
int ID = 1;
int era = 1;
int price = 1;
int prestigeValue = 3;
CharacterType ct = CharacterType.ARTIST;
int pm = 5;
b1 = new Building1(1,2,3, CharacterType.BUILDER);
assertEquals("Era:1 Price:2 Prestige:3 Icon: BUILDER", b1.toString());
Building1 b1 = new Building1(era, price, prestigeValue, ct);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString());
b1 = new Building1(1,2,3, CharacterType.GATHERER);
assertEquals("Era:1 Price:2 Prestige:3 Icon: GATHERER", b1.toString());
ct = CharacterType.BUILDER;
b1 = new Building1(era, price, prestigeValue, ct);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString());
b1 = new Building1(1,2,3, CharacterType.ARTIST);
assertEquals("Era:1 Price:2 Prestige:3 Icon: ARTIST", b1.toString());
ct = CharacterType.GATHERER;
b1 = new Building1(era, price, prestigeValue, ct);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString());
b1 = new Building1(1,2,3, CharacterType.SHAMAN);
assertEquals("Era:1 Price:2 Prestige:3 Icon: SHAMAN", b1.toString());
ct = CharacterType.HUNTER;
b1 = new Building1(era, price, prestigeValue, ct);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString());
b1 = new Building1(1,2,3, CharacterType.HUNTER);
assertEquals("Era:1 Price:2 Prestige:3 Icon: HUNTER", b1.toString());
ct = CharacterType.INVENTOR;
b1 = new Building1(era, price, prestigeValue, ct);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString());
ct = CharacterType.SHAMAN;
b1 = new Building1(era, price, prestigeValue, ct);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString());
}
}
@@ -2,6 +2,7 @@ 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.Building13;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Builder;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@@ -149,12 +150,162 @@ class BuildingCardTest {
assertFalse(bc0.buy(p2));
}
@Test
@DisplayName("Testing the buy method with discounts")
void testBuyDiscount() {
int food = 5;
int price = 5;
int RV = 1;
Player p = new Player("test");
p.addFood(food);
p.builders.add(new Builder(1, RV, 1));
//Testing that to pay == price - 1
for(int ID = 3; ID < 13; ID++){
if(ID == 4 || ID == 8 || ID == 10 || ID == 11){
continue;
}
BuildingCard bc = new BuildingCard(ID, 1, price,1);
assertEquals(food, p.getFoodValue());
assertTrue(bc.buy(p));
int discount = p.builders.stream().mapToInt(x -> x.getReductionValue()).sum();
assertEquals(food - price + discount, p.getFoodValue());
p.removeFood(p.getFoodValue());
p.addFood(food);
}
//Testing that to pay == 0
p.removeFood(p.getFoodValue());
p.addFood(food);
p.builders.add(new Builder(1, RV, 1));
p.builders.add(new Builder(1, RV, 1));
p.builders.add(new Builder(1, RV, 1));
p.builders.add(new Builder(1, RV, 1));
for(int ID = 3; ID < 13; ID++){
if(ID == 4 || ID == 8 || ID == 10 || ID == 11){
continue;
}
BuildingCard bc = new BuildingCard(ID, 1, price,1);
assertEquals(food, p.getFoodValue());
assertTrue(bc.buy(p));
assertEquals(food, p.getFoodValue());
p.removeFood(p.getFoodValue());
p.addFood(food);
}
//Testing that to pay == 0; discount shouldn't go below 0
p.removeFood(p.getFoodValue());
p.addFood(food);
p.builders.add(new Builder(1, RV, 1));
p.builders.add(new Builder(1, RV, 1));
p.builders.add(new Builder(1, RV, 1));
p.builders.add(new Builder(1, RV, 1));
p.builders.add(new Builder(1, RV, 1));
p.builders.add(new Builder(1, RV, 1));
p.builders.add(new Builder(1, RV, 1));
for(int ID = 3; ID < 13; ID++){
if(ID == 4 || ID == 8 || ID == 10 || ID == 11){
continue;
}
BuildingCard bc = new BuildingCard(ID, 1, price,1);
assertEquals(food, p.getFoodValue());
assertTrue(bc.buy(p));
assertEquals(food, p.getFoodValue());
p.removeFood(p.getFoodValue());
p.addFood(food);
}
//Testing that to pay == 0 if price < builder b * b.RV
food = 6;
price = 3;
RV = 4;
Player p2 = new Player("test");
p2.addFood(food);
p2.builders.add(new Builder(1, RV, 1));
for(int ID = 3; ID < 13; ID++){
if(ID == 4 || ID == 8 || ID == 10 || ID == 11){
continue;
}
BuildingCard bc = new BuildingCard(ID, 1, price,1);
assertEquals(food, p2.getFoodValue());
assertTrue(bc.buy(p2));
int discount = p2.builders.stream().mapToInt(x -> x.getReductionValue()).sum();
assertEquals(food, p2.getFoodValue());
p2.removeFood(p2.getFoodValue());
p2.addFood(food);
}
p2.removeFood(p2.getFoodValue());
p2.addFood(food);
//Testing discount with staggered values
price = 7;
for(int ID = 3; ID < 13; ID++){
if(ID == 4 || ID == 8 || ID == 10 || ID == 11){
continue;
}
BuildingCard bc = new BuildingCard(ID, 1, price,1);
assertEquals(food, p2.getFoodValue());
assertTrue(bc.buy(p2));
int discount = p2.builders.stream().mapToInt(x -> x.getReductionValue()).sum();
assertEquals(food - price + discount, p2.getFoodValue());
p2.removeFood(p2.getFoodValue());
p2.addFood(food);
}
//Testing discount with staggered values; discount shouldn't go below 0
p2.builders.add(new Builder(1, RV, 1));
for(int ID = 3; ID < 13; ID++){
if(ID == 4 || ID == 8 || ID == 10 || ID == 11){
continue;
}
BuildingCard bc = new BuildingCard(ID, 1, price,1);
assertEquals(food, p2.getFoodValue());
assertTrue(bc.buy(p2));
assertEquals(food, p2.getFoodValue());
p2.removeFood(p2.getFoodValue());
p2.addFood(food);
}
}
@Test
@DisplayName("Testing toString method")
void testToString() {
Building13 b0 = new Building13(1, 2,3);
int era = 2;
int price = 5;
int prestigeValue = 6;
assertEquals("Era:1 Price:2 Prestige:3", b0.toString());
BuildingCard b0 = new BuildingCard(era, price, prestigeValue);
assertEquals("⎕:" + " ID:0" + " $:"+ b0.getPrice() + " PV:" + b0.getPrestigeValue(), b0.toString());
for(int ID = 3; ID < 13; ID++){
if(ID == 4 || ID == 8 || ID == 10 || ID == 11){
continue;
}
BuildingCard b = new BuildingCard(ID, era, price, prestigeValue);
assertEquals("⎕:" + " ID:" + ID + " $:"+ b.getPrice() + " PV:" + b.getPrestigeValue(), b.toString());
}
}
@Test
@@ -14,7 +14,7 @@ class ArtistTest {
String s = a.toString();
assertNotNull(s);
assertTrue(s.contains(CharacterType.ARTIST.toString()));
assertTrue(s.contains("⎕:"));
}
@Test
@@ -27,9 +27,8 @@ class BuilderTest {
String s = b.toString();
assertNotNull(s);
assertTrue(s.contains(CharacterType.BUILDER.toString()));
assertTrue(s.contains("Reduction Value: 2"));
assertTrue(s.contains("Prestige Value: 3"));
assertFalse(s.contains(CharacterType.BUILDER.toString()));
assertEquals("⎕:" + " RV:" + b.getReductionValue() + " PV:" + b.getPrestigeValue(), s);
}
@Test
@@ -13,8 +13,11 @@ class GathererTest {
Gatherer g = new Gatherer(1);
String s = g.toString();
System.out.println(s);
assertNotNull(s);
assertTrue(s.contains(CharacterType.GATHERER.toString()));
assertFalse(s.contains(CharacterType.GATHERER.toString()));
assertTrue(s.contains("⎕:"));
}
@Test
@@ -141,13 +141,11 @@ class GameTest {
}
private boolean hasDrawableLower(Game game) {
return firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) != -1
|| !game.getLowerListBuilding().isEmpty();
return firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) != -1;
}
private boolean hasDrawableUpper(Game game) {
return firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) != -1
|| !game.getUpperListBuilding().isEmpty();
return firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) != -1;
}
@Test