mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Add equality comparator to geometry classes (#1882)
This commit is contained in:
committed by
Peter Johnson
parent
62f07c182c
commit
86b666bba9
@@ -11,6 +11,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
class Pose2dTest {
|
||||
private static final double kEpsilon = 1E-9;
|
||||
@@ -44,4 +45,18 @@ class Pose2dTest {
|
||||
() -> assertEquals(finalRelativeToInitial.getRotation().getDegrees(), 0.0, kEpsilon)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquality() {
|
||||
var one = new Pose2d(0.0, 5.0, Rotation2d.fromDegrees(43.0));
|
||||
var two = new Pose2d(0.0, 5.0, Rotation2d.fromDegrees(43.0));
|
||||
assertEquals(one, two);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInequality() {
|
||||
var one = new Pose2d(0.0, 5.0, Rotation2d.fromDegrees(43.0));
|
||||
var two = new Pose2d(0.0, 1.524, Rotation2d.fromDegrees(43.0));
|
||||
assertNotEquals(one, two);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
class Rotation2dTest {
|
||||
private static final double kEpsilon = 1E-9;
|
||||
@@ -63,4 +64,18 @@ class Rotation2dTest {
|
||||
|
||||
assertEquals(one.minus(two).getDegrees(), 40.0, kEpsilon);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquality() {
|
||||
var one = Rotation2d.fromDegrees(43.0);
|
||||
var two = Rotation2d.fromDegrees(43.0);
|
||||
assertEquals(one, two);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInequality() {
|
||||
var one = Rotation2d.fromDegrees(43.0);
|
||||
var two = Rotation2d.fromDegrees(43.5);
|
||||
assertNotEquals(one, two);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
class Translation2dTest {
|
||||
private static final double kEpsilon = 1E-9;
|
||||
@@ -97,4 +98,18 @@ class Translation2dTest {
|
||||
() -> assertEquals(inverted.getY(), -7, kEpsilon)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquality() {
|
||||
var one = new Translation2d(9, 5.5);
|
||||
var two = new Translation2d(9, 5.5);
|
||||
assertEquals(one, two);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInequality() {
|
||||
var one = new Translation2d(9, 5.5);
|
||||
var two = new Translation2d(9, 5.7);
|
||||
assertNotEquals(one, two);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
class Twist2dTest {
|
||||
private static final double kEpsilon = 1E-9;
|
||||
@@ -50,4 +51,18 @@ class Twist2dTest {
|
||||
() -> assertEquals(diagonalPose.getRotation().getDegrees(), 0.0, kEpsilon)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquality() {
|
||||
var one = new Twist2d(5, 1, 3);
|
||||
var two = new Twist2d(5, 1, 3);
|
||||
assertEquals(one, two);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInequality() {
|
||||
var one = new Twist2d(5, 1, 3);
|
||||
var two = new Twist2d(5, 1.2, 3);
|
||||
assertNotEquals(one, two);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user