Fix: Building4, Building4Test added
This commit is contained in:
@@ -36,7 +36,7 @@ public class Building4 extends BuildingCard {
|
|||||||
numPair=0;
|
numPair=0;
|
||||||
for(Integer i : map.values())
|
for(Integer i : map.values())
|
||||||
{
|
{
|
||||||
numPair+=(i%2);
|
numPair+=(i/2);
|
||||||
}
|
}
|
||||||
purchased = true;
|
purchased = true;
|
||||||
|
|
||||||
@@ -71,12 +71,13 @@ public class Building4 extends BuildingCard {
|
|||||||
int temp=0;
|
int temp=0;
|
||||||
for(Integer i : map.values())
|
for(Integer i : map.values())
|
||||||
{
|
{
|
||||||
temp+=(i%2);
|
temp+=(i/2);
|
||||||
}
|
}
|
||||||
if(temp<= numPair)
|
if(temp<= numPair)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player.addFood(3*(temp-numPair));
|
player.addFood(3*(temp-numPair));
|
||||||
|
numPair = temp;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Model.Cards.Building.Effects;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Inventor;
|
||||||
|
import it.polimi.ingsw.gc14.Model.Player;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class Building4Test {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void buy() {
|
||||||
|
Player p = new Player("test");
|
||||||
|
Building4 b4 = new Building4(1,1);
|
||||||
|
|
||||||
|
assertFalse(b4.buy(p));
|
||||||
|
|
||||||
|
p.addFood(1);
|
||||||
|
assertTrue(b4.buy(p));
|
||||||
|
assertEquals(0, p.getFoodValue());
|
||||||
|
|
||||||
|
p.addFood(1);
|
||||||
|
assertFalse(b4.buy(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void applyEffect() {
|
||||||
|
Player p = new Player("test");
|
||||||
|
p.addFood(1);
|
||||||
|
Building4 b4 = new Building4(1,1);
|
||||||
|
b4.buy(p);
|
||||||
|
|
||||||
|
b4.applyEffect(p);
|
||||||
|
assertEquals(0, p.getFoodValue());
|
||||||
|
|
||||||
|
new Inventor(1,1).insert(p);
|
||||||
|
new Inventor(1,1).insert(p);
|
||||||
|
b4.applyEffect(p);
|
||||||
|
assertEquals(3, p.getFoodValue());
|
||||||
|
|
||||||
|
b4.applyEffect(p);
|
||||||
|
assertEquals(3, p.getFoodValue());
|
||||||
|
|
||||||
|
new Inventor(1,2).insert(p);
|
||||||
|
new Inventor(1,2).insert(p);
|
||||||
|
b4.applyEffect(p);
|
||||||
|
assertEquals(6, p.getFoodValue());
|
||||||
|
|
||||||
|
Player p2 = new Player("test2");
|
||||||
|
new Inventor(1,1).insert(p2);
|
||||||
|
new Inventor(1,1).insert(p2);
|
||||||
|
p2.addFood(1);
|
||||||
|
Building4 b4b = new Building4(1,1);
|
||||||
|
b4b.buy(p2);
|
||||||
|
b4b.applyEffect(p2);
|
||||||
|
assertEquals(0, p2.getFoodValue());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void applyEffectException() {
|
||||||
|
Player p = new Player("test");
|
||||||
|
Building4 b4 = new Building4(1,1);
|
||||||
|
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> b4.applyEffect(p));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user