diff --git a/.gitignore b/.gitignore index 8f2792c7..369c58b2 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ logs *.hprof generated .vscode +test diff --git a/build.gradle b/build.gradle index 68568aac..27a7b0fd 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,10 @@ targetCompatibility = 1.8 repositories { mavenCentral() + maven { + url 'https://maven.legacyfabric.net/' + } + maven { name = "Fabric maven" url = "https://maven.fabricmc.net/" @@ -110,7 +114,7 @@ minecraft { dependencies { minecraft "com.mojang:minecraft:21w11a" mappings "net.fabricmc:yarn:21w11a+build.4:v2" - modImplementation "net.fabricmc:fabric-loader:0.11.2" + modImplementation "net.fabricmc:fabric-loader:0.11.3" modImplementation "net.fabricmc.fabric-api:fabric-api:0.32.4+1.17" includeCompile("com.flowpowered", "flow-math", "1.0.3") includeCompile("org.jgrapht", "jgrapht-core", "1.1.0") @@ -152,7 +156,9 @@ dependencies { datagenImplementation sourceSets.main.compileClasspath datagenRuntimeOnly sourceSets.main.runtimeClasspath - testImplementation('org.junit.jupiter:junit-jupiter:5.5.2') + testImplementation('junit:junit:4.13.2') + //testImplementation('net.devtech:PotatoUnit-fabric:1.0.0') + testImplementation('net.devtech:PotatoUnit:1.0.2') } version = computeVersion(project.mod_version) @@ -199,5 +205,14 @@ curseforge { } test { - useJUnitPlatform() + workingDir = file('test') + + systemProperty('fabric.dli.config', file('.gradle/loom-cache/launch.cfg').getAbsolutePath()) + //useJUnitPlatform() +} + +tasks.test.doFirst {Test test -> + if (!test.workingDir.exists()) { + test.workingDir.mkdirs(); + } } diff --git a/src/main/java/org/dimdev/dimdoors/DimensionalDoorsInitializer.java b/src/main/java/org/dimdev/dimdoors/DimensionalDoorsInitializer.java index 7c70f71f..5ba2fe4a 100644 --- a/src/main/java/org/dimdev/dimdoors/DimensionalDoorsInitializer.java +++ b/src/main/java/org/dimdev/dimdoors/DimensionalDoorsInitializer.java @@ -57,7 +57,6 @@ import net.fabricmc.fabric.api.event.player.UseBlockCallback; import net.fabricmc.fabric.api.event.player.UseItemCallback; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.fabricmc.fabric.api.resource.ResourceManagerHelper; -import net.fabricmc.fabric.api.resource.ResourcePackActivationType; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; diff --git a/src/main/java/org/dimdev/dimdoors/world/pocket/PocketDirectory.java b/src/main/java/org/dimdev/dimdoors/world/pocket/PocketDirectory.java index 0f4d3ee3..36e65efd 100644 --- a/src/main/java/org/dimdev/dimdoors/world/pocket/PocketDirectory.java +++ b/src/main/java/org/dimdev/dimdoors/world/pocket/PocketDirectory.java @@ -21,6 +21,7 @@ import net.minecraft.world.World; import org.dimdev.dimdoors.world.pocket.type.AbstractPocket; import org.dimdev.dimdoors.world.pocket.type.IdReferencePocket; import org.dimdev.dimdoors.world.pocket.type.Pocket; +import org.jetbrains.annotations.TestOnly; public class PocketDirectory { int gridSize; // Determines how much pockets in their dimension are spaced @@ -37,6 +38,14 @@ public class PocketDirectory { this.pockets = new HashMap<>(); } + @TestOnly + public PocketDirectory(RegistryKey worldKey, int gridSize) { + this.gridSize = gridSize; + this.worldKey = worldKey; + this.nextIDMap = new TreeMap<>(); + this.pockets = new HashMap<>(); + } + public static PocketDirectory readFromNbt(String id, CompoundTag tag) { PocketDirectory directory = new PocketDirectory(RegistryKey.of(Registry.DIMENSION, new Identifier(id))); // no need to parallelize @@ -81,8 +90,8 @@ public class PocketDirectory { */ public T newPocket(Pocket.PocketBuilder builder) { Vec3i size = builder.getExpectedSize(); - int longest = Math.max(size.getX(), size.getZ()); - longest = (longest / (gridSize * 16)) + 1; + int longest = Math.max(Math.max(size.getX(), size.getZ()), 1); + longest = (Math.floorDiv(longest - 1, gridSize * 16)) + 1; int base3Size = 1; while (longest > base3Size) { @@ -149,7 +158,7 @@ public class PocketDirectory { */ public Pocket getPocket(int id) { AbstractPocket pocket = this.pockets.get(id); - return pocket == null ? null : pocket.getReferencedPocket(); + return pocket == null ? null : pocket.getReferencedPocket(this); } public

P getPocket(int id, Class

clazz) { diff --git a/src/main/java/org/dimdev/dimdoors/world/pocket/type/AbstractPocket.java b/src/main/java/org/dimdev/dimdoors/world/pocket/type/AbstractPocket.java index 9b8c6ec8..38d3cfb0 100644 --- a/src/main/java/org/dimdev/dimdoors/world/pocket/type/AbstractPocket.java +++ b/src/main/java/org/dimdev/dimdoors/world/pocket/type/AbstractPocket.java @@ -11,6 +11,7 @@ import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.RegistryKey; import net.minecraft.util.registry.SimpleRegistry; import net.minecraft.world.World; +import org.dimdev.dimdoors.world.pocket.PocketDirectory; import java.util.Map; import java.util.function.Supplier; @@ -72,6 +73,11 @@ public abstract class AbstractPocket> { public abstract Pocket getReferencedPocket(); + // for bypassing the world check in some cases + public Pocket getReferencedPocket(PocketDirectory directory) { + return getReferencedPocket(); + } + public RegistryKey getWorld() { return world; } diff --git a/src/main/java/org/dimdev/dimdoors/world/pocket/type/IdReferencePocket.java b/src/main/java/org/dimdev/dimdoors/world/pocket/type/IdReferencePocket.java index 2dbae2a7..c6c55b29 100644 --- a/src/main/java/org/dimdev/dimdoors/world/pocket/type/IdReferencePocket.java +++ b/src/main/java/org/dimdev/dimdoors/world/pocket/type/IdReferencePocket.java @@ -3,6 +3,7 @@ package org.dimdev.dimdoors.world.pocket.type; import net.fabricmc.fabric.api.util.NbtType; import net.minecraft.nbt.CompoundTag; import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry; +import org.dimdev.dimdoors.world.pocket.PocketDirectory; public class IdReferencePocket extends AbstractPocket { public static String KEY = "id_reference"; @@ -34,7 +35,12 @@ public class IdReferencePocket extends AbstractPocket { @Override public Pocket getReferencedPocket() { - return DimensionalRegistry.getPocketDirectory(getWorld()).getPocket(referencedId); + return getReferencedPocket(DimensionalRegistry.getPocketDirectory(getWorld())); + } + + @Override + public Pocket getReferencedPocket(PocketDirectory directory) { + return directory.getPocket(referencedId); } public static IdReferencePocketBuilder builder() { diff --git a/src/main/resources/resourcepacks/classic/pack.png b/src/main/resources/resourcepacks/classic/pack.png index 51078db7..57240fa9 100644 Binary files a/src/main/resources/resourcepacks/classic/pack.png and b/src/main/resources/resourcepacks/classic/pack.png differ diff --git a/src/main/resources/resourcepacks/default/pack.png b/src/main/resources/resourcepacks/default/pack.png index 51078db7..eed2b478 100644 Binary files a/src/main/resources/resourcepacks/default/pack.png and b/src/main/resources/resourcepacks/default/pack.png differ diff --git a/src/test/java/org/dimdev/dimdoors/MiscellaneousTest.java b/src/test/java/org/dimdev/dimdoors/MiscellaneousTest.java index c696c8b8..0dbd0577 100644 --- a/src/test/java/org/dimdev/dimdoors/MiscellaneousTest.java +++ b/src/test/java/org/dimdev/dimdoors/MiscellaneousTest.java @@ -1,9 +1,9 @@ package org.dimdev.dimdoors; -import org.junit.jupiter.api.Test; +import org.junit.Test; public class MiscellaneousTest { @Test - void runSomeTestStuff() { + public void runSomeTestStuff() { } } diff --git a/src/test/java/org/dimdev/dimdoors/api/DimensionalDoorsApiTest.java b/src/test/java/org/dimdev/dimdoors/api/DimensionalDoorsApiTest.java new file mode 100644 index 00000000..fab16d22 --- /dev/null +++ b/src/test/java/org/dimdev/dimdoors/api/DimensionalDoorsApiTest.java @@ -0,0 +1,90 @@ +package org.dimdev.dimdoors.api; + +import net.fabricmc.api.ModInitializer; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.Bootstrap; +import net.minecraft.util.registry.Registry; +import org.dimdev.dimdoors.DimensionalDoorsInitializer; +import org.dimdev.dimdoors.block.door.data.condition.Condition; +import org.dimdev.dimdoors.pockets.generator.PocketGenerator; +import org.dimdev.dimdoors.pockets.modifier.Modifier; +import org.dimdev.dimdoors.pockets.virtual.AbstractVirtualPocket; +import org.dimdev.dimdoors.rift.targets.VirtualTarget; +import org.dimdev.dimdoors.world.pocket.type.AbstractPocket; +import org.dimdev.dimdoors.world.pocket.type.addon.PocketAddon; +import org.dimdev.test.ServerTestRunner; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +@RunWith(ServerTestRunner.class) +public class DimensionalDoorsApiTest implements DimensionalDoorsApi { + private static boolean hasCalledRegisterVirtualTargetTypes = false; + private static boolean hasCalledRegisterVirtualSingularPocketTypes = false; + private static boolean hasCalledRegisterModifierTypes = false; + private static boolean hasCalledRegisterPocketGeneratorTypes = false; + private static boolean hasCalledRegisterAbstractPocketTypes = false; + private static boolean hasCalledRegisterPocketAddonTypes = false; + private static boolean hasCalledRegisterConditionTypes = false; + private static boolean hasCalledPostInitialize = false; + + @Test + public void apiTest() { + Bootstrap.initialize(); + FabricLoader.getInstance().getEntrypoints("main", ModInitializer.class).stream() + .filter(DimensionalDoorsInitializer.class::isInstance) + .map(DimensionalDoorsInitializer.class::cast) + .forEach(DimensionalDoorsInitializer::onInitialize); + + assertTrue(hasCalledRegisterVirtualTargetTypes); + assertTrue(hasCalledRegisterVirtualSingularPocketTypes); + assertTrue(hasCalledRegisterModifierTypes); + assertTrue(hasCalledRegisterPocketGeneratorTypes); + assertTrue(hasCalledRegisterAbstractPocketTypes); + assertTrue(hasCalledRegisterPocketAddonTypes); + assertTrue(hasCalledRegisterConditionTypes); + assertTrue(hasCalledPostInitialize); + } + + @Override + public void registerVirtualTargetTypes(Registry> registry) { + System.out.println("test1234"); + hasCalledRegisterVirtualTargetTypes = true; + } + + @Override + public void registerVirtualSingularPocketTypes(Registry> registry) { + hasCalledRegisterVirtualSingularPocketTypes = true; + } + + @Override + public void registerModifierTypes(Registry> registry) { + hasCalledRegisterModifierTypes = true; + } + + @Override + public void registerPocketGeneratorTypes(Registry> registry) { + hasCalledRegisterPocketGeneratorTypes = true; + } + + @Override + public void registerAbstractPocketTypes(Registry> registry) { + hasCalledRegisterAbstractPocketTypes = true; + } + + @Override + public void registerPocketAddonTypes(Registry> registry) { + hasCalledRegisterPocketAddonTypes = true; + } + + @Override + public void registerConditionTypes(Registry> registry) { + hasCalledRegisterConditionTypes= true; + } + + @Override + public void postInitialize() { + hasCalledPostInitialize = true; + } +} diff --git a/src/test/java/org/dimdev/dimdoors/api/util/math/EquationTest.java b/src/test/java/org/dimdev/dimdoors/api/util/math/EquationTest.java new file mode 100644 index 00000000..8ce6d9e1 --- /dev/null +++ b/src/test/java/org/dimdev/dimdoors/api/util/math/EquationTest.java @@ -0,0 +1,52 @@ +package org.dimdev.dimdoors.api.util.math; + +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + +public class EquationTest { + + @Test + public void parseAndApply() throws Equation.EquationParseException { + Map empty = new HashMap<>(); + double expected; + String equation; + + assertThrows(Equation.EquationParseException.class, () -> Equation.parse(".")); + + expected = 15d; + equation = Double.toString(expected); + assertEquals(expected, Equation.parse(equation).apply(empty), 0); + + + expected = 4d; + equation = "2 + 2"; + assertEquals(expected, Equation.parse(equation).apply(empty), 0); + + + expected = 1; + equation = "1 ? 1 : 0"; + assertEquals(expected, Equation.parse(equation).apply(empty), 0); + + expected = 0; + equation = "0 ? 1 : 0"; + assertEquals(expected, Equation.parse(equation).apply(empty), 0); + + expected = 1; + equation = (Math.random() + 1d) + "? 1 : 0"; + assertEquals(expected, Equation.parse(equation).apply(empty), 0); + + expected = 1; + equation = (Math.random() - 1d) + "? 1 : 0"; + assertEquals(expected, Equation.parse(equation).apply(empty), 0); + } + + public void parseAndAsBoolean() throws Equation.EquationParseException { + Map empty = new HashMap<>(); + + + } +} diff --git a/src/test/java/org/dimdev/dimdoors/util/math/GridUtilTest.java b/src/test/java/org/dimdev/dimdoors/api/util/math/GridUtilTest.java similarity index 65% rename from src/test/java/org/dimdev/dimdoors/util/math/GridUtilTest.java rename to src/test/java/org/dimdev/dimdoors/api/util/math/GridUtilTest.java index 8af4c393..8a4767fe 100644 --- a/src/test/java/org/dimdev/dimdoors/util/math/GridUtilTest.java +++ b/src/test/java/org/dimdev/dimdoors/api/util/math/GridUtilTest.java @@ -1,14 +1,13 @@ -package org.dimdev.dimdoors.util.math; +package org.dimdev.dimdoors.api.util.math; -import org.dimdev.dimdoors.api.util.math.GridUtil; -import org.junit.jupiter.api.Test; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.*; -class GridUtilTest { +public class GridUtilTest { @Test - void idToGridPos() { + public void idToGridPos() { GridUtil.GridPos pos; // I scribbled the grid down so I could figure out these tests, lmao pos = GridUtil.idToGridPos(86); @@ -20,7 +19,7 @@ class GridUtilTest { } @Test - void conversionConsistencyTest() { + public void conversionConsistencyTest() { for (int i = 0; i < 1000; i++) { assertEquals(i, GridUtil.gridPosToID(GridUtil.idToGridPos(i))); } diff --git a/src/test/java/org/dimdev/dimdoors/util/math/MathUtilTest.java b/src/test/java/org/dimdev/dimdoors/api/util/math/MathUtilTest.java similarity index 55% rename from src/test/java/org/dimdev/dimdoors/util/math/MathUtilTest.java rename to src/test/java/org/dimdev/dimdoors/api/util/math/MathUtilTest.java index c8ddc062..f4f2b9ac 100644 --- a/src/test/java/org/dimdev/dimdoors/util/math/MathUtilTest.java +++ b/src/test/java/org/dimdev/dimdoors/api/util/math/MathUtilTest.java @@ -1,47 +1,46 @@ -package org.dimdev.dimdoors.util.math; +package org.dimdev.dimdoors.api.util.math; import net.minecraft.util.math.Direction; import net.minecraft.util.math.EulerAngle; import net.minecraft.util.math.Vec3d; -import org.dimdev.dimdoors.api.util.math.MathUtil; import org.dimdev.test.TestUtil; -import org.junit.jupiter.api.Test; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.*; -class MathUtilTest { +public class MathUtilTest { @Test - void eulerAngle() { + public void eulerAngle() { EulerAngle expected = new EulerAngle(0, 0, 0); Vec3d direction = new Vec3d(0, 0, 1); Vec3d upwards = new Vec3d(0, 1, 0); EulerAngle angle = MathUtil.eulerAngle(direction, upwards); - assertTrue(TestUtil.closeEnough(expected, angle), TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle))); + assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle)); expected = new EulerAngle(-90, 0, 0); direction = new Vec3d(0, 1, 0); upwards = new Vec3d(0, 0, -1); angle = MathUtil.eulerAngle(direction, upwards); - assertTrue(TestUtil.closeEnough(expected, angle), TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle))); + assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle)); expected = new EulerAngle(0, -45, 0); direction = new Vec3d(Math.cos(Math.PI / 2), 0, Math.cos(Math.PI / 2)); upwards = new Vec3d(0, 1, 0); angle = MathUtil.eulerAngle(direction, upwards); - assertTrue(TestUtil.closeEnough(expected, angle), TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle))); + assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle)); } @Test - void directionEulerAngle() { + public void directionEulerAngle() { for (Direction direction : Direction.values()) { EulerAngle expected = MathUtil.directionEulerAngle(direction); Vec3d dir = Vec3d.of(direction.getVector()); EulerAngle angle = new EulerAngle(MathUtil.pitch(dir), MathUtil.yaw(dir), 0); - assertTrue(TestUtil.closeEnough(expected, angle), TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle))); + assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle)); } } } diff --git a/src/test/java/org/dimdev/dimdoors/util/math/TransformationMatrix3dTest.java b/src/test/java/org/dimdev/dimdoors/api/util/math/TransformationMatrix3dTest.java similarity index 63% rename from src/test/java/org/dimdev/dimdoors/util/math/TransformationMatrix3dTest.java rename to src/test/java/org/dimdev/dimdoors/api/util/math/TransformationMatrix3dTest.java index 5f137b8c..7be2739b 100644 --- a/src/test/java/org/dimdev/dimdoors/util/math/TransformationMatrix3dTest.java +++ b/src/test/java/org/dimdev/dimdoors/api/util/math/TransformationMatrix3dTest.java @@ -1,18 +1,17 @@ -package org.dimdev.dimdoors.util.math; +package org.dimdev.dimdoors.api.util.math; import net.minecraft.util.math.EulerAngle; import net.minecraft.util.math.Vec3d; -import org.dimdev.dimdoors.api.util.math.TransformationMatrix3d; import org.dimdev.test.TestUtil; -import org.junit.jupiter.api.Test; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.*; -class TransformationMatrix3dTest { +public class TransformationMatrix3dTest { @Test - void identity() { + public void identity() { double[][] matrix = new double[4][4]; matrix[0] = new double[]{1, 0, 0, 0}; matrix[1] = new double[]{0, 1, 0, 0}; @@ -27,7 +26,7 @@ class TransformationMatrix3dTest { } @Test - void transformVec3d() { + public void transformVec3d() { // rotate around Vec3d vector = new Vec3d(1, 0, 0); Vec3d expected; @@ -35,25 +34,25 @@ class TransformationMatrix3dTest { vector = rotate90DegreesY.transform(vector); expected = new Vec3d(0, 0, -1); - assertTrue(TestUtil.closeEnough(expected, vector), TestUtil.expectedActual(expected, vector)); + assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector)); vector = rotate90DegreesY.transform(vector); expected = new Vec3d(-1, 0, 0); - assertTrue(TestUtil.closeEnough(expected, vector), TestUtil.expectedActual(expected, vector)); + assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector)); vector = rotate90DegreesY.transform(vector); expected = new Vec3d(0, 0, 1); - assertTrue(TestUtil.closeEnough(expected, vector), TestUtil.expectedActual(expected, vector)); + assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector)); vector = rotate90DegreesY.transform(vector); expected = new Vec3d(1, 0, 0); - assertTrue(TestUtil.closeEnough(expected, vector), TestUtil.expectedActual(expected, vector)); + assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector)); TransformationMatrix3d rotate45DegreesY = TransformationMatrix3d.builder().rotateY(Math.PI / 4).build(); vector = rotate45DegreesY.transform(vector); expected = new Vec3d(Math.cos(Math.PI/4), 0, -Math.sin(Math.PI/4)); - assertTrue(TestUtil.closeEnough(expected, vector), TestUtil.expectedActual(expected, vector)); + assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector)); double random = Math.random()*2*Math.PI; expected = new Vec3d(Math.cos(random), 0, -Math.sin(random)); @@ -64,12 +63,12 @@ class TransformationMatrix3dTest { .translate(new Vec3d(Math.random()*100, Math.random()*100, Math.random()*100)); vector = builder.buildReverse().transform(builder.build().transform(expected)); - assertTrue(TestUtil.closeEnough(expected, vector), TestUtil.expectedActual(expected, vector)); + assertTrue(TestUtil.expectedActual(expected, vector), TestUtil.closeEnough(expected, vector)); } @Test - void transformEulerAngle() { + public void transformEulerAngle() { EulerAngle expected; EulerAngle angle; @@ -77,54 +76,54 @@ class TransformationMatrix3dTest { expected = new EulerAngle(0, 0, 0); angle = identity.transform(expected); - assertTrue(TestUtil.closeEnough(expected, angle), TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle))); + assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle)); expected = new EulerAngle(90, 0, 0); angle = identity.transform(expected); - assertTrue(TestUtil.closeEnough(expected, angle), TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle))); + assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle)); expected = new EulerAngle(0, 90, 0); angle = identity.transform(expected); - assertTrue(TestUtil.closeEnough(expected, angle), TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle))); + assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle)); expected = new EulerAngle(0, 0, 90); angle = identity.transform(expected); - assertTrue(TestUtil.closeEnough(expected, angle), TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle))); + assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle)); expected = new EulerAngle(90, 90, 90); angle = identity.transform(expected); - assertTrue(TestUtil.closeEnough(expected, angle), TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle))); + assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle)); // randomize EulerAngle expected = new EulerAngle((((float) Math.random()) - 0.5F) * 180, (((float) Math.random()) - 0.5F) * 360, (((float) Math.random()) - 0.5F) * 360); angle = identity.transform(expected); - assertTrue(TestUtil.closeEnough(expected, angle), TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle))); + assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle)); angle = expected; TransformationMatrix3d rotate90DegreesY = TransformationMatrix3d.builder().rotateY(Math.PI / 2).build(); for (int i = 0; i < 4; i++) { angle = rotate90DegreesY.transform(angle); } - assertTrue(TestUtil.closeEnough(expected, angle), TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle))); + assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle)); angle = expected; TransformationMatrix3d rotate90DegreesX = TransformationMatrix3d.builder().rotateX(Math.PI / 2).build(); for (int i = 0; i < 4; i++) { angle = rotate90DegreesX.transform(angle); } - assertTrue(TestUtil.closeEnough(expected, angle), TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle))); + assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle)); angle = expected; TransformationMatrix3d rotate90DegreesZ = TransformationMatrix3d.builder().rotateZ(Math.PI / 2).build(); for (int i = 0; i < 4; i++) { angle = rotate90DegreesZ.transform(angle); } - assertTrue(TestUtil.closeEnough(expected, angle), TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle))); + assertTrue(TestUtil.expectedActual(TestUtil.toString(expected), TestUtil.toString(angle)), TestUtil.closeEnough(expected, angle)); } @Test - void product() { + public void product() { // compare I and I^2 assertEquals(TransformationMatrix3d.identity(), TransformationMatrix3d.identity().product(TransformationMatrix3d.identity())); } diff --git a/src/test/java/org/dimdev/dimdoors/util/math/EquationTest.java b/src/test/java/org/dimdev/dimdoors/util/math/EquationTest.java deleted file mode 100644 index c575ac5a..00000000 --- a/src/test/java/org/dimdev/dimdoors/util/math/EquationTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.dimdev.dimdoors.util.math; - -import org.dimdev.dimdoors.api.util.math.Equation; -import org.junit.jupiter.api.Test; - -import java.util.HashMap; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.*; - -class EquationTest { - - @Test - void parseAndApply() throws Equation.EquationParseException { - Map empty = new HashMap<>(); - double expected; - String equation; - - assertThrows(Equation.EquationParseException.class, () -> Equation.parse(".")); - - expected = 15d; - equation = Double.toString(expected); - assertEquals(expected, Equation.parse(equation).apply(empty)); - - - expected = 4d; - equation = "2 + 2"; - assertEquals(expected, Equation.parse(equation).apply(empty)); - - - expected = 1; - equation = "1 ? 1 : 0"; - assertEquals(expected, Equation.parse(equation).apply(empty)); - - expected = 0; - equation = "0 ? 1 : 0"; - assertEquals(expected, Equation.parse(equation).apply(empty)); - - expected = 1; - equation = (Math.random() + 1d) + "? 1 : 0"; - assertEquals(expected, Equation.parse(equation).apply(empty)); - - expected = 1; - equation = (Math.random() - 1d) + "? 1 : 0"; - assertEquals(expected, Equation.parse(equation).apply(empty)); - } - - void parseAndAsBoolean() throws Equation.EquationParseException { - Map empty = new HashMap<>(); - - - } -} diff --git a/src/test/java/org/dimdev/dimdoors/world/pocket/PocketDirectoryTest.java b/src/test/java/org/dimdev/dimdoors/world/pocket/PocketDirectoryTest.java index 1a3756d1..2c22c125 100644 --- a/src/test/java/org/dimdev/dimdoors/world/pocket/PocketDirectoryTest.java +++ b/src/test/java/org/dimdev/dimdoors/world/pocket/PocketDirectoryTest.java @@ -3,44 +3,46 @@ package org.dimdev.dimdoors.world.pocket; import net.minecraft.util.math.Vec3i; import org.dimdev.dimdoors.world.ModDimensions; import org.dimdev.dimdoors.world.pocket.type.Pocket; -import org.junit.jupiter.api.Test; +import org.dimdev.test.ServerTestRunner; +import org.junit.Test; +import org.junit.runner.RunWith; -import static org.junit.jupiter.api.Assertions.*; - -class PocketDirectoryTest { +import static org.junit.Assert.*; +//@RunWith(ServerTestRunner.class) +public class PocketDirectoryTest { //@Test - void newPocket() { - PocketDirectory directory = null;// new PocketDirectory(ModDimensions.DUNGEON, 512); + public void newPocket() { + PocketDirectory directory = new PocketDirectory(ModDimensions.DUNGEON, 13);// - Pocket.PocketBuilder builder = Pocket.builder().expand(new Vec3i(1, 1, 1)); + Pocket.PocketBuilder builder = Pocket.builder().expand(new Vec3i(16 * directory.getGridSize(), 1, 1)); - assertEquals(0, directory.newPocket(builder).getId()); - assertEquals(1, directory.newPocket(builder).getId()); - assertEquals(2, directory.newPocket(builder).getId()); - assertEquals(3, directory.newPocket(builder).getId()); - assertEquals(4, directory.newPocket(builder).getId()); - assertEquals(5, directory.newPocket(builder).getId()); - assertEquals(6, directory.newPocket(builder).getId()); + assertEquals(0, directory.newPocket(builder).getId()); // from 0 to 0 + assertEquals(1, directory.newPocket(builder).getId()); // from 1 to 1 + assertEquals(2, directory.newPocket(builder).getId()); // from 2 to 2 + assertEquals(3, directory.newPocket(builder).getId()); // from 3 to 3 + assertEquals(4, directory.newPocket(builder).getId()); // from 4 to 4 + assertEquals(5, directory.newPocket(builder).getId()); // from 5 to 5 + assertEquals(6, directory.newPocket(builder).getId()); // from 6 to 6 - builder = Pocket.builder().expand(new Vec3i(directory.getGridSize() + 1, directory.getGridSize() + 1, directory.getGridSize() + 1)); - assertEquals(9, directory.newPocket(builder).getId()); - assertEquals(18, directory.newPocket(builder).getId()); + builder = Pocket.builder().expand(new Vec3i(16 * directory.getGridSize() + 1, 16 * directory.getGridSize() + 1, 16 * directory.getGridSize() + 1)); + assertEquals(17, directory.newPocket(builder).getId()); // from 9 to 17 + assertEquals(26, directory.newPocket(builder).getId()); // from 18 to 26 - builder = Pocket.builder().expand(new Vec3i(3 * directory.getGridSize() + 1, 3 * directory.getGridSize() + 1, 3 * directory.getGridSize() + 1)); - assertEquals(81, directory.newPocket(builder).getId()); + builder = Pocket.builder().expand(new Vec3i(3 * 16 * directory.getGridSize() + 1, 3 * 16 * directory.getGridSize() + 1, 3 * 16 * directory.getGridSize() + 1)); + assertEquals(161, directory.newPocket(builder).getId()); // from 81 to 161 - Pocket.builder().expand(new Vec3i(directory.getGridSize() + 1, directory.getGridSize() + 1, directory.getGridSize() + 1)); - assertEquals(27, directory.newPocket(builder).getId()); + builder = Pocket.builder().expand(new Vec3i(16 * directory.getGridSize() + 1, 16 * directory.getGridSize() + 1, 16 * directory.getGridSize() + 1)); + assertEquals(35, directory.newPocket(builder).getId()); // from 27 to 35 builder = Pocket.builder().expand(new Vec3i(1, 1, 1)); - assertEquals(7, directory.newPocket(builder).getId()); - assertEquals(8, directory.newPocket(builder).getId()); - assertEquals(36, directory.newPocket(builder).getId()); + assertEquals(7, directory.newPocket(builder).getId()); // from 7 to 7 + assertEquals(8, directory.newPocket(builder).getId()); // from 8 to 8 + assertEquals(36, directory.newPocket(builder).getId()); // from 36 to 36 } } diff --git a/src/test/java/org/dimdev/test/ClientTestRunner.java b/src/test/java/org/dimdev/test/ClientTestRunner.java new file mode 100644 index 00000000..5e10569c --- /dev/null +++ b/src/test/java/org/dimdev/test/ClientTestRunner.java @@ -0,0 +1,16 @@ +package org.dimdev.test; + +import net.devtech.potatounit.TestRunner; +import net.fabricmc.api.EnvType; +import org.junit.runners.model.InitializationError; + +public class ClientTestRunner extends TestRunner { + public ClientTestRunner(Class testClass) throws InitializationError, ReflectiveOperationException { + super(hackyOrderMethod(testClass), EnvType.CLIENT); + } + + private static Class hackyOrderMethod(Class testClass) { + System.setProperty("fabric.dli.main", "net.fabricmc.loader.launch.knot.KnotClient"); + return testClass; + } +} diff --git a/src/test/java/org/dimdev/test/ServerTestRunner.java b/src/test/java/org/dimdev/test/ServerTestRunner.java new file mode 100644 index 00000000..00121836 --- /dev/null +++ b/src/test/java/org/dimdev/test/ServerTestRunner.java @@ -0,0 +1,16 @@ +package org.dimdev.test; + +import net.devtech.potatounit.TestRunner; +import net.fabricmc.api.EnvType; +import org.junit.runners.model.InitializationError; + +public class ServerTestRunner extends TestRunner { + public ServerTestRunner(Class testClass) throws InitializationError, ReflectiveOperationException { + super(hackyOrderMethod(testClass), EnvType.SERVER); + } + + private static Class hackyOrderMethod(Class testClass) { + System.setProperty("fabric.dli.main", "net.fabricmc.loader.launch.knot.KnotServer"); + return testClass; + } +} diff --git a/src/test/java/org/dimdev/test/TestUtil.java b/src/test/java/org/dimdev/test/TestUtil.java index 17ac5e0e..73835c1b 100644 --- a/src/test/java/org/dimdev/test/TestUtil.java +++ b/src/test/java/org/dimdev/test/TestUtil.java @@ -7,8 +7,8 @@ import org.dimdev.dimdoors.api.util.math.AbstractMatrixd; import java.util.function.Supplier; public class TestUtil { - public static Supplier expectedActual(Object expected,Object actual) { - return () -> "\nexpected:\n" + expected + "\nactual:\n" + actual + "\n"; + public static String expectedActual(Object expected,Object actual) { + return "\nexpected:\n" + expected + "\nactual:\n" + actual + "\n"; } public static boolean closeEnough(Vec3d expected, Vec3d actual) {