This commit is contained in:
SD 2021-03-31 16:37:25 +05:30
commit 38ab66af2a
19 changed files with 287 additions and 131 deletions

1
.gitignore vendored
View file

@ -31,3 +31,4 @@ logs
*.hprof
generated
.vscode
test

View file

@ -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();
}
}

View file

@ -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;

View file

@ -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<World> 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 extends Pocket> T newPocket(Pocket.PocketBuilder<?, T> 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 extends Pocket> P getPocket(int id, Class<P> clazz) {

View file

@ -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<V extends AbstractPocket<?>> {
public abstract Pocket getReferencedPocket();
// for bypassing the world check in some cases
public Pocket getReferencedPocket(PocketDirectory directory) {
return getReferencedPocket();
}
public RegistryKey<World> getWorld() {
return world;
}

View file

@ -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<IdReferencePocket> {
public static String KEY = "id_reference";
@ -34,7 +35,12 @@ public class IdReferencePocket extends AbstractPocket<IdReferencePocket> {
@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() {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 236 KiB

After

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 236 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View file

@ -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() {
}
}

View file

@ -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<VirtualTarget.VirtualTargetType<?>> registry) {
System.out.println("test1234");
hasCalledRegisterVirtualTargetTypes = true;
}
@Override
public void registerVirtualSingularPocketTypes(Registry<AbstractVirtualPocket.VirtualPocketType<?>> registry) {
hasCalledRegisterVirtualSingularPocketTypes = true;
}
@Override
public void registerModifierTypes(Registry<Modifier.ModifierType<?>> registry) {
hasCalledRegisterModifierTypes = true;
}
@Override
public void registerPocketGeneratorTypes(Registry<PocketGenerator.PocketGeneratorType<?>> registry) {
hasCalledRegisterPocketGeneratorTypes = true;
}
@Override
public void registerAbstractPocketTypes(Registry<AbstractPocket.AbstractPocketType<?>> registry) {
hasCalledRegisterAbstractPocketTypes = true;
}
@Override
public void registerPocketAddonTypes(Registry<PocketAddon.PocketAddonType<?>> registry) {
hasCalledRegisterPocketAddonTypes = true;
}
@Override
public void registerConditionTypes(Registry<Condition.ConditionType<?>> registry) {
hasCalledRegisterConditionTypes= true;
}
@Override
public void postInitialize() {
hasCalledPostInitialize = true;
}
}

View file

@ -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<String, Double> 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<String, Double> empty = new HashMap<>();
}
}

View file

@ -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)));
}

View file

@ -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));
}
}
}

View file

@ -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()));
}

View file

@ -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<String, Double> 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<String, Double> empty = new HashMap<>();
}
}

View file

@ -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
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -7,8 +7,8 @@ import org.dimdev.dimdoors.api.util.math.AbstractMatrixd;
import java.util.function.Supplier;
public class TestUtil {
public static Supplier<String> 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) {