Skip to content

Commit

Permalink
GH-44 Fix position E identification. (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
vLuckyyy authored Dec 29, 2024
1 parent 5963e2e commit 37c1fc8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ public record Position(double x, double y, double z, float yaw, float pitch, Str
public static final String NONE_WORLD = "__NONE__";

private static final Pattern PARSE_FORMAT = Pattern.compile(
"Position\\{x=(?<x>-?[\\d.]+), y=(?<y>-?[\\d.]+), z=(?<z>-?[\\d.]+), yaw=(?<yaw>-?[\\d.]+), pitch=(?<pitch>-?[\\d.]+), world='(?<world>.+)'}");

"Position\\{x=(?<x>-?[\\d.]+(?:[eE][-+]?\\d+)?), " +
"y=(?<y>-?[\\d.]+(?:[eE][-+]?\\d+)?), " +
"z=(?<z>-?[\\d.]+(?:[eE][-+]?\\d+)?), " +
"yaw=(?<yaw>-?[\\d.]+(?:[eE][-+]?\\d+)?), " +
"pitch=(?<pitch>-?[\\d.]+(?:[eE][-+]?\\d+)?), " +
"world='(?<world>.+)'}");

public Position(double x, double y, double z, String world) {
this(x, y, z, 0F, 0F, world);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PositionTest {

@BeforeEach
void setUp() {
position = new Position(1.0d, 2.0d, 3.0d, 4.0f, 5.0f, "world");
position = new Position(1.0d, 2.0d, 3.0d, 90.49303f, -6.020069E-6f, "world");
}

@Test
Expand All @@ -36,12 +36,12 @@ void getZ() {

@Test
void getYaw() {
assertEquals(4.0f, position.yaw());
assertEquals(90.49303f, position.yaw());
}

@Test
void getPitch() {
assertEquals(5.0f, position.pitch());
assertEquals(-6.020069E-6f, position.pitch());
}

@Test
Expand All @@ -51,8 +51,8 @@ void isNoneWorld() {

@Test
void testEqualsAndHashCode() {
Position position2 = new Position(1.0d, 2.0d, 3.0d, 4.0f, 5.0f, "world");
Position position3 = new Position(1.0d, 2.0d, 3.1d, 4.0f, 5.0f, "world");
Position position2 = new Position(1.0d, 2.0d, 3.0d, 90.49303f, -6.020069E-6f, "world");
Position position3 = new Position(1.0d, 2.0d, 3.1d, 90.49303f, -6.020069E-6f, "world");

// Reflexive test
assertEquals(position, position);
Expand All @@ -71,18 +71,18 @@ void testEqualsAndHashCode() {

@Test
void testToString() {
String expectedString = "Position{x=1.0, y=2.0, z=3.0, yaw=4.0, pitch=5.0, world='world'}";
String expectedString = "Position{x=1.0, y=2.0, z=3.0, yaw=90.49303, pitch=-6.020069E-6, world='world'}";
assertEquals(expectedString, position.toString());
}

@Test
void parse() {
Position parsed = Position.parse("Position{x=1.0, y=2.0, z=3.0, yaw=4.0, pitch=5.0, world='world'}");
Position parsed = Position.parse("Position{x=1.0, y=2.0, z=3.0, yaw=90.49303, pitch=-6.020069E-6, world='world'}");
assertEquals(position, parsed);
}

@Test
void parseInvalid() {
assertThrows(IllegalArgumentException.class, () -> Position.parse("Invalid{x=1.0, y=2.0, z=3.0, yaw=4.0, pitch=5.0, world='world'}"));
assertThrows(IllegalArgumentException.class, () -> Position.parse("Invalid{x=1.0, y=2.0, z=3.0, yaw=90.49303, pitch=-6.020069E-6, world='world'}"));
}
}

0 comments on commit 37c1fc8

Please sign in to comment.