diff --git a/testing/src/main/java/com/team2813/lib2813/testing/truth/Translation2dSubject.java b/testing/src/main/java/com/team2813/lib2813/testing/truth/Translation2dSubject.java index 846f97d8..e8e6e481 100644 --- a/testing/src/main/java/com/team2813/lib2813/testing/truth/Translation2dSubject.java +++ b/testing/src/main/java/com/team2813/lib2813/testing/truth/Translation2dSubject.java @@ -70,6 +70,24 @@ public void of(Translation2d expected) { }; } + public TolerantComparison isNotWithin(double tolerance) { + return new TolerantComparison<>() { + @Override + public void of(Translation2d expected) { + if (expected == null) { + throw new NullPointerException("Expected value cannot be null."); + } + checkTolerance(tolerance); + if (equalWithinTolerance(expected, nonNullActual(), tolerance)) { + failWithoutActual( + fact("expected not to be", expected), + fact("but was", actual), + fact("within tolerance", tolerance)); + } + } + }; + } + static boolean equalWithinTolerance( Translation2d translation1, Translation2d translation2, double tolerance) { double distance = translation1.getDistance(translation2); diff --git a/testing/src/main/java/com/team2813/lib2813/testing/truth/Translation3dSubject.java b/testing/src/main/java/com/team2813/lib2813/testing/truth/Translation3dSubject.java index 4e21fadf..91625520 100644 --- a/testing/src/main/java/com/team2813/lib2813/testing/truth/Translation3dSubject.java +++ b/testing/src/main/java/com/team2813/lib2813/testing/truth/Translation3dSubject.java @@ -70,6 +70,24 @@ public void of(Translation3d expected) { }; } + public TolerantComparison isNotWithin(double tolerance) { + return new TolerantComparison<>() { + @Override + public void of(Translation3d expected) { + if (expected == null) { + throw new NullPointerException("Expected value cannot be null."); + } + checkTolerance(tolerance); + if (equalWithinTolerance(expected, nonNullActual(), tolerance)) { + failWithoutActual( + fact("expected not to be", expected), + fact("but was", actual), + fact("within tolerance", tolerance)); + } + } + }; + } + static boolean equalWithinTolerance( Translation3d translation1, Translation3d translation2, double tolerance) { double distance = translation1.getDistance(translation2); diff --git a/testing/src/test/java/com/team2813/lib2813/testing/truth/Translation2dSubjectTest.java b/testing/src/test/java/com/team2813/lib2813/testing/truth/Translation2dSubjectTest.java index 6b47d309..1d13a911 100644 --- a/testing/src/test/java/com/team2813/lib2813/testing/truth/Translation2dSubjectTest.java +++ b/testing/src/test/java/com/team2813/lib2813/testing/truth/Translation2dSubjectTest.java @@ -66,4 +66,22 @@ public void isWithin_valueNotWithinTolerance_throws(Pose2dComponent component) { AssertionError.class, () -> Translation2dSubject.assertThat(closeTranslation).isWithin(0.01).of(TRANSLATION)); } + + @ParameterizedTest + @ArgumentsSource(Pose2dComponent.TranslationsArgumentsProvider.class) + public void isNotWithin_valueNotWithinTolerance_doesNotThrow(Pose2dComponent component) { + Translation2d closeTranslation = component.add(TRANSLATION, 0.016); + + Translation2dSubject.assertThat(closeTranslation).isNotWithin(0.01).of(TRANSLATION); + } + + @ParameterizedTest + @ArgumentsSource(Pose2dComponent.TranslationsArgumentsProvider.class) + public void isNotWithin_valueWithinTolerance_throws(Pose2dComponent component) { + Translation2d closeTranslation = component.add(TRANSLATION, 0.009); + + assertThrows( + AssertionError.class, + () -> Translation2dSubject.assertThat(closeTranslation).isNotWithin(0.01).of(TRANSLATION)); + } } diff --git a/testing/src/test/java/com/team2813/lib2813/testing/truth/Translation3dSubjectTest.java b/testing/src/test/java/com/team2813/lib2813/testing/truth/Translation3dSubjectTest.java index e41e5f23..94ca9b79 100644 --- a/testing/src/test/java/com/team2813/lib2813/testing/truth/Translation3dSubjectTest.java +++ b/testing/src/test/java/com/team2813/lib2813/testing/truth/Translation3dSubjectTest.java @@ -66,4 +66,22 @@ public void isWithin_valueNotWithinTolerance_throws(Pose3dComponent component) { AssertionError.class, () -> Translation3dSubject.assertThat(closeTranslation).isWithin(0.01).of(TRANSLATION)); } + + @ParameterizedTest + @ArgumentsSource(Pose3dComponent.TranslationsArgumentsProvider.class) + public void isNotWithin_valueNotWithinTolerance_doesNotThrow(Pose3dComponent component) { + Translation3d closeTranslation = component.add(TRANSLATION, 0.016); + + Translation3dSubject.assertThat(closeTranslation).isNotWithin(0.01).of(TRANSLATION); + } + + @ParameterizedTest + @ArgumentsSource(Pose3dComponent.TranslationsArgumentsProvider.class) + public void isNotWithin_valueWithinTolerance_throws(Pose3dComponent component) { + Translation3d closeTranslation = component.add(TRANSLATION, 0.009); + + assertThrows( + AssertionError.class, + () -> Translation3dSubject.assertThat(closeTranslation).isNotWithin(0.01).of(TRANSLATION)); + } }