wip: add basic test for GameState.snapshot

This commit is contained in:
punchready 2021-04-30 21:49:10 +02:00
parent fcd2338b11
commit fc1382b343
2 changed files with 37 additions and 3 deletions

View File

@ -1,14 +1,13 @@
package uulm.teamname.marvelous.gamelibrary; package uulm.teamname.marvelous.gamelibrary;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class TupleTest { class TupleTest {
@Test @Test
void basic() { void basicTest() {
var a = new Tuple<Integer, Integer>(0, 1); Tuple<Integer, Integer> a = new Tuple<>(0, 1);
assertEquals((int) a.item1, 0); assertEquals((int) a.item1, 0);
assertEquals((int) a.item2, 1); assertEquals((int) a.item2, 1);
} }

View File

@ -0,0 +1,35 @@
package uulm.teamname.marvelous.gamelibrary.gamelogic;
import org.junit.jupiter.api.Test;
import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
import uulm.teamname.marvelous.gamelibrary.entities.Rock;
import static org.junit.jupiter.api.Assertions.*;
class GameStateTest {
@Test
void testSnapshot() {
//TODO: test all properties in GameStateTest.testSnapshot
//base state
GameState state = new GameState(new IntVector2(10, 10));
//set up game
state.entities.addEntity(new Rock(new EntityID(0, EntityType.Rocks), new IntVector2(0, 0), 100));
//snapshot state
GameState snapshot = state.snapshot();
//modify snapshot and test for disconnection
snapshot.turnNumber = 10;
assertEquals(0, state.turnNumber, "Original's turn number should remain unchanged");
assertTrue(snapshot.entities.getEntities().hasNext(), "Snapshot should contain cloned entities");
((Rock)snapshot.entities.getEntities().next()).decreaseHp(5);
assertEquals(100, ((Rock)state.entities.getEntities().next()).getHp(), "Original's rock entity hp should remain unchanged");
}
}