From 8fa21f0ec183da2e626cbe0ad2f95226308c9b9a Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 19 Jun 2024 13:39:56 +0100 Subject: add wishing compass solver --- .../skyblock/dwarven/WishingCompassSolverTest.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/test/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolverTest.java (limited to 'src/test/java/de/hysky/skyblocker/skyblock') diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolverTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolverTest.java new file mode 100644 index 00000000..c5a6ba19 --- /dev/null +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolverTest.java @@ -0,0 +1,41 @@ +package de.hysky.skyblocker.skyblock.dwarven; + +import net.minecraft.util.math.Vec3d; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class WishingCompassSolverTest { + + @Test + void test2dSolve() { + Vec3d startPosOne = new Vec3d(100, 0, 0); + Vec3d startPosTwo = new Vec3d(0, 0, 100); + Vec3d directionOne = new Vec3d(-1, 0, 0); + Vec3d directionTwo = new Vec3d(0, 0, -1); + Assertions.assertEquals(WishingCompassSolver.solve(startPosOne, startPosTwo, directionOne, directionTwo), new Vec3d(0, 0, 0)); + + startPosOne = new Vec3d(100, 0, 100); + startPosTwo = new Vec3d(50, 0, 100); + directionOne = new Vec3d(-1, 0, -1); + directionTwo = new Vec3d(-0.5, 0, -1); + Assertions.assertEquals(WishingCompassSolver.solve(startPosOne, startPosTwo, directionOne, directionTwo), new Vec3d(0, 0, 0)); + } + + @Test + void test3dSolve() { + Vec3d startPosOne = new Vec3d(100, 100, 0); + Vec3d startPosTwo = new Vec3d(0, -100, 100); + Vec3d directionOne = new Vec3d(-1, -1, 0); + Vec3d directionTwo = new Vec3d(0, 1, -1); + Assertions.assertEquals(WishingCompassSolver.solve(startPosOne, startPosTwo, directionOne, directionTwo), new Vec3d(0, 0, 0)); + } + + @Test + void testParallelSolve() { + Vec3d startPosOne = new Vec3d(100, 0, 0); + Vec3d startPosTwo = new Vec3d(50, 0, 0); + Vec3d directionOne = new Vec3d(-1, 0, 0); + Vec3d directionTwo = new Vec3d(-1, 0, 0); + Assertions.assertNull(WishingCompassSolver.solve(startPosOne, startPosTwo, directionOne, directionTwo)); + } +} -- cgit From 586ef04b4f2b8118c481349dbcd219204d96318a Mon Sep 17 00:00:00 2001 From: olim Date: Thu, 20 Jun 2024 22:25:37 +0100 Subject: fix broken tests fix testing for translated string --- .../skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/test/java/de/hysky/skyblocker/skyblock') diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java index 4ce61880..5d555742 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java @@ -26,7 +26,7 @@ public class CrystalsLocationManagerTest { @Test void testSetLocationMessage() { - Assertions.assertEquals(CrystalsLocationsManager.getSetLocationMessage("Jungle Temple", new BlockPos(10, 11, 12)).getString(), Constants.PREFIX.get().getString() + "Added waypoint for Jungle Temple at : 10 11 12."); - Assertions.assertEquals(CrystalsLocationsManager.getSetLocationMessage("Fairy Grotto", new BlockPos(0, 0, 0)).getString(), Constants.PREFIX.get().getString() + "Added waypoint for Fairy Grotto at : 0 0 0."); + Assertions.assertEquals(CrystalsLocationsManager.getSetLocationMessage("Jungle Temple", new BlockPos(10, 11, 12)).getString(), Constants.PREFIX.get().getString() + "skyblocker.config.mining.crystalsWaypoints.addedWaypointJungle Temple skyblocker.config.mining.crystalsWaypoints.addedWaypoint.at : 10 11 12."); + Assertions.assertEquals(CrystalsLocationsManager.getSetLocationMessage("Fairy Grotto", new BlockPos(0, 0, 0)).getString(), Constants.PREFIX.get().getString() + "skyblocker.config.mining.crystalsWaypoints.addedWaypointFairy Grotto skyblocker.config.mining.crystalsWaypoints.addedWaypoint.at : 0 0 0."); } } -- cgit From 50827a487b06cab710ed6c29e48c3b8fe88ad881 Mon Sep 17 00:00:00 2001 From: olim Date: Fri, 21 Jun 2024 15:18:04 +0100 Subject: fix tests tests can not point to 0 as that now returns null because that is the same as parallel. but as 0 is not in ch it should not actually be a problem --- .../skyblock/dwarven/WishingCompassSolverTest.java | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/test/java/de/hysky/skyblocker/skyblock') diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolverTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolverTest.java index c5a6ba19..8da811a5 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolverTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolverTest.java @@ -4,30 +4,32 @@ import net.minecraft.util.math.Vec3d; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.Objects; + public class WishingCompassSolverTest { @Test void test2dSolve() { - Vec3d startPosOne = new Vec3d(100, 0, 0); - Vec3d startPosTwo = new Vec3d(0, 0, 100); + Vec3d startPosOne = new Vec3d(100, 1, 0); + Vec3d startPosTwo = new Vec3d(0, 1, 100); Vec3d directionOne = new Vec3d(-1, 0, 0); Vec3d directionTwo = new Vec3d(0, 0, -1); - Assertions.assertEquals(WishingCompassSolver.solve(startPosOne, startPosTwo, directionOne, directionTwo), new Vec3d(0, 0, 0)); + Assertions.assertEquals(WishingCompassSolver.solve(startPosOne, startPosTwo, directionOne, directionTwo), new Vec3d(0, 1, 0)); - startPosOne = new Vec3d(100, 0, 100); - startPosTwo = new Vec3d(50, 0, 100); + startPosOne = new Vec3d(100, 1, 100); + startPosTwo = new Vec3d(50, 1, 100); directionOne = new Vec3d(-1, 0, -1); directionTwo = new Vec3d(-0.5, 0, -1); - Assertions.assertEquals(WishingCompassSolver.solve(startPosOne, startPosTwo, directionOne, directionTwo), new Vec3d(0, 0, 0)); + Assertions.assertEquals(WishingCompassSolver.solve(startPosOne, startPosTwo, directionOne, directionTwo), new Vec3d(0, 1, 0)); } @Test void test3dSolve() { - Vec3d startPosOne = new Vec3d(100, 100, 0); - Vec3d startPosTwo = new Vec3d(0, -100, 100); + Vec3d startPosOne = new Vec3d(100, 200, 0); + Vec3d startPosTwo = new Vec3d(0, 0, 100); Vec3d directionOne = new Vec3d(-1, -1, 0); Vec3d directionTwo = new Vec3d(0, 1, -1); - Assertions.assertEquals(WishingCompassSolver.solve(startPosOne, startPosTwo, directionOne, directionTwo), new Vec3d(0, 0, 0)); + Assertions.assertTrue(Objects.requireNonNull(WishingCompassSolver.solve(startPosOne, startPosTwo, directionOne, directionTwo)).distanceTo(new Vec3d(0, 100, 0))<0.1); } @Test -- cgit From dfe5c28dd6a50fc88973e95e60bcfd418daa1e90 Mon Sep 17 00:00:00 2001 From: Rime <81419447+Emirlol@users.noreply.github.com> Date: Sat, 13 Jul 2024 02:21:47 +0300 Subject: Fix regex and add tests for the regex --- .../skyblock/dwarven/CrystalsLocationsManager.java | 4 ++-- .../dwarven/CrystalsLocationManagerTest.java | 26 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'src/test/java/de/hysky/skyblocker/skyblock') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java index 2a21776e..0e3b4d59 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -53,7 +53,8 @@ public class CrystalsLocationsManager { * A look-up table to convert between location names and waypoint in the {@link MiningLocationLabel.CrystalHollowsLocationsCategory} values. */ private static final Map WAYPOINT_LOCATIONS = Arrays.stream(MiningLocationLabel.CrystalHollowsLocationsCategory.values()).collect(Collectors.toMap(MiningLocationLabel.CrystalHollowsLocationsCategory::getName, Function.identity())); - private static final Pattern TEXT_CWORDS_PATTERN = Pattern.compile("([0-9][0-9][0-9])\\D*([0-9][0-9][0-9]?)\\D*([0-9][0-9][0-9])"); + //Package-private for testing + static final Pattern TEXT_CWORDS_PATTERN = Pattern.compile("\\Dx?(\\d{3})(?=[, ]),? ?y?(\\d{2,3})(?=[, ]),? ?z?(\\d{3})\\D?(?!\\d)"); private static final int REMOVE_UNKNOWN_DISTANCE = 50; protected static Map activeWaypoints = new HashMap<>(); @@ -72,7 +73,6 @@ public class CrystalsLocationsManager { } private static void extractLocationFromMessage(Text message, Boolean overlay) { - if (!SkyblockerConfigManager.get().mining.crystalsWaypoints.findInChat || !Utils.isInCrystalHollows() || overlay) { return; } diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java index 5d555742..11331fae 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java @@ -6,7 +6,31 @@ import org.junit.jupiter.api.Test; import de.hysky.skyblocker.utils.Constants; -public class CrystalsLocationManagerTest { +class CrystalsLocationManagerTest { + boolean matches(String text) { + return CrystalsLocationsManager.TEXT_CWORDS_PATTERN.matcher(text).find(); + } + + @Test + void testRegex() { + Assertions.assertTrue(matches("x123 y12 z123")); + Assertions.assertTrue(matches("x123, y12, z123")); + Assertions.assertTrue(matches("Player: 123 12 123")); //This and the ones below fail when specified in the same format as those above, as the regex check assumes that the message is sent somewhere in a message and that it isn't the whole message + Assertions.assertTrue(matches("Player: 123 123 123")); + Assertions.assertTrue(matches("Player: 123, 12, 123")); + Assertions.assertTrue(matches("Player: 123, 123, 123")); + Assertions.assertTrue(matches("Player: 123,12,123")); + Assertions.assertTrue(matches("Player: 123,123,123")); + + Assertions.assertFalse(matches("Player: 123 1234 123")); + Assertions.assertFalse(matches("Player: 1234 12 123")); + Assertions.assertFalse(matches("Player: 123 12 1234")); + Assertions.assertFalse(matches("Player: 12 12 123")); + Assertions.assertFalse(matches("Player: 123 1 123")); + Assertions.assertFalse(matches("Player: 123 12 12")); + Assertions.assertFalse(matches("Player: 12312123")); + Assertions.assertFalse(matches("Player: 123123123")); + } @Test void testLocationInCrystals() { -- cgit From 33c944a9ce9966374de93bab32b581d19e97cb81 Mon Sep 17 00:00:00 2001 From: Rime <81419447+Emirlol@users.noreply.github.com> Date: Sat, 13 Jul 2024 02:23:17 +0300 Subject: Simplify test case to not need long comment --- .../skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/test/java/de/hysky/skyblocker/skyblock') diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java index 11331fae..10c55faf 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java @@ -13,9 +13,9 @@ class CrystalsLocationManagerTest { @Test void testRegex() { - Assertions.assertTrue(matches("x123 y12 z123")); - Assertions.assertTrue(matches("x123, y12, z123")); - Assertions.assertTrue(matches("Player: 123 12 123")); //This and the ones below fail when specified in the same format as those above, as the regex check assumes that the message is sent somewhere in a message and that it isn't the whole message + Assertions.assertTrue(matches("Player: x123 y12 z123")); + Assertions.assertTrue(matches("Player: x123, y12, z123")); + Assertions.assertTrue(matches("Player: 123 12 123")); Assertions.assertTrue(matches("Player: 123 123 123")); Assertions.assertTrue(matches("Player: 123, 12, 123")); Assertions.assertTrue(matches("Player: 123, 123, 123")); -- cgit From d3cb3448f98c024beca3334e39eeb46fd1079e02 Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Wed, 24 Jul 2024 00:09:50 +0800 Subject: Fix test and daily mojank --- .../skyblocker/skyblock/dwarven/CrystalsLocationsManager.java | 6 +++++- .../skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java | 7 +++---- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src/test/java/de/hysky/skyblocker/skyblock') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java index 8ccafed2..22e494ab 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -188,7 +188,11 @@ public class CrystalsLocationsManager { protected static Text getSetLocationMessage(String location, BlockPos blockPos) { int locationColor = WAYPOINT_LOCATIONS.get(location).getColor(); - return Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.addedWaypoint", Text.literal(location).withColor(locationColor), blockPos.getX(), blockPos.getY(), blockPos.getZ())); + + // Minecraft transforms all arguments (`%s`, `%d`, whatever) to `%$1s` DURING LOADING in `Language#load(InputStream, BiConsumer)` for some unknown reason. + // And then `TranslatableTextContent#forEachPart` only accepts `%s` for some other unknown reason. + // So that's why the arguments are all `%s`. Wtf mojang????????? + return Constants.PREFIX.get().append(Text.translatableWithFallback("skyblocker.config.mining.crystalsWaypoints.addedWaypoint", "Added waypoint for '%s' at %s %s %s.", Text.literal(location).withColor(locationColor), blockPos.getX(), blockPos.getY(), blockPos.getZ())); } /** diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java index 10c55faf..aac4a641 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java @@ -1,11 +1,10 @@ package de.hysky.skyblocker.skyblock.dwarven; +import de.hysky.skyblocker.utils.Constants; import net.minecraft.util.math.BlockPos; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import de.hysky.skyblocker.utils.Constants; - class CrystalsLocationManagerTest { boolean matches(String text) { return CrystalsLocationsManager.TEXT_CWORDS_PATTERN.matcher(text).find(); @@ -50,7 +49,7 @@ class CrystalsLocationManagerTest { @Test void testSetLocationMessage() { - Assertions.assertEquals(CrystalsLocationsManager.getSetLocationMessage("Jungle Temple", new BlockPos(10, 11, 12)).getString(), Constants.PREFIX.get().getString() + "skyblocker.config.mining.crystalsWaypoints.addedWaypointJungle Temple skyblocker.config.mining.crystalsWaypoints.addedWaypoint.at : 10 11 12."); - Assertions.assertEquals(CrystalsLocationsManager.getSetLocationMessage("Fairy Grotto", new BlockPos(0, 0, 0)).getString(), Constants.PREFIX.get().getString() + "skyblocker.config.mining.crystalsWaypoints.addedWaypointFairy Grotto skyblocker.config.mining.crystalsWaypoints.addedWaypoint.at : 0 0 0."); + Assertions.assertEquals(Constants.PREFIX.get().getString() + "Added waypoint for 'Jungle Temple' at 10 11 12.", CrystalsLocationsManager.getSetLocationMessage("Jungle Temple", new BlockPos(10, 11, 12)).getString()); + Assertions.assertEquals(Constants.PREFIX.get().getString() + "Added waypoint for 'Fairy Grotto' at 0 0 0.", CrystalsLocationsManager.getSetLocationMessage("Fairy Grotto", new BlockPos(0, 0, 0)).getString()); } } -- cgit