-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
656bfb4
commit 6570b4a
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/test/java/com/kevinthegreat/skyblockmod/waypoint/WaypointCategoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.kevinthegreat.skyblockmod.waypoint; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.kevinthegreat.skyblockmod.SkyblockMod; | ||
import com.mojang.serialization.JsonOps; | ||
import net.minecraft.Bootstrap; | ||
import net.minecraft.SharedConstants; | ||
import net.minecraft.util.math.BlockPos; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
public class WaypointCategoryTest { | ||
@BeforeAll | ||
static void beforeAll() { | ||
SharedConstants.createGameVersion(); | ||
Bootstrap.initialize(); | ||
} | ||
|
||
@Test | ||
void testCodecEncode() { | ||
WaypointCategory category = new WaypointCategory("category", "hub", List.of(new NamedWaypoint(BlockPos.ORIGIN, "waypoint", new float[]{0f, 0.5f, 1f}, false), new NamedWaypoint(new BlockPos(-1, 0, 1), "waypoint", new float[]{0f, 0f, 0f}, true))); | ||
Object categoryJson = WaypointCategory.CODEC.encodeStart(JsonOps.INSTANCE, category).result().orElseThrow(); | ||
String expectedJson = "{\"name\":\"category\",\"island\":\"hub\",\"waypoints\":[{\"colorComponents\":[0.0,0.5,1.0],\"alpha\":0.5,\"shouldRender\":false,\"pos\":[0,0,0],\"name\":\"waypoint\"},{\"colorComponents\":[0.0,0.0,0.0],\"alpha\":0.5,\"shouldRender\":true,\"pos\":[-1,0,1],\"name\":\"waypoint\"}]}"; | ||
|
||
Assertions.assertEquals(expectedJson, categoryJson.toString()); | ||
} | ||
|
||
@Test | ||
void testCodecDecode() { | ||
String categoryJson = "{\"name\":\"category\",\"island\":\"hub\",\"waypoints\":[{\"colorComponents\":[0.0,0.5,1.0],\"alpha\":0.5,\"shouldRender\":false,\"pos\":[0,0,0],\"name\":\"waypoint\"},{\"colorComponents\":[0.0,0.0,0.0],\"alpha\":0.5,\"shouldRender\":true,\"pos\":[-1,0,1],\"name\":\"waypoint\"}]}"; | ||
WaypointCategory category = WaypointCategory.CODEC.parse(JsonOps.INSTANCE, SkyblockMod.GSON.fromJson(categoryJson, JsonElement.class)).result().orElseThrow(); | ||
WaypointCategory expectedCategory = new WaypointCategory("category", "hub", List.of(new NamedWaypoint(BlockPos.ORIGIN, "waypoint", new float[]{0f, 0.5f, 1f}, false), new NamedWaypoint(new BlockPos(-1, 0, 1), "waypoint", new float[]{0f, 0f, 0f}, true))); | ||
|
||
Assertions.assertEquals(expectedCategory, category); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/test/java/com/kevinthegreat/skyblockmod/waypoint/WaypointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.kevinthegreat.skyblockmod.waypoint; | ||
|
||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Box; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class WaypointTest { | ||
private Waypoint.Type type; | ||
private final float[] colorComponents = new float[]{0f, 0.5f, 1f}; | ||
|
||
@Test | ||
void testDefaultConstructor() { | ||
Waypoint waypoint = new Waypoint(BlockPos.ORIGIN, () -> type, colorComponents); | ||
Assertions.assertEquals(BlockPos.ORIGIN, waypoint.pos); | ||
Assertions.assertEquals(new Box(BlockPos.ORIGIN), waypoint.box); | ||
Assertions.assertEquals(type, waypoint.typeSupplier.get()); | ||
Assertions.assertEquals(0f, waypoint.colorComponents[0]); | ||
Assertions.assertEquals(0.5f, waypoint.colorComponents[1]); | ||
Assertions.assertEquals(1f, waypoint.colorComponents[2]); | ||
Assertions.assertEquals(Waypoint.DEFAULT_HIGHLIGHT_ALPHA, waypoint.alpha); | ||
Assertions.assertEquals(Waypoint.DEFAULT_LINE_WIDTH, waypoint.lineWidth); | ||
Assertions.assertTrue(waypoint.throughWalls); | ||
Assertions.assertTrue(waypoint.shouldRender()); | ||
} | ||
|
||
@Test | ||
void testTypeConstructor() { | ||
Waypoint waypoint = new Waypoint(BlockPos.ORIGIN, Waypoint.Type.WAYPOINT, colorComponents, Waypoint.DEFAULT_HIGHLIGHT_ALPHA); | ||
Assertions.assertEquals(Waypoint.Type.WAYPOINT, waypoint.typeSupplier.get()); | ||
} | ||
|
||
@Test | ||
void testLineWidthConstructor() { | ||
Waypoint waypoint = new Waypoint(BlockPos.ORIGIN, () -> type, colorComponents, Waypoint.DEFAULT_HIGHLIGHT_ALPHA, 10f); | ||
Assertions.assertEquals(10f, waypoint.lineWidth); | ||
} | ||
|
||
@Test | ||
void testThroughWallsConstructor() { | ||
Waypoint waypoint = new Waypoint(BlockPos.ORIGIN, () -> type, colorComponents, Waypoint.DEFAULT_HIGHLIGHT_ALPHA, Waypoint.DEFAULT_LINE_WIDTH, false); | ||
Assertions.assertFalse(waypoint.throughWalls); | ||
} | ||
|
||
@Test | ||
void testShouldRenderConstructor() { | ||
Waypoint waypoint = new Waypoint(BlockPos.ORIGIN, () -> type, colorComponents, Waypoint.DEFAULT_HIGHLIGHT_ALPHA, Waypoint.DEFAULT_LINE_WIDTH, true, false); | ||
Assertions.assertFalse(waypoint.shouldRender()); | ||
} | ||
|
||
@Test | ||
void testFound() { | ||
Waypoint waypoint = new Waypoint(BlockPos.ORIGIN, () -> type, colorComponents); | ||
Assertions.assertTrue(waypoint.shouldRender()); | ||
waypoint.setFound(); | ||
Assertions.assertFalse(waypoint.shouldRender()); | ||
waypoint.setMissing(); | ||
Assertions.assertTrue(waypoint.shouldRender()); | ||
} | ||
|
||
@Test | ||
void testType() { | ||
Waypoint waypoint = new Waypoint(BlockPos.ORIGIN, () -> type, colorComponents); | ||
Assertions.assertEquals(type, waypoint.typeSupplier.get()); | ||
type = Waypoint.Type.WAYPOINT; | ||
Assertions.assertEquals(type, waypoint.typeSupplier.get()); | ||
type = Waypoint.Type.OUTLINED_HIGHLIGHT; | ||
Assertions.assertEquals(type, waypoint.typeSupplier.get()); | ||
} | ||
} |