summaryrefslogtreecommitdiff
path: root/src/test/java/sevenUnits/utils/UncertainDoubleTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/sevenUnits/utils/UncertainDoubleTest.java')
-rw-r--r--src/test/java/sevenUnits/utils/UncertainDoubleTest.java39
1 files changed, 16 insertions, 23 deletions
diff --git a/src/test/java/sevenUnits/utils/UncertainDoubleTest.java b/src/test/java/sevenUnits/utils/UncertainDoubleTest.java
index 36b373b..733a308 100644
--- a/src/test/java/sevenUnits/utils/UncertainDoubleTest.java
+++ b/src/test/java/sevenUnits/utils/UncertainDoubleTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2021 Adrien Hopkins
+ * Copyright (C) 2021, 2022, 2024, 2025 Adrien Hopkins
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@@ -32,11 +32,10 @@ import org.junit.jupiter.api.Test;
*
* @author Adrien Hopkins
* @since 2021-11-29
+ * @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);
@@ -44,23 +43,18 @@ class UncertainDoubleTest {
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,
- 0.1);
- final UncertainDouble x2 = UncertainDouble.of(Math.PI * Math.E / Math.E,
- 0.1);
+ final var x1 = UncertainDouble.of(Math.PI + Math.E - Math.E, 0.1);
+ 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)
- .dividedByExact(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);
@@ -75,36 +69,35 @@ class UncertainDoubleTest {
/**
* Test for {@link UncertainDouble#fromRoundedString}
- *
+ *
* @since 2022-04-18
+ * @since v0.4.0
*/
@Test
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.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")) {
+ 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 ± 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());
+ assertEquals(of(2.0, 0.5).hashCode(), fromString("2.0 ± 0.5").hashCode());
}
}