breaking: remove observable pattern, make methods return events directly

This commit is contained in:
2021-06-01 15:43:04 +02:00
parent 4802b0113d
commit 842db2439a
6 changed files with 92 additions and 92 deletions

View File

@ -7,6 +7,8 @@ import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.*;
import uulm.teamname.marvelous.gamelibrary.entities.Character;
import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
import uulm.teamname.marvelous.gamelibrary.events.EventType;
import uulm.teamname.marvelous.gamelibrary.json.config.*;
import uulm.teamname.marvelous.gamelibrary.requests.*;
@ -16,6 +18,7 @@ import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
class GameLogicTest {
private static final Iterator<Integer> randomIntegers = ThreadLocalRandom.current().ints().iterator();
@ -24,6 +27,9 @@ class GameLogicTest {
private static CharacterConfig characterConfig;
private static ScenarioConfig scenarioConfig;
private static ArrayList<Integer> player1Selection = new ArrayList<>();
private static ArrayList<Integer> player2Selection = new ArrayList<>();
@BeforeAll
static void setUp() {
partyConfig = new PartyConfig();
@ -55,6 +61,14 @@ class GameLogicTest {
}
}
}
for(int i = 0; i < 6; i++) {
player1Selection.add(i);
}
for(int i = 6; i < 12; i++) {
player2Selection.add(i);
}
}
private static String generateName(int length) {
@ -87,16 +101,7 @@ class GameLogicTest {
void testGeneration() {
GameInstance game = new GameInstance(partyConfig, characterConfig, scenarioConfig);
ArrayList<Integer> selected1 = new ArrayList<>();
for(int i = 0; i < 6; i++) {
selected1.add(i);
}
ArrayList<Integer> selected2 = new ArrayList<>();
for(int i = 6; i < 12; i++) {
selected2.add(i);
}
game.startGame(selected1, selected2);
game.startGame(player1Selection, player2Selection);
int n = 0;
@ -114,7 +119,7 @@ class GameLogicTest {
n = 0;
for(Integer i: selected1) {
for(Integer i: player1Selection) {
Entity found = game.state.getEntities().findEntity(new EntityID(EntityType.P1, n));
assertNotEquals(null, found, "Character Entity "+n+" for Player 1 should exist");
Character c = (Character)found;
@ -129,7 +134,7 @@ class GameLogicTest {
n = 0;
for(Integer i: selected2) {
for(Integer i: player2Selection) {
Entity found = game.state.getEntities().findEntity(new EntityID(EntityType.P2, n));
assertNotEquals(null, found, "Character Entity "+n+" for Player 2 should exist");
Character c = (Character)found;
@ -165,26 +170,15 @@ class GameLogicTest {
void testGame() {
GameInstance game = new GameInstance(partyConfig, characterConfig, scenarioConfig);
game.addObserver(new EventObserver() {
@Override
protected void handle(Event[] events) {
ArrayList<Event> result = game.startGame(player1Selection, player2Selection);
}
});
assertTrue(result.size() > 0, "Start game should return at least one event");
ArrayList<Integer> selected1 = new ArrayList<>();
for(int i = 0; i < 6; i++) {
selected1.add(i);
}
ArrayList<Integer> selected2 = new ArrayList<>();
for(int i = 6; i < 12; i++) {
selected2.add(i);
}
Event actual = result.get(0);
game.startGame(selected1, selected2);
assertEquals(EventType.GamestateEvent, actual.type, "First event should be a GameStateEvent");
}
// @Provide("gamestate")
// Arbitrary<GameState> gamestate() {
// var states = Arbitraries.integers()