diff options
Diffstat (limited to 'src/test/java')
3 files changed, 114 insertions, 2 deletions
diff --git a/src/test/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonChestProfitTest.java b/src/test/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonChestProfitTest.java new file mode 100644 index 00000000..7a130b5a --- /dev/null +++ b/src/test/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonChestProfitTest.java @@ -0,0 +1,22 @@ +package me.xmrvizzy.skyblocker.skyblock.dungeon; + +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class DungeonChestProfitTest { + @Test + void testProfitText() { + SkyblockerConfig.DungeonChestProfit config = new SkyblockerConfig.DungeonChestProfit(); + Assertions.assertEquals("literal{ 0}[style={color=dark_gray}]", DungeonChestProfit.getProfitText(0, false, config.neutralThreshold, config.neutralColor.formatting, config.profitColor.formatting, config.lossColor.formatting, config.incompleteColor.formatting).toString()); + Assertions.assertEquals("literal{ 0}[style={color=blue}]", DungeonChestProfit.getProfitText(0, true, config.neutralThreshold, config.neutralColor.formatting, config.profitColor.formatting, config.lossColor.formatting, config.incompleteColor.formatting).toString()); + Assertions.assertEquals("literal{ +10}[style={color=dark_gray}]", DungeonChestProfit.getProfitText(10, false, config.neutralThreshold, config.neutralColor.formatting, config.profitColor.formatting, config.lossColor.formatting, config.incompleteColor.formatting).toString()); + Assertions.assertEquals("literal{ +10}[style={color=blue}]", DungeonChestProfit.getProfitText(10, true, config.neutralThreshold, config.neutralColor.formatting, config.profitColor.formatting, config.lossColor.formatting, config.incompleteColor.formatting).toString()); + Assertions.assertEquals("literal{ -10}[style={color=dark_gray}]", DungeonChestProfit.getProfitText(-10, false, config.neutralThreshold, config.neutralColor.formatting, config.profitColor.formatting, config.lossColor.formatting, config.incompleteColor.formatting).toString()); + Assertions.assertEquals("literal{ -10}[style={color=blue}]", DungeonChestProfit.getProfitText(-10, true, config.neutralThreshold, config.neutralColor.formatting, config.profitColor.formatting, config.lossColor.formatting, config.incompleteColor.formatting).toString()); + Assertions.assertEquals("literal{ +10,000}[style={color=dark_green}]", DungeonChestProfit.getProfitText(10000, false, config.neutralThreshold, config.neutralColor.formatting, config.profitColor.formatting, config.lossColor.formatting, config.incompleteColor.formatting).toString()); + Assertions.assertEquals("literal{ +10,000}[style={color=blue}]", DungeonChestProfit.getProfitText(10000, true, config.neutralThreshold, config.neutralColor.formatting, config.profitColor.formatting, config.lossColor.formatting, config.incompleteColor.formatting).toString()); + Assertions.assertEquals("literal{ -10,000}[style={color=red}]", DungeonChestProfit.getProfitText(-10000, false, config.neutralThreshold, config.neutralColor.formatting, config.profitColor.formatting, config.lossColor.formatting, config.incompleteColor.formatting).toString()); + Assertions.assertEquals("literal{ -10,000}[style={color=blue}]", DungeonChestProfit.getProfitText(-10000, true, config.neutralThreshold, config.neutralColor.formatting, config.profitColor.formatting, config.lossColor.formatting, config.incompleteColor.formatting).toString()); + } +} diff --git a/src/test/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonRoomsDFU.java b/src/test/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonRoomsDFU.java index c103bb3d..5e4cdeef 100644 --- a/src/test/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonRoomsDFU.java +++ b/src/test/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonRoomsDFU.java @@ -5,7 +5,9 @@ import net.minecraft.datafixer.fix.ItemInstanceTheFlatteningFix; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.*; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.net.URL; import java.nio.file.DirectoryStream; import java.nio.file.Files; @@ -91,7 +93,7 @@ public class DungeonRoomsDFU { for (Map.Entry<String, HashMap<String, long[]>> oldRoomShape : oldDungeon.getValue().entrySet()) { HashMap<String, int[]> roomShape = new HashMap<>(); for (Map.Entry<String, long[]> oldRoomEntry : oldRoomShape.getValue().entrySet()) { - roomShape.put(oldRoomEntry.getKey(), updateRoom(oldRoomEntry.getValue())); + roomShape.put(oldRoomEntry.getKey().replaceAll(" ", "-"), updateRoom(oldRoomEntry.getValue())); } dungeon.put(oldRoomShape.getKey(), roomShape); } diff --git a/src/test/java/me/xmrvizzy/skyblocker/utils/scheduler/SchedulerTest.java b/src/test/java/me/xmrvizzy/skyblocker/utils/scheduler/SchedulerTest.java new file mode 100644 index 00000000..5b3317ab --- /dev/null +++ b/src/test/java/me/xmrvizzy/skyblocker/utils/scheduler/SchedulerTest.java @@ -0,0 +1,88 @@ +package me.xmrvizzy.skyblocker.utils.scheduler; + +import org.apache.commons.lang3.mutable.MutableInt; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class SchedulerTest { + private final MutableInt currentTick = new MutableInt(0); + private final MutableInt cycleCount1 = new MutableInt(0); + private final MutableInt cycleCount2 = new MutableInt(0); + private final MutableInt cycleCount3 = new MutableInt(0); + private final MutableInt cycleCount4 = new MutableInt(0); + private final MutableInt cycleCount5 = new MutableInt(0); + private final MutableInt cycleCount6 = new MutableInt(0); + private final MutableInt cycleCount7 = new MutableInt(0); + private final MutableInt cycleCount8 = new MutableInt(0); + + @Test + public void testSchedule() { + Scheduler.INSTANCE.schedule(() -> Assertions.assertEquals(0, currentTick.intValue()), 0); + Scheduler.INSTANCE.schedule(() -> Assertions.assertEquals(1, currentTick.intValue()), 1); + Scheduler.INSTANCE.schedule(() -> Assertions.assertEquals(2, currentTick.intValue()), 2); + Scheduler.INSTANCE.schedule(() -> Assertions.assertEquals(10, currentTick.intValue()), 10); + Scheduler.INSTANCE.schedule(() -> Assertions.assertEquals(20, currentTick.intValue()), 20); + Scheduler.INSTANCE.schedule(() -> Assertions.assertEquals(50, currentTick.intValue()), 50); + Scheduler.INSTANCE.schedule(() -> Assertions.assertEquals(100, currentTick.intValue()), 100); + Scheduler.INSTANCE.schedule(() -> Assertions.assertEquals(123, currentTick.intValue()), 123); + Scheduler.INSTANCE.scheduleCyclic(() -> {}, 1); + Scheduler.INSTANCE.scheduleCyclic(() -> {}, 1); + Scheduler.INSTANCE.scheduleCyclic(() -> {}, 1); + Scheduler.INSTANCE.scheduleCyclic(() -> {}, 1); + Scheduler.INSTANCE.scheduleCyclic(() -> { + Assertions.assertEquals(cycleCount1.intValue(), currentTick.intValue()); + cycleCount1.increment(); + }, 1); + Scheduler.INSTANCE.scheduleCyclic(() -> { + Assertions.assertEquals(0, currentTick.intValue() % 10); + Assertions.assertEquals(cycleCount2.intValue(), currentTick.intValue() / 10); + cycleCount2.increment(); + }, 10); + Scheduler.INSTANCE.scheduleCyclic(() -> { + Assertions.assertEquals(0, currentTick.intValue() % 55); + Assertions.assertEquals(cycleCount3.intValue(), currentTick.intValue() / 55); + cycleCount3.increment(); + }, 55); + Scheduler.INSTANCE.schedule(() -> Scheduler.INSTANCE.scheduleCyclic(() -> { + Assertions.assertEquals(7, currentTick.intValue() % 10); + Assertions.assertEquals(cycleCount4.intValue(), currentTick.intValue() / 10); + cycleCount4.increment(); + }, 10), 7); + Scheduler.INSTANCE.schedule(() -> Scheduler.INSTANCE.scheduleCyclic(() -> { + Assertions.assertEquals(0, currentTick.intValue() % 75); + Assertions.assertEquals(cycleCount5.intValue(), currentTick.intValue() / 75); + cycleCount5.increment(); + }, 75), 0); + Scheduler.INSTANCE.schedule(() -> Scheduler.INSTANCE.scheduleCyclic(() -> { + Assertions.assertEquals(1, currentTick.intValue() % 99); + Assertions.assertEquals(cycleCount6.intValue(), currentTick.intValue() / 99); + cycleCount6.increment(); + }, 99), 1); + Scheduler.INSTANCE.scheduleCyclic(() -> Scheduler.INSTANCE.schedule(() -> { + Assertions.assertEquals(5, currentTick.intValue() % 10); + Assertions.assertEquals(cycleCount7.intValue(), currentTick.intValue() / 10); + cycleCount7.increment(); + }, 5), 10); + Scheduler.INSTANCE.scheduleCyclic(() -> Scheduler.INSTANCE.schedule(() -> { + Assertions.assertEquals(10, currentTick.intValue() % 55); + Assertions.assertEquals(cycleCount8.intValue(), currentTick.intValue() / 55); + cycleCount8.increment(); + }, 10), 55); + while (currentTick.intValue() < 100_000) { + tick(); + } + Assertions.assertEquals(100000, cycleCount1.intValue()); + Assertions.assertEquals(10000, cycleCount2.intValue()); + Assertions.assertEquals(1819, cycleCount3.intValue()); + Assertions.assertEquals(10000, cycleCount4.intValue()); + Assertions.assertEquals(1334, cycleCount5.intValue()); + Assertions.assertEquals(1011, cycleCount6.intValue()); + Assertions.assertEquals(10000, cycleCount7.intValue()); + Assertions.assertEquals(1818, cycleCount8.intValue()); + } + + private void tick() { + Scheduler.INSTANCE.tick(); + currentTick.increment(); + } +} |
