Fix: Fixed "buy" Method In BuildingCard.java And Relative Tests In BuildingCardTest.java; Now Correctly Handles Discounts Given By Builders.
Fix: Fixed "toString" Method In BuildingCard.java And Relative Tests In BuildingCardTest.java.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user