summaryrefslogtreecommitdiff
path: root/src/test/java/sevenUnits/utils
diff options
context:
space:
mode:
authorAdrien Hopkins <adrien.p.hopkins@gmail.com>2025-06-15 19:41:31 -0500
committerAdrien Hopkins <adrien.p.hopkins@gmail.com>2025-06-15 19:41:31 -0500
commit0d4bb6953d34434d1bc9813fa123912e1cf04264 (patch)
tree4c908950d9b049394f8160b8159b498aec586ecc /src/test/java/sevenUnits/utils
parent255a0ac50b07d4fef9664767c4123ecaf4881d55 (diff)
parentbccb5b5e3452421c81c1fb58f83391ba6584807c (diff)
Merge branch 'release-1.0.0' into developdevelop
Diffstat (limited to 'src/test/java/sevenUnits/utils')
-rw-r--r--src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java58
-rw-r--r--src/test/java/sevenUnits/utils/ExpressionParserTest.java80
-rw-r--r--src/test/java/sevenUnits/utils/NameSymbolTest.java76
-rw-r--r--src/test/java/sevenUnits/utils/ObjectProductTest.java8
-rw-r--r--src/test/java/sevenUnits/utils/SemanticVersionTest.java81
-rw-r--r--src/test/java/sevenUnits/utils/UncertainDoubleTest.java47
6 files changed, 163 insertions, 187 deletions
diff --git a/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java b/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java
index ea96574..8711847 100644
--- a/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java
+++ b/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java
@@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -38,7 +37,7 @@ import sevenUnits.utils.ConditionalExistenceCollections.ConditionalExistenceIter
* normal operations on conditional existence collections and ensures that
* elements that do not pass the existence condition are not included in the
* results.
- *
+ *
* @author Adrien Hopkins
* @since 2019-10-16
* @since v0.3.0
@@ -47,22 +46,22 @@ class ConditionalExistenceCollectionsTest {
/**
* The returned iterator ignores elements that don't start with "a".
- *
+ *
* @return test iterator
* @since 2019-10-17
* @since v0.3.0
*/
ConditionalExistenceIterator<String> getTestIterator() {
final List<String> items = Arrays.asList("aa", "ab", "ba");
- final Iterator<String> it = items.iterator();
- final ConditionalExistenceIterator<String> cit = (ConditionalExistenceIterator<String>) ConditionalExistenceCollections
+ final var it = items.iterator();
+ final var cit = (ConditionalExistenceIterator<String>) ConditionalExistenceCollections
.conditionalExistenceIterator(it, s -> s.startsWith("a"));
return cit;
}
/**
* The returned map ignores mappings where the value is zero.
- *
+ *
* @return map to be used for test data
* @since 2019-10-16
* @since v0.3.0
@@ -79,60 +78,49 @@ class ConditionalExistenceCollectionsTest {
return conditionalMap;
}
- /**
- * Test method for the ConditionalExistenceMap's containsKey method.
- */
+ /** Test method for the ConditionalExistenceMap's containsKey method. */
@Test
void testContainsKeyObject() {
- final Map<String, Integer> map = this.getTestMap();
+ final var map = this.getTestMap();
assertTrue(map.containsKey("one"));
assertTrue(map.containsKey("ten"));
assertFalse(map.containsKey("five"));
assertFalse(map.containsKey("zero"));
}
- /**
- * Test method for the ConditionalExistenceMap's containsValue method.
- */
+ /** Test method for the ConditionalExistenceMap's containsValue method. */
@Test
void testContainsValueObject() {
- final Map<String, Integer> map = this.getTestMap();
+ final var map = this.getTestMap();
assertTrue(map.containsValue(1));
assertTrue(map.containsValue(10));
assertFalse(map.containsValue(5));
assertFalse(map.containsValue(0));
}
- /**
- * Test method for the ConditionalExistenceMap's entrySet method.
- */
+ /** Test method for the ConditionalExistenceMap's entrySet method. */
@Test
void testEntrySet() {
- final Map<String, Integer> map = this.getTestMap();
+ final var map = this.getTestMap();
for (final Entry<String, Integer> e : map.entrySet()) {
assertTrue(e.getValue() != 0);
}
}
- /**
- * Test method for the ConditionalExistenceMap's get method.
- */
+ /** Test method for the ConditionalExistenceMap's get method. */
@Test
void testGetObject() {
- final Map<String, Integer> map = this.getTestMap();
+ final var map = this.getTestMap();
assertEquals(1, map.get("one"));
assertEquals(10, map.get("ten"));
assertEquals(null, map.get("five"));
assertEquals(null, map.get("zero"));
}
- /**
- * Test method for the ConditionalExistenceCollection's iterator.
- */
+ /** Test method for the ConditionalExistenceCollection's iterator. */
@Test
void testIterator() {
- final ConditionalExistenceIterator<String> testIterator = this
- .getTestIterator();
+ final var testIterator = this.getTestIterator();
assertTrue(testIterator.hasNext);
assertTrue(testIterator.hasNext());
@@ -150,22 +138,18 @@ class ConditionalExistenceCollectionsTest {
assertThrows(NoSuchElementException.class, testIterator::next);
}
- /**
- * Test method for the ConditionalExistenceMap's keySet operation.
- */
+ /** Test method for the ConditionalExistenceMap's keySet operation. */
@Test
void testKeySet() {
- final Map<String, Integer> map = this.getTestMap();
- assertFalse(map.keySet().contains("zero"));
+ final var map = this.getTestMap();
+ assertFalse(map.containsKey("zero"));
}
- /**
- * Test method for the ConditionalExistenceMap's values operation.
- */
+ /** Test method for the ConditionalExistenceMap's values operation. */
@Test
void testValues() {
- final Map<String, Integer> map = this.getTestMap();
- assertFalse(map.values().contains(0));
+ final var map = this.getTestMap();
+ assertFalse(map.containsValue(0));
}
}
diff --git a/src/test/java/sevenUnits/utils/ExpressionParserTest.java b/src/test/java/sevenUnits/utils/ExpressionParserTest.java
index 72d3b19..2e0b4b0 100644
--- a/src/test/java/sevenUnits/utils/ExpressionParserTest.java
+++ b/src/test/java/sevenUnits/utils/ExpressionParserTest.java
@@ -30,7 +30,7 @@ import org.junit.jupiter.params.provider.MethodSource;
/**
* A test for the {@code ExpressionParser} class. This is NOT part of this
* program's public API.
- *
+ *
* @author Adrien Hopkins
* @since 2019-03-22
* @since v0.2.0
@@ -45,9 +45,7 @@ class ExpressionParserTest {
.addUnaryOperator("recip", o1 -> 1 / o1, 3)
.addBinaryOperator("^", (o1, o2) -> (int) Math.pow(o1, o2), 4).build();
- /**
- * The expressions used in the expression parsing tests
- */
+ /** The expressions used in the expression parsing tests */
private static final List<String> TEST_EXPRESSIONS = List.of(
// test parsing of expressions
"1 + 2 ^ 5 * 3", "(1 + 2) ^ 5 * 3",
@@ -56,22 +54,9 @@ class ExpressionParserTest {
// ensure it normally goes from left to right
"1 + 2 + 3 + 4", "12 - 4 - 3", "12 - (4 - 3)", "1 / 2 + 3");
- /**
- * The expected results for evaluating these expressions
- */
+ /** The expected results for evaluating these expressions */
private static final int[] RESULTS = { 97, 729, 133, 10, 5, 11, 3 };
- /**
- * @return A stream of objects, where each one is an expression and the
- * expected result
- * @since 2021-09-27
- * @since v0.3.2
- */
- private static final Stream<Arguments> testParseExpressionData() {
- return IntStream.range(0, TEST_EXPRESSIONS.size())
- .mapToObj(i -> Arguments.of(TEST_EXPRESSIONS.get(i), RESULTS[i]));
- }
-
private static final Stream<Arguments> testConvertExpressionToRPN() {
return Stream.of(Arguments.of("1 + 2 ^ 5 * 3", "1 2 5 ^ 3 * +"),
Arguments.of("(1 + 2) ^ 5 * 3", "1 2 + 5 ^ 3 *"),
@@ -91,18 +76,6 @@ class ExpressionParserTest {
Arguments.of("1 + neg 2", "1 2 neg +"));
}
- private static final Stream<Arguments> testParseRPN() {
- return Stream.of(Arguments.of("1 2 5 ^ 3 * +", 97),
- Arguments.of("1 2 + 5 ^ 3 *", 729),
- Arguments.of("12 5 * 3 2 3 * ^ 72 - 3 3 2 * + / +", 133),
- Arguments.of("1 2 + 3 + 4 +", 10), Arguments.of("12 4 - 3 -", 5),
- Arguments.of("12 4 3 - -", 11), Arguments.of("1 2 / 3 +", 3),
- Arguments.of("12", 12), Arguments.of("2 3 * 4 +", 10),
- Arguments.of("2 3 * 4 -", 2), Arguments.of("2 3 4 + *", 14),
- Arguments.of("2 3 4 - *", -2), Arguments.of("2 neg", -2),
- Arguments.of("1 2 neg +", -1));
- }
-
private static final Stream<String> testInvalidExpression() {
return Stream.of("+", "1 +", "1 + * 2", "1 (+ 1)", "neg");
}
@@ -112,13 +85,26 @@ class ExpressionParserTest {
}
/**
- * Test method for
- * {@link sevenUnits.utils.ExpressionParser#parseExpression(java.lang.String)}.
+ * @return A stream of objects, where each one is an expression and the
+ * expected result
+ * @since 2021-09-27
+ * @since v0.3.2
*/
- @ParameterizedTest
- @MethodSource("testParseExpressionData")
- public void testParseExpression(String expression, int value) {
- assertEquals(value, numberParser.parseExpression(expression));
+ private static final Stream<Arguments> testParseExpressionData() {
+ return IntStream.range(0, TEST_EXPRESSIONS.size())
+ .mapToObj(i -> Arguments.of(TEST_EXPRESSIONS.get(i), RESULTS[i]));
+ }
+
+ private static final Stream<Arguments> testParseRPN() {
+ return Stream.of(Arguments.of("1 2 5 ^ 3 * +", 97),
+ Arguments.of("1 2 + 5 ^ 3 *", 729),
+ Arguments.of("12 5 * 3 2 3 * ^ 72 - 3 3 2 * + / +", 133),
+ Arguments.of("1 2 + 3 + 4 +", 10), Arguments.of("12 4 - 3 -", 5),
+ Arguments.of("12 4 3 - -", 11), Arguments.of("1 2 / 3 +", 3),
+ Arguments.of("12", 12), Arguments.of("2 3 * 4 +", 10),
+ Arguments.of("2 3 * 4 -", 2), Arguments.of("2 3 4 + *", 14),
+ Arguments.of("2 3 4 - *", -2), Arguments.of("2 neg", -2),
+ Arguments.of("1 2 neg +", -1));
}
@ParameterizedTest
@@ -138,15 +124,25 @@ class ExpressionParserTest {
@ParameterizedTest
@MethodSource
- public void testParseRPN(String expressionRPN, int value) {
- assertEquals(value,
- numberParser.parseReversePolishExpression(expressionRPN));
+ public void testInvalidRPN(String expressionRPN) {
+ assertThrows(RuntimeException.class,
+ () -> numberParser.parseReversePolishExpression(expressionRPN));
+ }
+
+ /**
+ * Test method for
+ * {@link sevenUnits.utils.ExpressionParser#parseExpression(java.lang.String)}.
+ */
+ @ParameterizedTest
+ @MethodSource("testParseExpressionData")
+ public void testParseExpression(String expression, int value) {
+ assertEquals(value, numberParser.parseExpression(expression));
}
@ParameterizedTest
@MethodSource
- public void testInvalidRPN(String expressionRPN) {
- assertThrows(RuntimeException.class,
- () -> numberParser.parseReversePolishExpression(expressionRPN));
+ public void testParseRPN(String expressionRPN, int value) {
+ assertEquals(value,
+ numberParser.parseReversePolishExpression(expressionRPN));
}
}
diff --git a/src/test/java/sevenUnits/utils/NameSymbolTest.java b/src/test/java/sevenUnits/utils/NameSymbolTest.java
index 3ae2448..f8843e0 100644
--- a/src/test/java/sevenUnits/utils/NameSymbolTest.java
+++ b/src/test/java/sevenUnits/utils/NameSymbolTest.java
@@ -33,37 +33,65 @@ import org.junit.jupiter.params.provider.MethodSource;
/**
* Tests for the {@link NameSymbol} class.
- *
+ *
* @since v1.0.0
*/
class NameSymbolTest {
private static Stream<Arguments> testEqualsHashCode() {
return Stream.of(
- Arguments.of(NameSymbol.ofName("test"), NameSymbol.ofName("test"), true),
+ Arguments.of(NameSymbol.ofName("test"), NameSymbol.ofName("test"),
+ true),
Arguments.of(NameSymbol.ofName("a"), NameSymbol.ofName("b"), false),
- Arguments.of(NameSymbol.ofSymbol("test"), NameSymbol.ofSymbol("test"), true),
- Arguments.of(NameSymbol.ofSymbol("a"), NameSymbol.ofSymbol("b"), false),
- Arguments.of(NameSymbol.ofName("test"), NameSymbol.ofSymbol("test"), false),
- Arguments.of(NameSymbol.of("main", "s"), NameSymbol.of("main", "s"), true),
- Arguments.of(NameSymbol.of("main", "s"), NameSymbol.of("main", "s", "m"), false),
+ Arguments.of(NameSymbol.ofSymbol("test"),
+ NameSymbol.ofSymbol("test"), true),
+ Arguments.of(NameSymbol.ofSymbol("a"), NameSymbol.ofSymbol("b"),
+ false),
+ Arguments.of(NameSymbol.ofName("test"), NameSymbol.ofSymbol("test"),
+ false),
+ Arguments.of(NameSymbol.of("main", "s"), NameSymbol.of("main", "s"),
+ true),
+ Arguments.of(NameSymbol.of("main", "s"),
+ NameSymbol.of("main", "s", "m"), false),
Arguments.of(new NameSymbol(null, null, new HashSet<>()),
new NameSymbol(null, null, new HashSet<>()), true),
- Arguments.of(new NameSymbol(
- Optional.of("main"), Optional.of("s"), new HashSet<>()),
+ Arguments.of(
+ new NameSymbol(Optional.of("main"), Optional.of("s"),
+ new HashSet<>()),
new NameSymbol(null, null, new HashSet<>()), false),
Arguments.of(new NameSymbol(null, null, new HashSet<>()),
new NameSymbol(Optional.of("main"), Optional.of("s"),
- new HashSet<>()), false),
- Arguments.of(new NameSymbol(Optional.of("main"), null, new HashSet<>()),
+ new HashSet<>()),
+ false),
+ Arguments.of(
+ new NameSymbol(Optional.of("main"), null, new HashSet<>()),
new NameSymbol(Optional.of("main"), Optional.of("s"),
- new HashSet<>()), false));
+ new HashSet<>()),
+ false));
+ }
+
+ @Test
+ public void testCreate() {
+ final Set<String> names = Set.of("a", "b", "c");
+ final var ns = NameSymbol.ofNullable(null, null, names);
+ assertTrue(ns.getPrimaryName().isPresent(),
+ "NameSymbol created without primary name.");
+ assertTrue(names.contains(ns.getPrimaryName().orElseThrow()),
+ String.format("Primary name (%s) was not obtained from names set.",
+ ns.getPrimaryName()));
+ assertFalse(
+ ns.getOtherNames().contains(ns.getPrimaryName().orElseThrow()),
+ String.format("Primary name (%s) was included in other names set.",
+ ns.getPrimaryName()));
+ assertEquals(Set.of("a", "b", "c"), names,
+ "names input was changed by ofNullable()");
}
-
+
/**
- * Tests that two NameSymbols are or are not equal.
- * If they are equal, also ensures they have the same hash code.
- * @param a first NameSymbol to test
- * @param b second NameSymbol to test
+ * Tests that two NameSymbols are or are not equal. If they are equal, also
+ * ensures they have the same hash code.
+ *
+ * @param a first NameSymbol to test
+ * @param b second NameSymbol to test
* @param equal true iff a should be equal to be, otherwise false
*/
@ParameterizedTest
@@ -77,18 +105,4 @@ class NameSymbolTest {
assertFalse(Objects.equals(a, b));
}
}
-
- @Test
- public void testCreate() {
- Set<String> names = Set.of("a", "b", "c");
- NameSymbol ns = NameSymbol.ofNullable(null, null, names);
- assertTrue(ns.getPrimaryName().isPresent(), "NameSymbol created without primary name.");
- assertTrue(names.contains(ns.getPrimaryName().orElseThrow()),
- String.format("Primary name (%s) was not obtained from names set.",
- ns.getPrimaryName()));
- assertFalse(ns.getOtherNames().contains(ns.getPrimaryName().orElseThrow()),
- String.format("Primary name (%s) was included in other names set.",
- ns.getPrimaryName()));
- assertEquals(Set.of("a", "b", "c"), names, "names input was changed by ofNullable()");
- }
}
diff --git a/src/test/java/sevenUnits/utils/ObjectProductTest.java b/src/test/java/sevenUnits/utils/ObjectProductTest.java
index 584b3f3..7c5df88 100644
--- a/src/test/java/sevenUnits/utils/ObjectProductTest.java
+++ b/src/test/java/sevenUnits/utils/ObjectProductTest.java
@@ -34,7 +34,7 @@ import sevenUnits.unit.Metric;
/**
* Tests for {@link ObjectProduct} using BaseDimension as a test object. This is
* NOT part of this program's public API.
- *
+ *
* @author Adrien Hopkins
* @since 2018-12-12
* @since v0.1.0
@@ -42,7 +42,7 @@ import sevenUnits.unit.Metric;
class ObjectProductTest {
/**
* Tests {@link UnitDimension#equals}
- *
+ *
* @since 2018-12-12
* @since v0.1.0
*/
@@ -54,7 +54,7 @@ class ObjectProductTest {
/**
* Tests {@code UnitDimension}'s exponentiation
- *
+ *
* @since 2019-01-15
* @since v0.1.0
*/
@@ -66,7 +66,7 @@ class ObjectProductTest {
/**
* Tests {@code UnitDimension}'s multiplication and division.
- *
+ *
* @since 2018-12-12
* @since v0.1.0
*/
diff --git a/src/test/java/sevenUnits/utils/SemanticVersionTest.java b/src/test/java/sevenUnits/utils/SemanticVersionTest.java
index 3bef773..5b74812 100644
--- a/src/test/java/sevenUnits/utils/SemanticVersionTest.java
+++ b/src/test/java/sevenUnits/utils/SemanticVersionTest.java
@@ -40,7 +40,7 @@ import org.junit.jupiter.api.Test;
public final class SemanticVersionTest {
/**
* Test for {@link SemanticVersionNumber#compatible}
- *
+ *
* @since 2022-02-20
* @since v0.4.0
*/
@@ -66,40 +66,37 @@ public final class SemanticVersionTest {
/**
* Tests {@link SemanticVersionNumber#toString} for complex version numbers
- *
+ *
* @since 2022-02-19
* @since v0.4.0
*/
@Test
public void testComplexToString() {
- final SemanticVersionNumber v1 = builder(1, 2, 3).preRelease(1, 2, 3)
- .build();
+ final var v1 = builder(1, 2, 3).preRelease(1, 2, 3).build();
assertEquals("1.2.3-1.2.3", v1.toString());
- final SemanticVersionNumber v2 = builder(4, 5, 6).preRelease("abc", 123)
+ final var v2 = builder(4, 5, 6).preRelease("abc", 123)
.buildMetadata("2022-02-19").build();
assertEquals("4.5.6-abc.123+2022-02-19", v2.toString());
- final SemanticVersionNumber v3 = builder(1, 0, 0)
- .preRelease("x-y-z", "--").build();
+ final var v3 = builder(1, 0, 0).preRelease("x-y-z", "--").build();
assertEquals("1.0.0-x-y-z.--", v3.toString());
}
/**
* Tests that complex version can be created and their parts read
- *
+ *
* @since 2022-02-19
* @since v0.4.0
*/
@Test
public void testComplexVersions() {
- final SemanticVersionNumber v1 = builder(1, 2, 3).preRelease(1, 2, 3)
- .build();
+ final var v1 = builder(1, 2, 3).preRelease(1, 2, 3).build();
assertEquals(1, v1.majorVersion());
assertEquals(2, v1.minorVersion());
assertEquals(3, v1.patchVersion());
assertEquals(List.of("1", "2", "3"), v1.preReleaseIdentifiers());
assertEquals(List.of(), v1.buildMetadata());
- final SemanticVersionNumber v2 = builder(4, 5, 6).preRelease("abc", 123)
+ final var v2 = builder(4, 5, 6).preRelease("abc", 123)
.buildMetadata("2022-02-19").build();
assertEquals(4, v2.majorVersion());
assertEquals(5, v2.minorVersion());
@@ -107,8 +104,7 @@ public final class SemanticVersionTest {
assertEquals(List.of("abc", "123"), v2.preReleaseIdentifiers());
assertEquals(List.of("2022-02-19"), v2.buildMetadata());
- final SemanticVersionNumber v3 = builder(1, 0, 0)
- .preRelease("x-y-z", "--").build();
+ final var v3 = builder(1, 0, 0).preRelease("x-y-z", "--").build();
assertEquals(1, v3.majorVersion());
assertEquals(0, v3.minorVersion());
assertEquals(0, v3.patchVersion());
@@ -118,7 +114,7 @@ public final class SemanticVersionTest {
/**
* Test that semantic version strings can be parsed correctly
- *
+ *
* @since 2022-02-19
* @since v0.4.0
* @see SemanticVersionNumber#fromString
@@ -158,9 +154,7 @@ public final class SemanticVersionTest {
"Could not parse 1.2.3-abc.56.def+2022abc99");
}
- /**
- * Ensures it is impossible to create invalid version numbers
- */
+ /** Ensures it is impossible to create invalid version numbers */
@Test
public void testInvalidVersionNumbers() {
// stableVersion()
@@ -204,7 +198,7 @@ public final class SemanticVersionTest {
assertThrows(IllegalArgumentException.class, () -> builder(-3, 0, 7),
"Negative major version number tolerated by builder");
- final SemanticVersionNumber.Builder testBuilder = builder(1, 2, 3);
+ final var testBuilder = builder(1, 2, 3);
// note: builder.buildMetadata(null) doesn't even compile lol
// builder.buildMetadata
assertThrows(NullPointerException.class,
@@ -270,7 +264,7 @@ public final class SemanticVersionTest {
/**
* Test for {@link SemanticVersionNumber#isStable}
- *
+ *
* @since 2022-02-19
* @since v0.4.0
*/
@@ -294,30 +288,27 @@ public final class SemanticVersionTest {
* {@link SemanticVersionNumber#compareTo} according to official rules. Tests
* all of the versions compared in section 11 of the SemVer 2.0.0 document
* and some more.
- *
+ *
* @since 2022-02-19
* @since v0.4.0
*/
@Test
public void testOrder() {
- final SemanticVersionNumber v100a = builder(1, 0, 0).preRelease("alpha")
- .build(); // 1.0.0-alpha
- final SemanticVersionNumber v100a1 = preRelease(1, 0, 0, "alpha", 1); // 1.0.0-alpha.1
- final SemanticVersionNumber v100ab = builder(1, 0, 0)
- .preRelease("alpha", "beta").build(); // 1.0.0-alpha.beta
- final SemanticVersionNumber v100b = builder(1, 0, 0).preRelease("beta")
- .build(); // 1.0.0-alpha
- final SemanticVersionNumber v100b2 = preRelease(1, 0, 0, "beta", 2); // 1.0.0-beta.2
- final SemanticVersionNumber v100b11 = preRelease(1, 0, 0, "beta", 11); // 1.0.0-beta.11
- final SemanticVersionNumber v100rc1 = preRelease(1, 0, 0, "rc", 1); // 1.0.0-rc.1
- final SemanticVersionNumber v100 = stableVersion(1, 0, 0);
- final SemanticVersionNumber v100plus = builder(1, 0, 0)
+ final var v100a = builder(1, 0, 0).preRelease("alpha").build(); // 1.0.0-alpha
+ final var v100a1 = preRelease(1, 0, 0, "alpha", 1); // 1.0.0-alpha.1
+ final var v100ab = builder(1, 0, 0).preRelease("alpha", "beta").build(); // 1.0.0-alpha.beta
+ final var v100b = builder(1, 0, 0).preRelease("beta").build(); // 1.0.0-alpha
+ final var v100b2 = preRelease(1, 0, 0, "beta", 2); // 1.0.0-beta.2
+ final var v100b11 = preRelease(1, 0, 0, "beta", 11); // 1.0.0-beta.11
+ final var v100rc1 = preRelease(1, 0, 0, "rc", 1); // 1.0.0-rc.1
+ final var v100 = stableVersion(1, 0, 0);
+ final var v100plus = builder(1, 0, 0)
.buildMetadata("blah", "blah", "blah").build(); // 1.0.0+blah.blah.blah
- final SemanticVersionNumber v200 = stableVersion(2, 0, 0);
- final SemanticVersionNumber v201 = stableVersion(2, 0, 1);
- final SemanticVersionNumber v210 = stableVersion(2, 1, 0);
- final SemanticVersionNumber v211 = stableVersion(2, 1, 1);
- final SemanticVersionNumber v300 = stableVersion(3, 0, 0);
+ final var v200 = stableVersion(2, 0, 0);
+ final var v201 = stableVersion(2, 0, 1);
+ final var v210 = stableVersion(2, 1, 0);
+ final var v211 = stableVersion(2, 1, 1);
+ final var v300 = stableVersion(3, 0, 0);
// test order of version numbers
assertTrue(v100a.compareTo(v100a1) < 0, "1.0.0-alpha >= 1.0.0-alpha.1");
@@ -355,18 +346,18 @@ public final class SemanticVersionTest {
/**
* Tests that simple stable versions can be created and their parts read
- *
+ *
* @since 2022-02-19
* @since v0.4.0
*/
@Test
public void testSimpleStableVersions() {
- final SemanticVersionNumber v100 = stableVersion(1, 0, 0);
+ final var v100 = stableVersion(1, 0, 0);
assertEquals(1, v100.majorVersion());
assertEquals(0, v100.minorVersion());
assertEquals(0, v100.patchVersion());
- final SemanticVersionNumber v925 = stableVersion(9, 2, 5);
+ final var v925 = stableVersion(9, 2, 5);
assertEquals(9, v925.majorVersion());
assertEquals(2, v925.minorVersion());
assertEquals(5, v925.patchVersion());
@@ -375,28 +366,28 @@ public final class SemanticVersionTest {
/**
* Tests that {@link SemanticVersionNumber#toString} works for simple version
* numbers
- *
+ *
* @since 2022-02-19
* @since v0.4.0
*/
@Test
public void testSimpleToString() {
- final SemanticVersionNumber v100 = stableVersion(1, 0, 0);
+ final var v100 = stableVersion(1, 0, 0);
assertEquals("1.0.0", v100.toString());
- final SemanticVersionNumber v845a1 = preRelease(8, 4, 5, "alpha", 1);
+ final var v845a1 = preRelease(8, 4, 5, "alpha", 1);
assertEquals("8.4.5-alpha.1", v845a1.toString());
}
/**
* Tests that simple unstable versions can be created and their parts read
- *
+ *
* @since 2022-02-19
* @since v0.4.0
*/
@Test
public void testSimpleUnstableVersions() {
- final SemanticVersionNumber v350a1 = preRelease(3, 5, 0, "alpha", 1);
+ final var v350a1 = preRelease(3, 5, 0, "alpha", 1);
assertEquals(3, v350a1.majorVersion(),
"Incorrect major version for v3.5.0a1");
assertEquals(5, v350a1.minorVersion(),
diff --git a/src/test/java/sevenUnits/utils/UncertainDoubleTest.java b/src/test/java/sevenUnits/utils/UncertainDoubleTest.java
index 518c818..733a308 100644
--- a/src/test/java/sevenUnits/utils/UncertainDoubleTest.java
+++ b/src/test/java/sevenUnits/utils/UncertainDoubleTest.java
@@ -35,48 +35,41 @@ 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,
- 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);
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 +77,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());