Add: complete tests for model cards and player logic
This commit is contained in:
@@ -69,7 +69,7 @@ class BuildingCardTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Testing the second constructor (4 parameters)")
|
||||
void testBuildingCard2() {}{
|
||||
void testBuildingCard2() {
|
||||
// Testing right parameters
|
||||
BuildingCard bc2 = new BuildingCard(2,1,1,1);
|
||||
BuildingCard bc3 = new BuildingCard(3,1,1,1);
|
||||
@@ -87,15 +87,13 @@ class BuildingCardTest {
|
||||
assertEquals(EffectType.ON_EVENT, bc9.getEffectType());
|
||||
assertEquals(EffectType.ON_ROUND_END, bc12.getEffectType());
|
||||
|
||||
// Testing wrong parameters
|
||||
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(0,1,1,1);});
|
||||
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(1,1,1,1);});
|
||||
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(4,1,1,1);});
|
||||
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(8,1,1,1);});
|
||||
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(10,1,1,1);});
|
||||
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(11,1,1,1);});
|
||||
assertThrows(IllegalArgumentException.class, () -> {new BuildingCard(13,1,1,1);});
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> new BuildingCard(0,1,1,1));
|
||||
assertThrows(IllegalArgumentException.class, () -> new BuildingCard(1,1,1,1));
|
||||
assertThrows(IllegalArgumentException.class, () -> new BuildingCard(4,1,1,1));
|
||||
assertThrows(IllegalArgumentException.class, () -> new BuildingCard(8,1,1,1));
|
||||
assertThrows(IllegalArgumentException.class, () -> new BuildingCard(10,1,1,1));
|
||||
assertThrows(IllegalArgumentException.class, () -> new BuildingCard(11,1,1,1));
|
||||
assertThrows(IllegalArgumentException.class, () -> new BuildingCard(13,1,1,1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -146,6 +144,10 @@ class BuildingCardTest {
|
||||
BuildingCard bc0 = new BuildingCard(2, 1,1,1);
|
||||
|
||||
assertTrue(bc0.buy(p1));
|
||||
|
||||
assertTrue(p1.buildingCards.contains(bc0));
|
||||
assertEquals(1, p1.buildingCards.size());
|
||||
|
||||
assertFalse(bc0.buy(p1));
|
||||
assertFalse(bc0.buy(p2));
|
||||
}
|
||||
@@ -338,4 +340,87 @@ class BuildingCardTest {
|
||||
assertEquals(0, p.getPrestigeValue());
|
||||
assertEquals(user, p.getUserName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void constructorWithIdIMGTest() {
|
||||
BuildingCard b = new BuildingCard("building1", 1, 5, 6);
|
||||
|
||||
assertEquals(1, b.getEra());
|
||||
assertEquals(5, b.getPrice());
|
||||
assertEquals(6, b.getPrestigeValue());
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new BuildingCard("building1", 1, 0, 6)
|
||||
);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new BuildingCard("building1", 1, 5, -1)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void constructorWithIdIMGAndEffectIdTest() {
|
||||
BuildingCard bc2 = new BuildingCard("b2", 2, 1, 1, 1);
|
||||
BuildingCard bc3 = new BuildingCard("b3", 3, 1, 1, 1);
|
||||
BuildingCard bc5 = new BuildingCard("b5", 5, 1, 1, 1);
|
||||
BuildingCard bc6 = new BuildingCard("b6", 6, 1, 1, 1);
|
||||
BuildingCard bc7 = new BuildingCard("b7", 7, 1, 1, 1);
|
||||
BuildingCard bc9 = new BuildingCard("b9", 9, 1, 1, 1);
|
||||
BuildingCard bc12 = new BuildingCard("b12", 12, 1, 1, 1);
|
||||
|
||||
assertEquals(2, bc2.getEffectId());
|
||||
assertEquals(3, bc3.getEffectId());
|
||||
assertEquals(5, bc5.getEffectId());
|
||||
assertEquals(6, bc6.getEffectId());
|
||||
assertEquals(7, bc7.getEffectId());
|
||||
assertEquals(9, bc9.getEffectId());
|
||||
assertEquals(12, bc12.getEffectId());
|
||||
|
||||
assertEquals(EffectType.ON_EVENT, bc2.getEffectType());
|
||||
assertEquals(EffectType.ON_END_TURN, bc3.getEffectType());
|
||||
assertEquals(EffectType.ON_EVENT, bc5.getEffectType());
|
||||
assertEquals(EffectType.ON_EVENT, bc6.getEffectType());
|
||||
assertEquals(EffectType.ON_EVENT, bc7.getEffectType());
|
||||
assertEquals(EffectType.ON_EVENT, bc9.getEffectType());
|
||||
assertEquals(EffectType.ON_ROUND_END, bc12.getEffectType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void constructorWithIdIMGAndEffectIdInvalidValuesTest() {
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new BuildingCard("b0", 0, 1, 1, 1)
|
||||
);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new BuildingCard("b1", 1, 1, 1, 1)
|
||||
);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new BuildingCard("b4", 4, 1, 1, 1)
|
||||
);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new BuildingCard("b13", 13, 1, 1, 1)
|
||||
);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new BuildingCard("b2", 2, 1, 0, 1)
|
||||
);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new BuildingCard("b2", 2, 1, 1, -1)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void buyShouldFailWhenPlayerHasNotEnoughFood() {
|
||||
Player p = new Player("test");
|
||||
p.addFood(2);
|
||||
|
||||
BuildingCard b = new BuildingCard(2, 1, 5, 1);
|
||||
|
||||
assertFalse(b.buy(p));
|
||||
assertFalse(p.buildingCards.contains(b));
|
||||
assertEquals(2, p.getFoodValue());
|
||||
}
|
||||
}
|
||||
@@ -108,4 +108,56 @@ class BuilderTest {
|
||||
new Builder(1, 2, -3);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void constructorWithIdIMGTest() {
|
||||
Builder b = new Builder("builder1", 1, 2, 3);
|
||||
|
||||
assertEquals(1, b.getEra());
|
||||
assertEquals(CharacterType.BUILDER, b.getType());
|
||||
assertEquals(2, b.getReductionValue());
|
||||
assertEquals(3, b.getPrestigeValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void constructorWithIdIMGAndNMinTest() {
|
||||
Builder b = new Builder("builder1", 1, 2, 3, 4);
|
||||
|
||||
assertEquals(1, b.getEra());
|
||||
assertEquals(CharacterType.BUILDER, b.getType());
|
||||
assertEquals(2, b.getReductionValue());
|
||||
assertEquals(3, b.getPrestigeValue());
|
||||
assertEquals(4, b.getNMin());
|
||||
assertFalse(b.IsEventCard());
|
||||
}
|
||||
|
||||
@Test
|
||||
void constructorWithIdIMGInvalidValuesTest() {
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new Builder("builder1", 1, -1, 3)
|
||||
);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new Builder("builder1", 1, 2, -1)
|
||||
);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new Builder("builder1", 1, -1, 3, 4)
|
||||
);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new Builder("builder1", 1, 2, -1, 4)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToStringBoard() {
|
||||
Builder b = new Builder(1, 2, 3);
|
||||
|
||||
String s = b.toStringBoard();
|
||||
|
||||
assertNotNull(s);
|
||||
assertTrue(s.contains("RV:2"));
|
||||
assertTrue(s.contains("PV:3"));
|
||||
}
|
||||
}
|
||||
+56
-3
@@ -1,12 +1,9 @@
|
||||
package it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
||||
import it.polimi.ingsw.gc14.Model.Orders.Order2;
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class InventorTest {
|
||||
@@ -109,4 +106,60 @@ class InventorTest {
|
||||
new Inventor(1, 10, 3);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void constructorWithIdIMGTest() {
|
||||
Inventor i = new Inventor("inventor1", 1, 5);
|
||||
|
||||
assertEquals(1, i.getEra());
|
||||
assertEquals(CharacterType.INVENTOR, i.getType());
|
||||
assertEquals(5, i.Icon());
|
||||
assertEquals(0, i.getNMin());
|
||||
assertFalse(i.IsEventCard());
|
||||
}
|
||||
|
||||
@Test
|
||||
void constructorWithIdIMGAndToStringBoardCoverageTest() {
|
||||
// Valid constructor with idIMG
|
||||
Inventor i1 = new Inventor("inventor1", 1, 5);
|
||||
|
||||
assertEquals(1, i1.getEra());
|
||||
assertEquals(CharacterType.INVENTOR, i1.getType());
|
||||
assertEquals(5, i1.Icon());
|
||||
assertEquals(0, i1.getNMin());
|
||||
assertFalse(i1.IsEventCard());
|
||||
|
||||
// Valid constructor with idIMG and nMin
|
||||
Inventor i2 = new Inventor("inventor2", 1, 7, 3);
|
||||
|
||||
assertEquals(1, i2.getEra());
|
||||
assertEquals(CharacterType.INVENTOR, i2.getType());
|
||||
assertEquals(7, i2.Icon());
|
||||
assertEquals(3, i2.getNMin());
|
||||
assertFalse(i2.IsEventCard());
|
||||
|
||||
// Invalid icon with idIMG constructor
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new Inventor("inventor3", 1, -1);
|
||||
});
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new Inventor("inventor4", 1, 10);
|
||||
});
|
||||
|
||||
// Invalid icon with idIMG and nMin constructor
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new Inventor("inventor5", 1, -1, 3);
|
||||
});
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new Inventor("inventor6", 1, 10, 3);
|
||||
});
|
||||
|
||||
// toStringBoard coverage
|
||||
String s = i1.toStringBoard();
|
||||
|
||||
assertNotNull(s);
|
||||
assertTrue(s.contains("I_ID:5"));
|
||||
}
|
||||
}
|
||||
@@ -81,4 +81,23 @@ class DecksCreatorTest {
|
||||
assertEquals(7, slots.size());
|
||||
assertFalse(slots.contains(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void loadTribeDeckByEra() {
|
||||
List<TribeCard> era1 = DecksCreator.loadTribeDeckByEra(1);
|
||||
List<TribeCard> era2 = DecksCreator.loadTribeDeckByEra(2);
|
||||
List<TribeCard> era3 = DecksCreator.loadTribeDeckByEra(3);
|
||||
|
||||
assertNotNull(era1);
|
||||
assertNotNull(era2);
|
||||
assertNotNull(era3);
|
||||
|
||||
assertEquals(33, era1.size());
|
||||
assertEquals(32, era2.size());
|
||||
assertEquals(29, era3.size());
|
||||
|
||||
assertTrue(era1.stream().allMatch(c -> c.getEra() == 1));
|
||||
assertTrue(era2.stream().allMatch(c -> c.getEra() == 2));
|
||||
assertTrue(era3.stream().allMatch(c -> c.getEra() == 3));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,21 @@ class PlayableCardTest {
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void playableCardWithIdIMGShouldRejectInvalidEra() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new BuildingCard("building1", 2, 0, 5, 1);
|
||||
});
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new BuildingCard("building1", 2, 4, 5, 1);
|
||||
});
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new BuildingCard("building1", 2, -1, 5, 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -240,4 +240,57 @@ class PlayerTest {
|
||||
"║ Buildings: [⎕: ID:2 $:2 PV:5, ⎕: ID:2 $:3 PV:6, ⎕: ID:1 $:5 PV:5 Icon: I, ⎕: ID:1 $:5 PV:5 Icon: S, ⎕: ID:11 $:5 PV:7 Icon: A MP: 3]║\n" +
|
||||
"╚═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝", p.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toStringShouldCoverAllLastCharacterCases() {
|
||||
Player empty = new Player("empty");
|
||||
String emptyString = empty.toString();
|
||||
|
||||
assertNotNull(emptyString);
|
||||
assertTrue(emptyString.contains("empty"));
|
||||
assertTrue(emptyString.contains("CHARACTERS:"));
|
||||
assertTrue(emptyString.contains("BUILDING CARDS:"));
|
||||
|
||||
Player onlyArtist = new Player("onlyArtist");
|
||||
onlyArtist.artists.add(new Artist(1));
|
||||
String artistString = onlyArtist.toString();
|
||||
|
||||
assertTrue(artistString.contains("Artists:"));
|
||||
assertTrue(artistString.contains("BUILDING CARDS:"));
|
||||
|
||||
Player onlyBuilder = new Player("onlyBuilder");
|
||||
onlyBuilder.builders.add(new Builder(1, 1, 1));
|
||||
String builderString = onlyBuilder.toString();
|
||||
|
||||
assertTrue(builderString.contains("Builders:"));
|
||||
assertTrue(builderString.contains("BUILDING CARDS:"));
|
||||
|
||||
Player onlyGatherer = new Player("onlyGatherer");
|
||||
onlyGatherer.gatherers.add(new Gatherer(1, 1));
|
||||
String gathererString = onlyGatherer.toString();
|
||||
|
||||
assertTrue(gathererString.contains("Gatherers:"));
|
||||
assertTrue(gathererString.contains("BUILDING CARDS:"));
|
||||
|
||||
Player onlyShaman = new Player("onlyShaman");
|
||||
onlyShaman.shamans.add(new Shaman(1, 1));
|
||||
String shamanString = onlyShaman.toString();
|
||||
|
||||
assertTrue(shamanString.contains("Shamans:"));
|
||||
assertTrue(shamanString.contains("BUILDING CARDS:"));
|
||||
|
||||
Player onlyInventor = new Player("onlyInventor");
|
||||
onlyInventor.inventors.add(new Inventor(1, 1));
|
||||
String inventorString = onlyInventor.toString();
|
||||
|
||||
assertTrue(inventorString.contains("Inventors:"));
|
||||
assertTrue(inventorString.contains("BUILDING CARDS:"));
|
||||
|
||||
Player onlyHunter = new Player("onlyHunter");
|
||||
onlyHunter.hunters.add(new Hunter(1, true));
|
||||
String hunterString = onlyHunter.toString();
|
||||
|
||||
assertTrue(hunterString.contains("Hunters:"));
|
||||
assertTrue(hunterString.contains("BUILDING CARDS:"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user