mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[wpimath] Make transform tests use pose/transform equality operators (#4675)
Also add more nonzeros to Transform3d tests to make them more comprehensive.
This commit is contained in:
@@ -4,14 +4,11 @@
|
||||
|
||||
package edu.wpi.first.math.geometry;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class Transform2dTest {
|
||||
private static final double kEpsilon = 1E-9;
|
||||
|
||||
@Test
|
||||
void testInverse() {
|
||||
var initial = new Pose2d(new Translation2d(1.0, 2.0), Rotation2d.fromDegrees(45.0));
|
||||
@@ -20,14 +17,7 @@ class Transform2dTest {
|
||||
var transformed = initial.plus(transform);
|
||||
var untransformed = transformed.plus(transform.inverse());
|
||||
|
||||
assertAll(
|
||||
() -> assertEquals(initial.getX(), untransformed.getX(), kEpsilon),
|
||||
() -> assertEquals(initial.getY(), untransformed.getY(), kEpsilon),
|
||||
() ->
|
||||
assertEquals(
|
||||
initial.getRotation().getDegrees(),
|
||||
untransformed.getRotation().getDegrees(),
|
||||
kEpsilon));
|
||||
assertEquals(initial, untransformed);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -39,13 +29,6 @@ class Transform2dTest {
|
||||
var transformedSeparate = initial.plus(transform1).plus(transform2);
|
||||
var transformedCombined = initial.plus(transform1.plus(transform2));
|
||||
|
||||
assertAll(
|
||||
() -> assertEquals(transformedSeparate.getX(), transformedCombined.getX(), kEpsilon),
|
||||
() -> assertEquals(transformedSeparate.getY(), transformedCombined.getY(), kEpsilon),
|
||||
() ->
|
||||
assertEquals(
|
||||
transformedSeparate.getRotation().getDegrees(),
|
||||
transformedCombined.getRotation().getDegrees(),
|
||||
kEpsilon));
|
||||
assertEquals(transformedSeparate, transformedCombined);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
package edu.wpi.first.math.geometry;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import edu.wpi.first.math.VecBuilder;
|
||||
@@ -12,29 +11,21 @@ import edu.wpi.first.math.util.Units;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class Transform3dTest {
|
||||
private static final double kEpsilon = 1E-9;
|
||||
|
||||
@Test
|
||||
void testInverse() {
|
||||
var zAxis = VecBuilder.fill(0.0, 0.0, 1.0);
|
||||
|
||||
var initial =
|
||||
new Pose3d(
|
||||
new Translation3d(1.0, 2.0, 0.0), new Rotation3d(zAxis, Units.degreesToRadians(45.0)));
|
||||
new Translation3d(1.0, 2.0, 3.0), new Rotation3d(zAxis, Units.degreesToRadians(45.0)));
|
||||
var transform =
|
||||
new Transform3d(
|
||||
new Translation3d(5.0, 0.0, 0.0), new Rotation3d(zAxis, Units.degreesToRadians(5.0)));
|
||||
new Translation3d(5.0, 4.0, 3.0), new Rotation3d(zAxis, Units.degreesToRadians(5.0)));
|
||||
|
||||
var transformed = initial.plus(transform);
|
||||
var untransformed = transformed.plus(transform.inverse());
|
||||
|
||||
assertAll(
|
||||
() -> assertEquals(initial.getX(), untransformed.getX(), kEpsilon),
|
||||
() -> assertEquals(initial.getY(), untransformed.getY(), kEpsilon),
|
||||
() -> assertEquals(initial.getZ(), untransformed.getZ(), kEpsilon),
|
||||
() ->
|
||||
assertEquals(
|
||||
initial.getRotation().getZ(), untransformed.getRotation().getZ(), kEpsilon));
|
||||
assertEquals(initial, untransformed);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,7 +34,7 @@ class Transform3dTest {
|
||||
|
||||
var initial =
|
||||
new Pose3d(
|
||||
new Translation3d(1.0, 2.0, 0.0), new Rotation3d(zAxis, Units.degreesToRadians(45.0)));
|
||||
new Translation3d(1.0, 2.0, 3.0), new Rotation3d(zAxis, Units.degreesToRadians(45.0)));
|
||||
var transform1 =
|
||||
new Transform3d(
|
||||
new Translation3d(5.0, 0.0, 0.0), new Rotation3d(zAxis, Units.degreesToRadians(5.0)));
|
||||
@@ -54,14 +45,6 @@ class Transform3dTest {
|
||||
var transformedSeparate = initial.plus(transform1).plus(transform2);
|
||||
var transformedCombined = initial.plus(transform1.plus(transform2));
|
||||
|
||||
assertAll(
|
||||
() -> assertEquals(transformedSeparate.getX(), transformedCombined.getX(), kEpsilon),
|
||||
() -> assertEquals(transformedSeparate.getY(), transformedCombined.getY(), kEpsilon),
|
||||
() -> assertEquals(transformedSeparate.getZ(), transformedCombined.getZ(), kEpsilon),
|
||||
() ->
|
||||
assertEquals(
|
||||
transformedSeparate.getRotation().getZ(),
|
||||
transformedCombined.getRotation().getZ(),
|
||||
kEpsilon));
|
||||
assertEquals(transformedSeparate, transformedCombined);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user