diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/EventSerializerTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/EventSerializerTest.java new file mode 100644 index 0000000..0407ae2 --- /dev/null +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/EventSerializerTest.java @@ -0,0 +1,85 @@ +package uulm.teamname.marvelous.gamelibrary.json.ingame; + +import com.fasterxml.jackson.databind.ObjectMapper; +import net.jqwik.api.*; +import net.jqwik.api.lifecycle.BeforeProperty; +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.events.EventBuilder; + +public class EventSerializerTest { + + ObjectMapper mapper; + + @BeforeProperty + void beforeProperty() { + mapper = new ObjectMapper(); + } + + + @Property + void gameEventsGetDeserializedProperly() { + var jsonRepresentingEvent = ""; + } + + + @Provide("filledEventBuilders") + private Arbitrary filledEventBuilders() { + return null; + } + + + + + @Provide("entityIDs") + private Arbitrary entityIDs() { + var entityTypes = Arbitraries.of(EntityType.class); + return Combinators.combine(entityTypes, Arbitraries.integers().greaterOrEqual(0)) + .as((type, id) -> { + int actualID; + if (type == EntityType.P1 || type == EntityType.P2 || type == EntityType.InfinityStones) { + actualID = id % 6; + } else if (type == EntityType.NPC) { + actualID = id % 3; + } else { + actualID = id; + } + return new EntityID(type, id); + }); + } + + @Provide("randomPositions") + private Arbitrary randomPositions() { + return Arbitraries.integers() + .greaterOrEqual(0) + .tuple2() + .map((pos) -> new IntVector2(pos.get1(), pos.get2())); + } + + @Provide("directions") + private Arbitrary directions() { + return Arbitraries.integers() + .between(-1, 1) + .tuple2() + .filter(pos -> pos.get1() != 0 && pos.get2() != 0) // eliminate zero vectors + .map(pos -> new IntVector2(pos.get1(), pos.get2())); + } + + @Provide("attackPositions") + /** Returns tuples of origin vectors (of an attack), and the vector pointing to the attack dir */ + private Arbitrary> attackPositions() { + return Combinators.combine(randomPositions(), directions().tuple5()) + .as((origin, dir) -> { + var attackField = origin.copy() + .add(dir.get1().scale(3)) + .add(dir.get2().scale(3)) + .add(dir.get3().scale(3)) + .add(dir.get4().scale(3)); + if (attackField.length() == 0) { + attackField.add(dir.get5().scale(3)); + } + return Tuple.of(origin, attackField); + }); + } +}