Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robotgryphon committed Feb 21, 2024
1 parent c2f15d0 commit fd0a66f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package dev.compactmods.machines.test.data;

import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.JsonOps;
import dev.compactmods.machines.api.Constants;
import dev.compactmods.machines.api.codec.CodecExtensions;
import dev.compactmods.machines.test.TestBatches;
import dev.compactmods.machines.api.room.history.PlayerRoomHistoryEntry;
import net.minecraft.core.UUIDUtil;
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.nbt.ListTag;
Expand All @@ -12,12 +15,30 @@
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.gametest.GameTestHolder;
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate;
import org.jline.terminal.spi.JansiSupport;

import java.util.List;
import java.util.Map;
import java.util.UUID;

@PrefixGameTestTemplate(false)
@GameTestHolder(Constants.MOD_ID)
public class CodecTests {

@GameTest(template = "empty_1x1", batch = TestBatches.CODEC_TESTS)
private static final String BATCH = "CODECS";

@GameTest(template = "empty_1x1", batch = BATCH)
public static void test(final GameTestHelper test) {
final var MAP = Map.of(UUID.randomUUID(), List.of("hello", "world"));

final var result = Codec.unboundedMap(UUIDUtil.STRING_CODEC, Codec.STRING.listOf())
.encodeStart(JsonOps.INSTANCE, MAP)
.resultOrPartial(test::fail);

test.succeed();
}

@GameTest(template = "empty_1x1", batch = BATCH)
public static void canSerializeVector3d(final GameTestHelper test) {
Vec3 expected = new Vec3(1.25d, 2.50d, 3.75d);

Expand All @@ -26,13 +47,13 @@ public static void canSerializeVector3d(final GameTestHelper test) {
.ifPresent(nbt -> {
ListTag list = (ListTag) nbt;

if(expected.x != list.getDouble(0))
if (expected.x != list.getDouble(0))
test.fail("Position x did not match; expected " + expected + " but got " + list);

if(expected.y != list.getDouble(1))
if (expected.y != list.getDouble(1))
test.fail("Position y did not match; expected " + expected + " but got " + list);

if(expected.z != list.getDouble(2))
if (expected.z != list.getDouble(2))
test.fail("Position z did not match; expected " + expected + " but got " + list);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import dev.compactmods.machines.api.Constants;
import dev.compactmods.machines.api.util.BlockSpaceUtil;
import dev.compactmods.machines.machine.BuiltInRoomTemplate;
import dev.compactmods.machines.test.TestBatches;
import dev.compactmods.machines.test.util.TestUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -28,6 +27,8 @@
@GameTestHolder(Constants.MOD_ID)
public class RoomGenerationTests {

public static final String BATCH = "room_generation";

@GameTestGenerator
public static Collection<TestFunction> roomTests() {
List<TestFunction> funcs = new ArrayList<>();
Expand Down Expand Up @@ -59,7 +60,7 @@ private static void makeTemplateTest(GameTestHelper testHelper, RoomTemplate tem
testHelper.succeed();
}

@GameTest(template = "empty_15x15", batch = TestBatches.ROOM_GENERATION)
@GameTest(template = "empty_15x15", batch = BATCH)
public static void checkOffsetsNormalTest(final GameTestHelper testHelper) {
final var logs = LogManager.getLogger();

Expand All @@ -80,7 +81,7 @@ public static void checkOffsetsNormalTest(final GameTestHelper testHelper) {
testHelper.succeed();
}

@GameTest(template = "empty_15x15", batch = TestBatches.ROOM_GENERATION)
@GameTest(template = "empty_15x15", batch = BATCH)
public static void checkRoomGeneratorNormal(final GameTestHelper testHelper) {

AABB localBounds = TestUtil.localBounds(testHelper);
Expand All @@ -94,7 +95,7 @@ public static void checkRoomGeneratorNormal(final GameTestHelper testHelper) {
testHelper.succeed();
}

@GameTest(template = "empty_15x15", batch = TestBatches.ROOM_GENERATION)
@GameTest(template = "empty_15x15", batch = BATCH)
public static void checkRoomGeneratorWeirdShape(final GameTestHelper testHelper) {

AABB localBounds = TestUtil.localBounds(testHelper);
Expand Down

0 comments on commit fd0a66f

Please sign in to comment.