Skip to content

Commit

Permalink
Minor additions to tests for Util.inTolerance().
Browse files Browse the repository at this point in the history
  • Loading branch information
STHobbes committed May 5, 2023
1 parent e047d94 commit 36bae9e
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/test/java/org/a05annex/util/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,27 @@ void test_clip_no_max() {
@Test
@DisplayName("Test inTolerance true")
public void testInToleranceTrue() {
// Test when the value is within the tolerance
assertTrue(Utl.inTolerance(5.0, 4.9, 0.1));
assertTrue(Utl.inTolerance(10.0, 10.05, 0.1));
assertTrue(Utl.inTolerance(3.0, 2.95, 0.1));
// Test when the value is within the tolerance - NOTE: the tolerance value has an .000000001 value added to
// account for the very small representational round-off error when the specified value and target are
// converted to doubles.
assertTrue(Utl.inTolerance(5.0, 4.9, 0.100000001));
assertTrue(Utl.inTolerance(4.8, 4.9, 0.100000001));
assertTrue(Utl.inTolerance(10.0, 10.05, 0.100000001));
assertTrue(Utl.inTolerance(10.1, 10.05, 0.100000001));
assertTrue(Utl.inTolerance(3.0, 2.95, 0.100000001));
assertTrue(Utl.inTolerance(2.9, 2.95, 0.100000001));
}

@Test
@DisplayName("Test inTolerance false")
public void testInToleranceFalse() {
// Test when the value is not within the tolerance
assertFalse(Utl.inTolerance(5.0, 4.9, 0.05));
assertFalse(Utl.inTolerance(4.8, 4.9, 0.05));
assertFalse(Utl.inTolerance(10.0, 10.05, 0.01));
assertFalse(Utl.inTolerance(10.1, 10.05, 0.01));
assertFalse(Utl.inTolerance(3.0, 2.95, 0.001));
assertFalse(Utl.inTolerance(2.9, 2.95, 0.001));
}

@Test
Expand All @@ -176,9 +184,14 @@ public void testInToleranceZeroTolerance() {
@Test
@DisplayName("Test inTolerance with negative values")
public void testInToleranceNegativeValues() {
// Test when the value and/or target are negative
assertTrue(Utl.inTolerance(-5.0, -4.9, 0.1));
assertTrue(Utl.inTolerance(-10.0, -10.05, 0.1));
assertTrue(Utl.inTolerance(-3.0, -2.95, 0.1));
// Test when the value and/or target are negative - NOTE: the tolerance value has an .000000001 value added to
// account for the very small representational round-off error when the specified value and target are
// converted to doubles.
assertTrue(Utl.inTolerance(-5.0, -4.9, 0.100000001));
assertTrue(Utl.inTolerance(-4.8, -4.9, 0.100000001));
assertTrue(Utl.inTolerance(-10.0, -10.05, 0.100000001));
assertTrue(Utl.inTolerance(-10.1, -10.05, 0.100000001));
assertTrue(Utl.inTolerance(-3.0, -2.95, 0.100000001));
assertTrue(Utl.inTolerance(-2.9, -2.95, 0.100000001));
}
}

0 comments on commit 36bae9e

Please sign in to comment.