summaryrefslogtreecommitdiff
path: root/src/test/java/sevenUnits/utils
diff options
context:
space:
mode:
authorAdrien Hopkins <adrien.p.hopkins@gmail.com>2025-06-15 19:42:01 -0500
committerAdrien Hopkins <adrien.p.hopkins@gmail.com>2025-06-15 19:42:01 -0500
commit2fdbc084fd1d78f0b7633db34460b1195de264f3 (patch)
tree4c908950d9b049394f8160b8159b498aec586ecc /src/test/java/sevenUnits/utils
parented53492243ecad8d975401a97f5b634328ad2c71 (diff)
parentbccb5b5e3452421c81c1fb58f83391ba6584807c (diff)
Merge release 1.0.0 into stable branchHEADstable
See the tag 'v1.0.0' or the changelog for more information about this release.
Diffstat (limited to 'src/test/java/sevenUnits/utils')
-rw-r--r--src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java63
-rw-r--r--src/test/java/sevenUnits/utils/ExpressionParserTest.java91
-rw-r--r--src/test/java/sevenUnits/utils/NameSymbolTest.java108
-rw-r--r--src/test/java/sevenUnits/utils/ObjectProductTest.java10
-rw-r--r--src/test/java/sevenUnits/utils/SemanticVersionTest.java93
-rw-r--r--src/test/java/sevenUnits/utils/UncertainDoubleTest.java39
6 files changed, 280 insertions, 124 deletions
diff --git a/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java b/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java
index 868385b..8711847 100644
--- a/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java
+++ b/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2019 Adrien Hopkins
+ * Copyright (C) 2019, 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
@@ -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,31 +37,34 @@ 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
*/
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
*/
Map<String, Integer> getTestMap() {
final Map<String, Integer> map = new HashMap<>();
@@ -76,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());
@@ -147,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 3a95285..2e0b4b0 100644
--- a/src/test/java/sevenUnits/utils/ExpressionParserTest.java
+++ b/src/test/java/sevenUnits/utils/ExpressionParserTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2019 Adrien Hopkins
+ * Copyright (C) 2019, 2021, 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
@@ -17,6 +17,7 @@
package sevenUnits.utils;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.List;
import java.util.stream.IntStream;
@@ -26,11 +27,10 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
-// TODO add tests for expression-to-RPN and RPN-to-result
/**
* 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
@@ -39,13 +39,13 @@ class ExpressionParserTest {
private static final ExpressionParser<Integer> numberParser = new ExpressionParser.Builder<>(
Integer::parseInt).addBinaryOperator("+", (o1, o2) -> o1 + o2, 0)
.addBinaryOperator("-", (o1, o2) -> o1 - o2, 0)
- .addBinaryOperator("*", (o1, o2) -> o1 * o2, 1)
- .addBinaryOperator("/", (o1, o2) -> o1 / o2, 1)
- .addBinaryOperator("^", (o1, o2) -> (int) Math.pow(o1, o2), 2).build();
+ .addUnaryOperator("neg", o1 -> -o1, 1)
+ .addBinaryOperator("*", (o1, o2) -> o1 * o2, 2)
+ .addBinaryOperator("/", (o1, o2) -> o1 / o2, 2)
+ .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",
@@ -54,21 +54,81 @@ 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 };
+ 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 *"),
+ Arguments.of("12 * 5 + (3 ^ (2 * 3) - 72) / (3 + 3 * 2)",
+ "12 5 * 3 2 3 * ^ 72 - 3 3 2 * + / +"),
+ Arguments.of("1 + 2 + 3 + 4", "1 2 + 3 + 4 +"),
+ Arguments.of("12 - 4 - 3", "12 4 - 3 -"),
+ Arguments.of("12 - (4 - 3)", "12 4 3 - -"),
+ Arguments.of("1 / 2 + 3", "1 2 / 3 +"), Arguments.of("12", "12"),
+ Arguments.of("2 * 3 + 4", "2 3 * 4 +"),
+ Arguments.of("(2 * 3) + 4", "2 3 * 4 +"),
+ Arguments.of("2 * 3 - 4", "2 3 * 4 -"),
+ Arguments.of("(2 * 3) - 4", "2 3 * 4 -"),
+ Arguments.of("2 * (3 + 4)", "2 3 4 + *"),
+ Arguments.of("2 * (3 - 4)", "2 3 4 - *"),
+ Arguments.of("neg 2", "2 neg"),
+ Arguments.of("1 + neg 2", "1 2 neg +"));
+ }
+
+ private static final Stream<String> testInvalidExpression() {
+ return Stream.of("+", "1 +", "1 + * 2", "1 (+ 1)", "neg");
+ }
+
+ private static final Stream<String> testInvalidRPN() {
+ return Stream.of("+", "1 +", "1 + * 2", "1 * 2", "1 2", "neg");
+ }
+
/**
* @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> 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
+ @MethodSource
+ public void testConvertExpressionToRPN(String expression,
+ String expectedRPN) {
+ assertEquals(expectedRPN,
+ numberParser.convertExpressionToReversePolish(expression));
+ }
+
+ @ParameterizedTest
+ @MethodSource
+ public void testInvalidExpression(String expression) {
+ assertThrows(RuntimeException.class,
+ () -> numberParser.convertExpressionToReversePolish(expression));
+ }
+
+ @ParameterizedTest
+ @MethodSource
+ public void testInvalidRPN(String expressionRPN) {
+ assertThrows(RuntimeException.class,
+ () -> numberParser.parseReversePolishExpression(expressionRPN));
+ }
+
/**
* Test method for
* {@link sevenUnits.utils.ExpressionParser#parseExpression(java.lang.String)}.
@@ -78,4 +138,11 @@ class ExpressionParserTest {
public void testParseExpression(String expression, int value) {
assertEquals(value, numberParser.parseExpression(expression));
}
+
+ @ParameterizedTest
+ @MethodSource
+ 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
new file mode 100644
index 0000000..f8843e0
--- /dev/null
+++ b/src/test/java/sevenUnits/utils/NameSymbolTest.java
@@ -0,0 +1,108 @@
+/**
+ * Copyright (C) 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+package sevenUnits.utils;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+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("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(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<>()),
+ 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 NameSymbol(Optional.of("main"), Optional.of("s"),
+ 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
+ * @param equal true iff a should be equal to be, otherwise false
+ */
+ @ParameterizedTest
+ @MethodSource
+ public void testEqualsHashCode(NameSymbol a, NameSymbol b, boolean equal) {
+ if (equal) {
+ assertTrue(Objects.equals(a, b));
+ assertEquals(a.hashCode(), b.hashCode(),
+ "Equal NameSymbol instances have different hash codes.");
+ } else {
+ assertFalse(Objects.equals(a, b));
+ }
+ }
+}
diff --git a/src/test/java/sevenUnits/utils/ObjectProductTest.java b/src/test/java/sevenUnits/utils/ObjectProductTest.java
index 8c6b353..7c5df88 100644
--- a/src/test/java/sevenUnits/utils/ObjectProductTest.java
+++ b/src/test/java/sevenUnits/utils/ObjectProductTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2018 Adrien Hopkins
+ * Copyright (C) 2018, 2021, 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
@@ -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 1e59ae3..5b74812 100644
--- a/src/test/java/sevenUnits/utils/SemanticVersionTest.java
+++ b/src/test/java/sevenUnits/utils/SemanticVersionTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2022 Adrien Hopkins
+ * Copyright (C) 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
@@ -35,12 +35,14 @@ import org.junit.jupiter.api.Test;
* Tests for {@link SemanticVersionNumber}
*
* @since 2022-02-19
+ * @since v0.4.0
*/
public final class SemanticVersionTest {
/**
* Test for {@link SemanticVersionNumber#compatible}
- *
+ *
* @since 2022-02-20
+ * @since v0.4.0
*/
@Test
public void testCompatibility() {
@@ -64,38 +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());
@@ -103,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());
@@ -114,8 +114,9 @@ public final class SemanticVersionTest {
/**
* Test that semantic version strings can be parsed correctly
- *
+ *
* @since 2022-02-19
+ * @since v0.4.0
* @see SemanticVersionNumber#fromString
* @see SemanticVersionNumber#isValidVersionString
*/
@@ -153,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()
@@ -199,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,
@@ -265,8 +264,9 @@ public final class SemanticVersionTest {
/**
* Test for {@link SemanticVersionNumber#isStable}
- *
+ *
* @since 2022-02-19
+ * @since v0.4.0
*/
@Test
public void testIsStable() {
@@ -288,29 +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");
@@ -348,17 +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());
@@ -367,26 +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 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());
}
}