@@ -159,8 +159,16 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
|
|||||||
* @return {@code true} if the building card is successfully bought,
|
* @return {@code true} if the building card is successfully bought,
|
||||||
* {@code false} otherwise.
|
* {@code false} otherwise.
|
||||||
*/
|
*/
|
||||||
|
// sum reduction value builder=> sconto
|
||||||
public boolean buy(Player player) {
|
public boolean buy(Player player) {
|
||||||
if( bought || !player.removeFood(getPrice()))
|
int discount = 0;
|
||||||
|
discount = player.builders.stream().mapToInt(x -> x.getReductionValue()).sum();
|
||||||
|
|
||||||
|
if(discount > this.price){
|
||||||
|
discount = this.price;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bought || !player.removeFood(this.price - discount))
|
||||||
return false;
|
return false;
|
||||||
player.buildingCards.add(this);
|
player.buildingCards.add(this);
|
||||||
bought=true;
|
bought=true;
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ class Building11Test {
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("toString")
|
@DisplayName("toString")
|
||||||
void testToString(){
|
void testToString(){
|
||||||
|
int ID = 11;
|
||||||
int era = 1;
|
int era = 1;
|
||||||
int price = 1;
|
int price = 1;
|
||||||
int prestigeValue = 3;
|
int prestigeValue = 3;
|
||||||
@@ -119,26 +120,26 @@ class Building11Test {
|
|||||||
int pm = 5;
|
int pm = 5;
|
||||||
|
|
||||||
Building11 b11 = new Building11(era, price, prestigeValue, ct, pm);
|
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;
|
ct = CharacterType.BUILDER;
|
||||||
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
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;
|
ct = CharacterType.GATHERER;
|
||||||
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
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;
|
ct = CharacterType.HUNTER;
|
||||||
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
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;
|
ct = CharacterType.INVENTOR;
|
||||||
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
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;
|
ct = CharacterType.SHAMAN;
|
||||||
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+24
-12
@@ -70,22 +70,34 @@ class Building1Test {
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("toString")
|
@DisplayName("toString")
|
||||||
void testToString(){
|
void testToString(){
|
||||||
Building1 b1 = new Building1(1,2,3, CharacterType.INVENTOR);
|
int ID = 1;
|
||||||
assertEquals("Era:1 Price:2 Prestige:3 Icon: INVENTOR", b1.toString());
|
int era = 1;
|
||||||
|
int price = 1;
|
||||||
|
int prestigeValue = 3;
|
||||||
|
CharacterType ct = CharacterType.ARTIST;
|
||||||
|
int pm = 5;
|
||||||
|
|
||||||
b1 = new Building1(1,2,3, CharacterType.BUILDER);
|
Building1 b1 = new Building1(era, price, prestigeValue, ct);
|
||||||
assertEquals("Era:1 Price:2 Prestige:3 Icon: BUILDER", b1.toString());
|
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString());
|
||||||
|
|
||||||
b1 = new Building1(1,2,3, CharacterType.GATHERER);
|
ct = CharacterType.BUILDER;
|
||||||
assertEquals("Era:1 Price:2 Prestige:3 Icon: GATHERER", b1.toString());
|
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);
|
ct = CharacterType.GATHERER;
|
||||||
assertEquals("Era:1 Price:2 Prestige:3 Icon: ARTIST", b1.toString());
|
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);
|
ct = CharacterType.HUNTER;
|
||||||
assertEquals("Era:1 Price:2 Prestige:3 Icon: SHAMAN", b1.toString());
|
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);
|
ct = CharacterType.INVENTOR;
|
||||||
assertEquals("Era:1 Price:2 Prestige:3 Icon: HUNTER", b1.toString());
|
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.EffectType;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.Building13;
|
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 it.polimi.ingsw.gc14.Model.Player;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -149,12 +150,162 @@ class BuildingCardTest {
|
|||||||
assertFalse(bc0.buy(p2));
|
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
|
@Test
|
||||||
@DisplayName("Testing toString method")
|
@DisplayName("Testing toString method")
|
||||||
void testToString() {
|
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
|
@Test
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ class ArtistTest {
|
|||||||
String s = a.toString();
|
String s = a.toString();
|
||||||
|
|
||||||
assertNotNull(s);
|
assertNotNull(s);
|
||||||
assertTrue(s.contains(CharacterType.ARTIST.toString()));
|
assertTrue(s.contains("⎕:"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+2
-3
@@ -27,9 +27,8 @@ class BuilderTest {
|
|||||||
String s = b.toString();
|
String s = b.toString();
|
||||||
|
|
||||||
assertNotNull(s);
|
assertNotNull(s);
|
||||||
assertTrue(s.contains(CharacterType.BUILDER.toString()));
|
assertFalse(s.contains(CharacterType.BUILDER.toString()));
|
||||||
assertTrue(s.contains("Reduction Value: 2"));
|
assertEquals("⎕:" + " RV:" + b.getReductionValue() + " PV:" + b.getPrestigeValue(), s);
|
||||||
assertTrue(s.contains("Prestige Value: 3"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+4
-1
@@ -13,8 +13,11 @@ class GathererTest {
|
|||||||
Gatherer g = new Gatherer(1);
|
Gatherer g = new Gatherer(1);
|
||||||
String s = g.toString();
|
String s = g.toString();
|
||||||
|
|
||||||
|
System.out.println(s);
|
||||||
|
|
||||||
assertNotNull(s);
|
assertNotNull(s);
|
||||||
assertTrue(s.contains(CharacterType.GATHERER.toString()));
|
assertFalse(s.contains(CharacterType.GATHERER.toString()));
|
||||||
|
assertTrue(s.contains("⎕:"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -141,13 +141,11 @@ class GameTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasDrawableLower(Game game) {
|
private boolean hasDrawableLower(Game game) {
|
||||||
return firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) != -1
|
return firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) != -1;
|
||||||
|| !game.getLowerListBuilding().isEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasDrawableUpper(Game game) {
|
private boolean hasDrawableUpper(Game game) {
|
||||||
return firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) != -1
|
return firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) != -1;
|
||||||
|| !game.getUpperListBuilding().isEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user