test: partial test for EventDeserializer
This commit is contained in:
parent
488b18b40c
commit
ab011e54da
@ -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<EventBuilder> filledEventBuilders() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Provide("entityIDs")
|
||||
private Arbitrary<EntityID> 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<IntVector2> randomPositions() {
|
||||
return Arbitraries.integers()
|
||||
.greaterOrEqual(0)
|
||||
.tuple2()
|
||||
.map((pos) -> new IntVector2(pos.get1(), pos.get2()));
|
||||
}
|
||||
|
||||
@Provide("directions")
|
||||
private Arbitrary<IntVector2> 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<Tuple.Tuple2<IntVector2, IntVector2>> 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.<IntVector2, IntVector2>of(origin, attackField);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user