Skip to content

Add truth extensions for Measure, and add isNotWithin#151

Open
cuttestkittensrule wants to merge 8 commits intomainfrom
kyle/truth-units-assert
Open

Add truth extensions for Measure, and add isNotWithin#151
cuttestkittensrule wants to merge 8 commits intomainfrom
kyle/truth-units-assert

Conversation

@cuttestkittensrule
Copy link
Copy Markdown
Collaborator

  • Add MeasureSubject
    • Operates on any WPILib Measure class, and can check if a value is what is expected, within a given degree of tolerance. This degree of tolerance is supplied as a Measure so it is clear what unit it is in.
    • When printing error messages, it shows the values in the units it was created in. This does mean that the different prints can all be different types.
  • Add isNotWithin
    • Uses DoubleSubject's isNotWithin to assert that a value is not within a given tolerance of an expected value.
    • For non-measure subjects, they still exhibit the same behavior, interpreting the tolerance as the default unit (meters for distance, and radians for rotation).

Copy link
Copy Markdown
Contributor

@kcooney kcooney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, but would be better with tests.

I sent out #152 which adds tests to the existing subjects

@kcooney
Copy link
Copy Markdown
Contributor

kcooney commented Mar 28, 2026

I started adding tests for Pose2dSubject.isNotWithin() and, unfortunately, it doesn't work.

For example:

      @Override
      public void of(Pose2d expected) {
        translation().isNotWithin(tolerance).of(expected.getTranslation());
        rotation().isNotWithin(tolerance).of(expected.getRotation());
      }

If both the rotation and the translation are not within tolerance than this will not throw, but if only one of them is not within tolerance it will throw.

@kcooney kcooney force-pushed the kyle/truth-units-assert branch from db80c86 to 787d19c Compare March 28, 2026 18:07
@kcooney
Copy link
Copy Markdown
Contributor

kcooney commented Mar 28, 2026

@cuttestkittensrule I removed the broken isNotWithin() methods and added some tests for MeasureSubject.

Currently all of the tests use expected and actual values that have the same units. We should add tests for different units (ex: volts vs minivolts).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants