Skip to content

Commit 6570b4a

Browse files
Add more waypoint tests
1 parent 656bfb4 commit 6570b4a

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.kevinthegreat.skyblockmod.waypoint;
2+
3+
import com.google.gson.JsonElement;
4+
import com.kevinthegreat.skyblockmod.SkyblockMod;
5+
import com.mojang.serialization.JsonOps;
6+
import net.minecraft.Bootstrap;
7+
import net.minecraft.SharedConstants;
8+
import net.minecraft.util.math.BlockPos;
9+
import org.junit.jupiter.api.Assertions;
10+
import org.junit.jupiter.api.BeforeAll;
11+
import org.junit.jupiter.api.Test;
12+
13+
import java.util.List;
14+
15+
public class WaypointCategoryTest {
16+
@BeforeAll
17+
static void beforeAll() {
18+
SharedConstants.createGameVersion();
19+
Bootstrap.initialize();
20+
}
21+
22+
@Test
23+
void testCodecEncode() {
24+
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)));
25+
Object categoryJson = WaypointCategory.CODEC.encodeStart(JsonOps.INSTANCE, category).result().orElseThrow();
26+
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\"}]}";
27+
28+
Assertions.assertEquals(expectedJson, categoryJson.toString());
29+
}
30+
31+
@Test
32+
void testCodecDecode() {
33+
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\"}]}";
34+
WaypointCategory category = WaypointCategory.CODEC.parse(JsonOps.INSTANCE, SkyblockMod.GSON.fromJson(categoryJson, JsonElement.class)).result().orElseThrow();
35+
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)));
36+
37+
Assertions.assertEquals(expectedCategory, category);
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.kevinthegreat.skyblockmod.waypoint;
2+
3+
import net.minecraft.util.math.BlockPos;
4+
import net.minecraft.util.math.Box;
5+
import org.junit.jupiter.api.Assertions;
6+
import org.junit.jupiter.api.Test;
7+
8+
public class WaypointTest {
9+
private Waypoint.Type type;
10+
private final float[] colorComponents = new float[]{0f, 0.5f, 1f};
11+
12+
@Test
13+
void testDefaultConstructor() {
14+
Waypoint waypoint = new Waypoint(BlockPos.ORIGIN, () -> type, colorComponents);
15+
Assertions.assertEquals(BlockPos.ORIGIN, waypoint.pos);
16+
Assertions.assertEquals(new Box(BlockPos.ORIGIN), waypoint.box);
17+
Assertions.assertEquals(type, waypoint.typeSupplier.get());
18+
Assertions.assertEquals(0f, waypoint.colorComponents[0]);
19+
Assertions.assertEquals(0.5f, waypoint.colorComponents[1]);
20+
Assertions.assertEquals(1f, waypoint.colorComponents[2]);
21+
Assertions.assertEquals(Waypoint.DEFAULT_HIGHLIGHT_ALPHA, waypoint.alpha);
22+
Assertions.assertEquals(Waypoint.DEFAULT_LINE_WIDTH, waypoint.lineWidth);
23+
Assertions.assertTrue(waypoint.throughWalls);
24+
Assertions.assertTrue(waypoint.shouldRender());
25+
}
26+
27+
@Test
28+
void testTypeConstructor() {
29+
Waypoint waypoint = new Waypoint(BlockPos.ORIGIN, Waypoint.Type.WAYPOINT, colorComponents, Waypoint.DEFAULT_HIGHLIGHT_ALPHA);
30+
Assertions.assertEquals(Waypoint.Type.WAYPOINT, waypoint.typeSupplier.get());
31+
}
32+
33+
@Test
34+
void testLineWidthConstructor() {
35+
Waypoint waypoint = new Waypoint(BlockPos.ORIGIN, () -> type, colorComponents, Waypoint.DEFAULT_HIGHLIGHT_ALPHA, 10f);
36+
Assertions.assertEquals(10f, waypoint.lineWidth);
37+
}
38+
39+
@Test
40+
void testThroughWallsConstructor() {
41+
Waypoint waypoint = new Waypoint(BlockPos.ORIGIN, () -> type, colorComponents, Waypoint.DEFAULT_HIGHLIGHT_ALPHA, Waypoint.DEFAULT_LINE_WIDTH, false);
42+
Assertions.assertFalse(waypoint.throughWalls);
43+
}
44+
45+
@Test
46+
void testShouldRenderConstructor() {
47+
Waypoint waypoint = new Waypoint(BlockPos.ORIGIN, () -> type, colorComponents, Waypoint.DEFAULT_HIGHLIGHT_ALPHA, Waypoint.DEFAULT_LINE_WIDTH, true, false);
48+
Assertions.assertFalse(waypoint.shouldRender());
49+
}
50+
51+
@Test
52+
void testFound() {
53+
Waypoint waypoint = new Waypoint(BlockPos.ORIGIN, () -> type, colorComponents);
54+
Assertions.assertTrue(waypoint.shouldRender());
55+
waypoint.setFound();
56+
Assertions.assertFalse(waypoint.shouldRender());
57+
waypoint.setMissing();
58+
Assertions.assertTrue(waypoint.shouldRender());
59+
}
60+
61+
@Test
62+
void testType() {
63+
Waypoint waypoint = new Waypoint(BlockPos.ORIGIN, () -> type, colorComponents);
64+
Assertions.assertEquals(type, waypoint.typeSupplier.get());
65+
type = Waypoint.Type.WAYPOINT;
66+
Assertions.assertEquals(type, waypoint.typeSupplier.get());
67+
type = Waypoint.Type.OUTLINED_HIGHLIGHT;
68+
Assertions.assertEquals(type, waypoint.typeSupplier.get());
69+
}
70+
}

0 commit comments

Comments
 (0)