From 27b1f0641e2e88f794bba82fc935afdc7646f6a7 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Mon, 18 Oct 2021 14:57:12 +0200 Subject: [PATCH] Adds some block location tests --- .../stargate/container/BlockLocationTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/test/java/net/knarcraft/stargate/container/BlockLocationTest.java diff --git a/src/test/java/net/knarcraft/stargate/container/BlockLocationTest.java b/src/test/java/net/knarcraft/stargate/container/BlockLocationTest.java new file mode 100644 index 0000000..c3cd916 --- /dev/null +++ b/src/test/java/net/knarcraft/stargate/container/BlockLocationTest.java @@ -0,0 +1,50 @@ +package net.knarcraft.stargate.container; + +import be.seeseemelk.mockbukkit.WorldMock; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class BlockLocationTest { + + @Test + public void makeRelativeBlockLocationTest() { + WorldMock world = new WorldMock(); + BlockLocation startLocation = new BlockLocation(world, 5, 4, 3); + + //Move to some other, different location + BlockLocation relativeLocation = startLocation.makeRelativeBlockLocation(4, 6, 8); + Assertions.assertNotEquals(startLocation, relativeLocation); + + //Move back to make sure we can go back to where we started by going in the opposite direction + BlockLocation sameAsStartLocation = relativeLocation.makeRelativeBlockLocation(-4, -6, -8); + Assertions.assertEquals(startLocation, sameAsStartLocation); + } + + @Test + public void getRelativeLocationTest() { + WorldMock world = new WorldMock(); + BlockLocation startLocation = new BlockLocation(world, 7, 3, 6); + + RelativeBlockVector relativeBlockVector = new RelativeBlockVector(2, 1, 3); + BlockLocation relativeLocation1 = startLocation.getRelativeLocation(relativeBlockVector, 0); + //With yaw = 0, going right goes in the x direction, and distance goes in the z direction, while y is decremented + BlockLocation targetLocation1 = new BlockLocation(world, 9, 2, 9); + Assertions.assertEquals(targetLocation1, relativeLocation1); + + BlockLocation relativeLocation2 = startLocation.getRelativeLocation(relativeBlockVector, 90); + //With yaw = 90, going right goes in the z direction, and distance goes in the -x direction, while y is decremented + BlockLocation targetLocation2 = new BlockLocation(world, 4, 2, 8); + Assertions.assertEquals(targetLocation2, relativeLocation2); + + BlockLocation relativeLocation3 = startLocation.getRelativeLocation(relativeBlockVector, 180); + //With yaw = 180, going right goes in the -x direction, and distance goes in the -z direction, while y is decremented + BlockLocation targetLocation3 = new BlockLocation(world, 5, 2, 3); + Assertions.assertEquals(targetLocation3, relativeLocation3); + + BlockLocation relativeLocation4 = startLocation.getRelativeLocation(relativeBlockVector, 270); + //With yaw = 270, going right goes in the -z direction, and distance goes in the x direction, while y is decremented + BlockLocation targetLocation4 = new BlockLocation(world, 10, 2, 4); + Assertions.assertEquals(targetLocation4, relativeLocation4); + } + +}