diff options
Diffstat (limited to 'src/test/java/sevenUnits/utils/UncertainDoubleTest.java')
-rw-r--r-- | src/test/java/sevenUnits/utils/UncertainDoubleTest.java | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/src/test/java/sevenUnits/utils/UncertainDoubleTest.java b/src/test/java/sevenUnits/utils/UncertainDoubleTest.java index 518c818..8dcd595 100644 --- a/src/test/java/sevenUnits/utils/UncertainDoubleTest.java +++ b/src/test/java/sevenUnits/utils/UncertainDoubleTest.java @@ -35,48 +35,44 @@ import org.junit.jupiter.api.Test; * @since v0.3.2 */ class UncertainDoubleTest { - /** - * Ensures that the compareTo function behaves correctly. - */ + /** Ensures that the compareTo function behaves correctly. */ @Test final void testCompareTo() { assertTrue(of(2.0, 0.5).compareTo(of(2.0, 0.1)) == 0); assertTrue(of(2.0, 0.5).compareTo(of(1.0, 0.1)) > 0); assertTrue(of(2.0, 0.5).compareTo(of(3.0, 0.1)) < 0); } - - /** - * Tests the ___exact operations - */ + + /** Tests the ___exact operations */ @Test final void testExactOperations() { - final UncertainDouble x = UncertainDouble.of(Math.PI, 0.1); - + final var x = UncertainDouble.of(Math.PI, 0.1); + // slightly different because roundoff errors - final UncertainDouble x1 = UncertainDouble.of(Math.PI + Math.E - Math.E, + final var x1 = UncertainDouble.of(Math.PI + Math.E - Math.E, 0.1); - final UncertainDouble x2 = UncertainDouble.of(Math.PI * Math.E / Math.E, + final var x2 = UncertainDouble.of(Math.PI * Math.E / Math.E, 0.1); - + // get results - final UncertainDouble result1 = x.plusExact(Math.E).minusExact(Math.E); - final UncertainDouble result2 = x.timesExact(Math.E) + final var result1 = x.plusExact(Math.E).minusExact(Math.E); + final var result2 = x.timesExact(Math.E) .dividedByExact(Math.E); - + // test that these operations work & don't change uncertainty assertEquals(x1, result1); assertTrue(x.equivalent(result1)); assertEquals(x2, result2); assertTrue(x.equivalent(result2)); - + // exponents are different assertEquals(Math.pow(Math.PI, Math.E), x.toExponentExact(Math.E).value()); } - + /** * Test for {@link UncertainDouble#fromRoundedString} - * + * * @since 2022-04-18 * @since v0.4.0 */ @@ -84,27 +80,25 @@ class UncertainDoubleTest { final void testFromRoundedString() { assertEquals(of(12345.678, 0.001), fromRoundedString("12345.678")); } - - /** - * Test for {@link UncertainDouble#fromString} - */ + + /** Test for {@link UncertainDouble#fromString} */ @Test final void testFromString() { // valid strings assertEquals(of(2.0, 0.5), fromString("2.0 ± 0.5")); assertEquals(of(2.0, 0.5), fromString("2.0 +- 0.5")); assertEquals(of(2.0, 0.0), fromString("2.0")); - + // invalid strings for (final String s : List.of("2.A", "A", "2.0 ± ", " ± 3.5")) { assertThrows(IllegalArgumentException.class, () -> fromString(s)); } - + // back and forth assertEquals("2.0 ± 0.5", of(2.0, 0.5).toString()); assertEquals("2.0", of(2.0, 0).toString()); } - + @Test final void testHashCode() { assertEquals(of(2.0, 0.5).hashCode(), fromString("2.0 ± 0.5").hashCode()); |