update ManaMultiMap clear

update ManaPoolTest
This commit is contained in:
Anthony Calosa
2024-11-21 14:37:32 +08:00
parent dda5afe704
commit 259247c842
3 changed files with 24 additions and 1 deletions

View File

@@ -442,6 +442,9 @@ public class ManaPool extends ManaConversionMatrix implements Iterable<Mana> {
}
public void clear() {
for (Map.Entry<K, Collection<V>> entry : storage().entrySet()) {
entry.getValue().clear();
}
storage().clear();
}

View File

@@ -36,7 +36,7 @@ public class FCollectionTest {
int i = 0;
for (Card c : cc) {
if (i != 3)
cc.remove(c);
cc.remove(c); // throws error if the CardCollection not threadsafe
i++;
}
assertEquals(cc.size(), 1);

View File

@@ -19,6 +19,26 @@ public class ManaPoolTest extends SimulationTest {
* Just a quick test for ManaPool.
*/
@Test
void testManaPoolBadLogic() {
Game game = initAndCreateGame();
Player p0 = game.getPlayers().get(0);
Player p1 = game.getPlayers().get(1);
Mana w = new Mana(MagicColor.WHITE, new Card(1, game), null);
Mana b = new Mana(MagicColor.BLACK, new Card(1, game), null);
p0.getManaPool().addMana(w, false);
p0.getManaPool().addMana(w, false);
p0.getManaPool().addMana(w, false);
p1.getManaPool().addMana(b, false);
p1.getManaPool().addMana(b, false);
p1.getManaPool().resetPool(); // empty manapool, should clear all values
for (Mana m : p0.getManaPool()) {
p1.getManaPool().addMana(m, false);
p0.getManaPool().removeMana(m, false); // throws error if ManaPool is not threadsafe
}
assertEquals(p0.getManaPool().getAmountOfColor(MagicColor.WHITE), 0);
assertEquals(p1.getManaPool().getAmountOfColor(MagicColor.WHITE), 3);
}
@Test
void testCompletableFuture() {
Game game = initAndCreateGame();
Player p0 = game.getPlayers().get(0);