Merge branch 'main' into Game-test-fix

This commit is contained in:
rubenpirreram
2026-05-02 17:40:25 +02:00
committed by GitHub
13 changed files with 277 additions and 68 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
@@ -125,11 +125,11 @@ class BoardTest {
void removeUpperTribeCard() {
Board bd = new Board(3);
List<TribeCard> before = bd.upperListTribe;
TribeCard cardToRemove = before.get(2);
List<TribeCard> before = new ArrayList<>( bd.upperListTribe);
TribeCard cardToRemove = before.get(0);
before.remove(2);
bd.removeUpperTribeCard(cardToRemove);
assertEquals(cardToRemove, before.remove(0));
assertTrue( bd.removeUpperTribeCard(cardToRemove));
assertEquals(before, bd.upperListTribe);
}
@@ -139,25 +139,25 @@ class BoardTest {
void removeLowerTribeCard() {
Board bd = new Board(3);
List<TribeCard> before = bd.lowerListTribe;
TribeCard cardToRemove = before.get(2);
List<TribeCard> before = new ArrayList<>(bd.lowerListTribe);
TribeCard cardToRemove = before.get(0);
before.remove(2);
bd.removeLowerTribeCard(cardToRemove);
assertEquals(cardToRemove, before.remove(0));
assertTrue( bd.removeLowerTribeCard(cardToRemove));
assertEquals(before, bd.lowerListTribe);
}
@Test
@DisplayName("RemgetTribeDeckSizeoving a card from upper row of building cards")
@DisplayName("Removing a card from upper row of building cards")
void removeUpperBuildingCard() {
Board bd = new Board(3);
List<BuildingCard> before = bd.upperListBuilding;
List<BuildingCard> before = new ArrayList<>(bd.upperListBuilding);
BuildingCard cardToRemove = before.get(0);
before.remove(0);
bd.removeUpperBuildingCard(cardToRemove);
assertEquals(cardToRemove, before.remove(0));
assertTrue( bd.removeUpperBuildingCard(cardToRemove));
assertEquals(before, bd.upperListBuilding);
}
@@ -171,12 +171,10 @@ class BoardTest {
bd.nextRound(); // Skip to era 2
}
List<BuildingCard> before = bd.lowerListBuilding;
List<BuildingCard> before = new ArrayList<>( bd.lowerListBuilding);
BuildingCard cardToRemove = before.get(0);
before.remove(0);
bd.removeLowerBuildingCard(cardToRemove);
assertEquals(cardToRemove, before.remove(0));
assertTrue(bd.removeLowerBuildingCard(cardToRemove));
assertEquals(before, bd.lowerListBuilding);
}
@@ -214,6 +212,8 @@ class BoardTest {
assertEquals(upperListBefore, bd1.lowerListBuilding);
assertNotEquals(upperListBefore, bd1.upperListBuilding);
assertEquals(2, bd1.upperListBuilding.size());
assertTrue(bd1.upperListBuilding.stream().allMatch(x->x.getEra()==2));
assertTrue(bd1.lowerListBuilding.stream().allMatch(x->x.getEra()==1));
// Era 2, nTotem > 3
@@ -227,7 +227,8 @@ class BoardTest {
assertEquals(upperListBefore, bd2.lowerListBuilding);
assertNotEquals(upperListBefore, bd2.upperListBuilding);
assertEquals(3, bd2.upperListBuilding.size());
assertTrue(bd2.upperListBuilding.stream().allMatch(x->x.getEra()==2));
assertTrue(bd2.lowerListBuilding.stream().allMatch(x->x.getEra()==1));
// Era 3, nTotem == 2
numPlayer = 2;
@@ -243,6 +244,8 @@ class BoardTest {
assertEquals(upperListBefore, bd3.lowerListBuilding);
assertNotEquals(upperListBefore, bd3.upperListBuilding);
assertEquals(3, bd3.upperListBuilding.size());
assertTrue(bd3.upperListBuilding.stream().allMatch(x->x.getEra()==3));
assertTrue(bd3.lowerListBuilding.stream().allMatch(x->x.getEra()==2));
// Era 3, nTotem == 5
@@ -259,6 +262,8 @@ class BoardTest {
assertEquals(upperListBefore, bd4.lowerListBuilding);
assertNotEquals(upperListBefore, bd4.upperListBuilding);
assertEquals(5, bd4.upperListBuilding.size());
assertTrue(bd4.upperListBuilding.stream().allMatch(x->x.getEra()==3));
assertTrue(bd4.lowerListBuilding.stream().allMatch(x->x.getEra()==2));
// Era 3, nTotem != 2, 5
@@ -275,6 +280,8 @@ class BoardTest {
assertEquals(upperListBefore, bd5.lowerListBuilding);
assertNotEquals(upperListBefore, bd5.upperListBuilding);
assertEquals(4, bd5.upperListBuilding.size());
assertTrue(bd5.upperListBuilding.stream().allMatch(x->x.getEra()==3));
assertTrue(bd5.lowerListBuilding.stream().allMatch(x->x.getEra()==2));
}