fix: improve rasterization and tests

This commit is contained in:
2021-06-01 17:15:44 +02:00
parent 0572450ced
commit 5984e40384
4 changed files with 95 additions and 59 deletions

View File

@ -7,32 +7,27 @@ 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.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.*;
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();
private static PartyConfig partyConfig;
private static CharacterConfig characterConfig;
private static ScenarioConfig scenarioConfig;
private static final PartyConfig partyConfig = new PartyConfig();
private static final CharacterConfig characterConfig = new CharacterConfig();
private static final ScenarioConfig scenarioConfig = new ScenarioConfig();
private static ArrayList<Integer> player1Selection = new ArrayList<>();
private static ArrayList<Integer> player2Selection = new ArrayList<>();
private static final ArrayList<Integer> player1Selection = new ArrayList<>();
private static final ArrayList<Integer> player2Selection = new ArrayList<>();
@BeforeAll
static void setUp() {
partyConfig = new PartyConfig();
partyConfig.maxRounds = 100;
partyConfig.mindStoneCD = 2;
partyConfig.powerStoneCD = 3;
@ -42,13 +37,11 @@ class GameLogicTest {
partyConfig.timeStoneCD = 7;
partyConfig.mindStoneDMG = 3;
characterConfig = new CharacterConfig();
characterConfig.characters = new CharacterProperties[] {
generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(),
generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter()
};
scenarioConfig = new ScenarioConfig();
scenarioConfig.name = generateName(20);
scenarioConfig.author = generateName(20);
scenarioConfig.scenario = new FieldType[30][30];
@ -179,6 +172,29 @@ class GameLogicTest {
assertEquals(EventType.GamestateEvent, actual.type, "First event should be a GameStateEvent");
}
@Test
void testRasterize() {
ArrayList<IntVector2> result = GameLogic.rasterize(new IntVector2(0, 0), new IntVector2(1, 1), false, false);
assertEquals(0, result.size(), "Diagonals are not included");
IntVector2[] result2 = GameLogic.rasterize(new IntVector2(0, 0), new IntVector2(4, 0)).toArray(new IntVector2[0]);
assertEquals(new HashSet<>(Arrays.asList(
new IntVector2(0, 0), new IntVector2(1, 0), new IntVector2(2, 0), new IntVector2(3, 0), new IntVector2(4, 0)
)), new HashSet<>(Arrays.asList(result2)), "Straight lines work correctly");
IntVector2[] result3 = GameLogic.rasterize(new IntVector2(0, 0), new IntVector2(2, 1)).toArray(new IntVector2[0]);
assertEquals(new HashSet<>(Arrays.asList(
new IntVector2(0, 0), new IntVector2(1, 0), new IntVector2(1, 1), new IntVector2(2, 1))
), new HashSet<>(Arrays.asList(result3)), "Tilted lines work correctly");
}
// @Provide("gamestate")
// Arbitrary<GameState> gamestate() {
// var states = Arbitraries.integers()