diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java index 7c82d6f..055ca2a 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java @@ -1,12 +1,17 @@ package uulm.teamname.marvelous.gamelibrary.gamelogic; +import net.jqwik.api.*; import org.junit.jupiter.api.Test; 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.requests.RequestBuilder; -import uulm.teamname.marvelous.gamelibrary.requests.RequestType; +import uulm.teamname.marvelous.gamelibrary.events.EventBuilder; +import uulm.teamname.marvelous.gamelibrary.requests.*; import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*; @@ -39,4 +44,151 @@ class GameLogicTest { @Test void checkWinConditions() { } + +// @Provide("gamestate") +// Arbitrary gamestate() { +// var states = Arbitraries.integers() +// .tuple2() +// .map(x -> new IntVector2(x.get1(), x.get2())) +// .map(GameState::new); +// } + +// @Provide("entityManager") +// Arbitrary entityManager() { +// var managers = Arbitraries.of(EntityManager.class); +// +// } + +// @Provide("entity") +// Arbitrary entity() { +// var entities = Arbitraries.of(Entity.class); +// } + + // Characters are kind of hard, but most prequisites are here + +// @Provide("character") +// Arbitrary character() { +// var characters = Combinators.combine( +// anyStat(), +// Arbitraries.integers() +// ).as(x -> new Character()); +// } + + @Provide("stat") + Arbitrary anyStat() { + var stats = Combinators.combine( + Arbitraries.of(StatType.class), + Arbitraries.integers()) + .as(Stat::new); + return Combinators.combine(stats, Arbitraries.integers().greaterOrEqual(0)) + .as((stat, decrease) -> { + stat.decreaseValue(decrease % (stat.max + 1)); + return stat; + }); + } + + + @Provide("entityIDs") + Arbitrary entityIDs() { + return Combinators.combine( + Arbitraries.of(EntityType.class), + Arbitraries.integers() + ).as((type, id) -> { + EntityID eid; + switch (type) { + case NPC -> eid = new EntityID(type, id % 3); + case P1, P2, InfinityStones -> eid = new EntityID(type, id % 6); + case Rocks -> eid = new EntityID(type, id); + default -> throw new IllegalStateException("Unexpected value: " + type); + } + return eid; + }); + } + + @Provide("positions") + Arbitrary positions() { + return Arbitraries.integers() + .greaterOrEqual(0) + .tuple2() + .map(x -> new IntVector2(x.get1(), x.get2())); + } + + @Provide("requests") + Arbitrary requests() { + return Combinators.combine( + Arbitraries.of(true, false), + gameRequests(), + characterRequests()) + .as((which, gameRequest, characterRequest) -> which ? gameRequest : characterRequest); + } + + @Provide("gameRequests") + Arbitrary gameRequests() { + final var gameRequestTypes = List.of( + RequestType.PauseStopRequest, + RequestType.PauseStartRequest, + RequestType.EndRoundRequest, + RequestType.DisconnectRequest, + RequestType.Req); + + + return Arbitraries.of(RequestType.class) + .filter(gameRequestTypes::contains) + .map(x -> new RequestBuilder(x).buildGameRequest()); + } + + @Provide("characterRequests") + Arbitrary characterRequests() { + + final var characterRequestTypes = List.of( + RequestType.MeleeAttackRequest, + RequestType.RangedAttackRequest, + RequestType.MoveRequest, + RequestType.ExchangeInfinityStoneRequest, + RequestType.UseInfinityStoneRequest); + + var positions = Arbitraries.integers() + .greaterOrEqual(0) + .tuple2() + .map(x -> new IntVector2(x.get1(), x.get2())); + + + var characterIDs = Combinators.combine(Arbitraries.of(true, false) + .map(x -> x ? EntityType.P1 : EntityType.P2), + Arbitraries.integers() + .between(0, 5)) + .as(EntityID::new); + + var rockIDs = Arbitraries.integers() + .greaterOrEqual(0) + .map(x -> new EntityID(EntityType.Rocks, x)); + + var targetIDs = Combinators.combine( + Arbitraries.of(true, false), + characterIDs, + rockIDs) + .as((which, characterID, rockID) -> which ? characterID : rockID); + + var stoneTypes = Arbitraries.of(StoneType.class); + + var values = Arbitraries.integers(); + + return Combinators.combine( + Arbitraries.of(RequestType.class).filter(characterRequestTypes::contains), // types + positions.tuple2(), + characterIDs, + targetIDs, + stoneTypes, + values + ).as((type, pos, characterID, targetID, stoneType, val) -> { + return new RequestBuilder(type) + .withOriginField(pos.get1()) + .withTargetField(pos.get2()) + .withOriginEntity(characterID) + .withTargetEntity(targetID) + .withStoneType(stoneType) + .withValue(val) + .buildCharacterRequest(); + }); + } }