Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ public void of(Translation2d expected) {
};
}

public TolerantComparison<Translation2d> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ public void of(Translation3d expected) {
};
}

public TolerantComparison<Translation3d> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Loading