summaryrefslogtreecommitdiff
path: root/src/test/java/sevenUnits/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/sevenUnits/utils')
-rw-r--r--src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java26
-rw-r--r--src/test/java/sevenUnits/utils/ExpressionParserTest.java19
-rw-r--r--src/test/java/sevenUnits/utils/ObjectProductTest.java3
-rw-r--r--src/test/java/sevenUnits/utils/SemanticVersionTest.java56
-rw-r--r--src/test/java/sevenUnits/utils/UncertainDoubleTest.java28
5 files changed, 66 insertions, 66 deletions
diff --git a/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java b/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java
index 6b5f9cf..868385b 100644
--- a/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java
+++ b/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java
@@ -43,7 +43,7 @@ import sevenUnits.utils.ConditionalExistenceCollections.ConditionalExistenceIter
* @since 2019-10-16
*/
class ConditionalExistenceCollectionsTest {
-
+
/**
* The returned iterator ignores elements that don't start with "a".
*
@@ -57,7 +57,7 @@ class ConditionalExistenceCollectionsTest {
.conditionalExistenceIterator(it, s -> s.startsWith("a"));
return cit;
}
-
+
/**
* The returned map ignores mappings where the value is zero.
*
@@ -75,7 +75,7 @@ class ConditionalExistenceCollectionsTest {
e -> !Integer.valueOf(0).equals(e.getValue()));
return conditionalMap;
}
-
+
/**
* Test method for the ConditionalExistenceMap's containsKey method.
*/
@@ -87,7 +87,7 @@ class ConditionalExistenceCollectionsTest {
assertFalse(map.containsKey("five"));
assertFalse(map.containsKey("zero"));
}
-
+
/**
* Test method for the ConditionalExistenceMap's containsValue method.
*/
@@ -99,7 +99,7 @@ class ConditionalExistenceCollectionsTest {
assertFalse(map.containsValue(5));
assertFalse(map.containsValue(0));
}
-
+
/**
* Test method for the ConditionalExistenceMap's entrySet method.
*/
@@ -110,7 +110,7 @@ class ConditionalExistenceCollectionsTest {
assertTrue(e.getValue() != 0);
}
}
-
+
/**
* Test method for the ConditionalExistenceMap's get method.
*/
@@ -122,7 +122,7 @@ class ConditionalExistenceCollectionsTest {
assertEquals(null, map.get("five"));
assertEquals(null, map.get("zero"));
}
-
+
/**
* Test method for the ConditionalExistenceCollection's iterator.
*/
@@ -130,23 +130,23 @@ class ConditionalExistenceCollectionsTest {
void testIterator() {
final ConditionalExistenceIterator<String> testIterator = this
.getTestIterator();
-
+
assertTrue(testIterator.hasNext);
assertTrue(testIterator.hasNext());
assertEquals("aa", testIterator.nextElement);
assertEquals("aa", testIterator.next());
-
+
assertTrue(testIterator.hasNext);
assertTrue(testIterator.hasNext());
assertEquals("ab", testIterator.nextElement);
assertEquals("ab", testIterator.next());
-
+
assertFalse(testIterator.hasNext);
assertFalse(testIterator.hasNext());
assertEquals(null, testIterator.nextElement);
assertThrows(NoSuchElementException.class, testIterator::next);
}
-
+
/**
* Test method for the ConditionalExistenceMap's keySet operation.
*/
@@ -155,7 +155,7 @@ class ConditionalExistenceCollectionsTest {
final Map<String, Integer> map = this.getTestMap();
assertFalse(map.keySet().contains("zero"));
}
-
+
/**
* Test method for the ConditionalExistenceMap's values operation.
*/
@@ -164,5 +164,5 @@ class ConditionalExistenceCollectionsTest {
final Map<String, Integer> map = this.getTestMap();
assertFalse(map.values().contains(0));
}
-
+
}
diff --git a/src/test/java/sevenUnits/utils/ExpressionParserTest.java b/src/test/java/sevenUnits/utils/ExpressionParserTest.java
index a954b12..3a95285 100644
--- a/src/test/java/sevenUnits/utils/ExpressionParserTest.java
+++ b/src/test/java/sevenUnits/utils/ExpressionParserTest.java
@@ -38,12 +38,11 @@ import org.junit.jupiter.params.provider.MethodSource;
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();
-
+ .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();
+
/**
* The expressions used in the expression parsing tests
*/
@@ -51,15 +50,15 @@ class ExpressionParserTest {
// test parsing of expressions
"1 + 2 ^ 5 * 3", "(1 + 2) ^ 5 * 3",
"12 * 5 + (3 ^ (2 * 3) - 72) / (3 + 3 * 2)",
-
+
// 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
*/
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
@@ -69,7 +68,7 @@ class ExpressionParserTest {
return IntStream.range(0, TEST_EXPRESSIONS.size())
.mapToObj(i -> Arguments.of(TEST_EXPRESSIONS.get(i), RESULTS[i]));
}
-
+
/**
* Test method for
* {@link sevenUnits.utils.ExpressionParser#parseExpression(java.lang.String)}.
diff --git a/src/test/java/sevenUnits/utils/ObjectProductTest.java b/src/test/java/sevenUnits/utils/ObjectProductTest.java
index 15ff277..8c6b353 100644
--- a/src/test/java/sevenUnits/utils/ObjectProductTest.java
+++ b/src/test/java/sevenUnits/utils/ObjectProductTest.java
@@ -32,7 +32,8 @@ import org.junit.jupiter.api.Test;
import sevenUnits.unit.Metric;
/**
- * Tests for {@link ObjectProduct} using BaseDimension as a test object. This is NOT part of this program's public API.
+ * 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
diff --git a/src/test/java/sevenUnits/utils/SemanticVersionTest.java b/src/test/java/sevenUnits/utils/SemanticVersionTest.java
index 877b258..1e59ae3 100644
--- a/src/test/java/sevenUnits/utils/SemanticVersionTest.java
+++ b/src/test/java/sevenUnits/utils/SemanticVersionTest.java
@@ -48,20 +48,20 @@ public final class SemanticVersionTest {
"1.0.0 not compatible with 1.0.5");
assertTrue(stableVersion(1, 3, 1).compatibleWith(stableVersion(1, 4, 0)),
"1.3.1 not compatible with 1.4.0");
-
+
// 0.y.z should not be compatible with any other version
assertFalse(stableVersion(0, 4, 0).compatibleWith(stableVersion(0, 4, 1)),
"0.4.0 compatible with 0.4.1 (0.y.z versions should be treated as unstable/incompatbile)");
-
+
// upgrading major version should = incompatible
assertFalse(stableVersion(1, 0, 0).compatibleWith(stableVersion(2, 0, 0)),
"1.0.0 compatible with 2.0.0");
-
+
// dowgrade should = incompatible
assertFalse(stableVersion(1, 1, 0).compatibleWith(stableVersion(1, 0, 0)),
"1.1.0 compatible with 1.0.0");
}
-
+
/**
* Tests {@link SemanticVersionNumber#toString} for complex version numbers
*
@@ -79,7 +79,7 @@ public final class SemanticVersionTest {
.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
*
@@ -94,7 +94,7 @@ public final class SemanticVersionTest {
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)
.buildMetadata("2022-02-19").build();
assertEquals(4, v2.majorVersion());
@@ -102,7 +102,7 @@ public final class SemanticVersionTest {
assertEquals(6, v2.patchVersion());
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();
assertEquals(1, v3.majorVersion());
@@ -111,7 +111,7 @@ public final class SemanticVersionTest {
assertEquals(List.of("x-y-z", "--"), v3.preReleaseIdentifiers());
assertEquals(List.of(), v3.buildMetadata());
}
-
+
/**
* Test that semantic version strings can be parsed correctly
*
@@ -132,7 +132,7 @@ public final class SemanticVersionTest {
"1.0.0+abc is treated as invalid");
assertTrue(isValidVersionString("1.0.0-abc+def"),
"1.0.0-abc+def is treated as invalid");
-
+
// test that invalid versions don't match
assertFalse(isValidVersionString("1.0"),
"1.0 is treated as valid (patch should be required)");
@@ -142,7 +142,7 @@ public final class SemanticVersionTest {
"1.0.0- is treated as valid (pre-release must not be empty)");
assertFalse(isValidVersionString("1.0.0+"),
"1.0.0+ is treated as valid (build metadata must not be empty)");
-
+
// test that versions can be parsed
assertEquals(stableVersion(1, 0, 0), fromString("1.0.0"),
"Could not parse 1.0.0");
@@ -152,7 +152,7 @@ public final class SemanticVersionTest {
fromString("1.2.3-abc.56.def+2022abc99"),
"Could not parse 1.2.3-abc.56.def+2022abc99");
}
-
+
/**
* Ensures it is impossible to create invalid version numbers
*/
@@ -168,7 +168,7 @@ public final class SemanticVersionTest {
assertThrows(IllegalArgumentException.class,
() -> stableVersion(-3, 0, 7),
"Negative major version number tolerated by stableVersion");
-
+
// preRelease()
assertThrows(IllegalArgumentException.class,
() -> preRelease(1, 0, -1, "test", 2),
@@ -190,7 +190,7 @@ public final class SemanticVersionTest {
assertThrows(IllegalArgumentException.class,
() -> preRelease(1, 0, 0, "abc+cde", 1),
"Invalid string tolerated by preRelease");
-
+
// builder()
assertThrows(IllegalArgumentException.class, () -> builder(1, 0, -1),
"Negative patch tolerated by builder");
@@ -198,7 +198,7 @@ public final class SemanticVersionTest {
"Negative minor version number tolerated by builder");
assertThrows(IllegalArgumentException.class, () -> builder(-3, 0, 7),
"Negative major version number tolerated by builder");
-
+
final SemanticVersionNumber.Builder testBuilder = builder(1, 2, 3);
// note: builder.buildMetadata(null) doesn't even compile lol
// builder.buildMetadata
@@ -220,7 +220,7 @@ public final class SemanticVersionTest {
assertThrows(IllegalArgumentException.class,
() -> testBuilder.buildMetadata(List.of("")),
"Invalid string tolerated by builder.buildMetadata(List<String>)");
-
+
// builder.preRelease
assertThrows(NullPointerException.class,
() -> testBuilder.preRelease(null, "abc"),
@@ -240,7 +240,7 @@ public final class SemanticVersionTest {
assertThrows(IllegalArgumentException.class,
() -> testBuilder.preRelease(List.of("")),
"Invalid string tolerated by builder.preRelease(List<String>)");
-
+
// the overloadings that accept numeric arguments
assertThrows(IllegalArgumentException.class,
() -> testBuilder.preRelease(-1),
@@ -257,12 +257,12 @@ public final class SemanticVersionTest {
assertThrows(IllegalArgumentException.class,
() -> testBuilder.preRelease("#$#c", 1),
"Invalid string tolerated by builder.preRelease(String, int)");
-
+
// ensure all these attempts didn't change the builder
assertEquals(builder(1, 2, 3), testBuilder,
"Attempts at making invalid version number succeeded despite throwing errors");
}
-
+
/**
* Test for {@link SemanticVersionNumber#isStable}
*
@@ -282,7 +282,7 @@ public final class SemanticVersionTest {
.isStable(),
"9.9.99+lots-of-metadata.abc123.2022 should be stable but is not");
}
-
+
/**
* Tests that the versions are ordered by
* {@link SemanticVersionNumber#compareTo} according to official rules. Tests
@@ -311,7 +311,7 @@ public final class SemanticVersionTest {
final SemanticVersionNumber v210 = stableVersion(2, 1, 0);
final SemanticVersionNumber v211 = stableVersion(2, 1, 1);
final SemanticVersionNumber v300 = stableVersion(3, 0, 0);
-
+
// test order of version numbers
assertTrue(v100a.compareTo(v100a1) < 0, "1.0.0-alpha >= 1.0.0-alpha.1");
assertTrue(v100a1.compareTo(v100ab) < 0,
@@ -327,25 +327,25 @@ public final class SemanticVersionTest {
assertTrue(v201.compareTo(v210) < 0, "2.0.1 >= 2.1.0");
assertTrue(v210.compareTo(v211) < 0, "2.1.0 >= 2.1.1");
assertTrue(v211.compareTo(v300) < 0, "2.1.1 >= 3.0.0");
-
+
// test symmetry - assume previous tests passed
assertTrue(v100a1.compareTo(v100a) > 0, "1.0.0-alpha.1 <= 1.0.0-alpha");
assertTrue(v100.compareTo(v100rc1) > 0, "1.0.0 <= 1.0.0-rc.1");
assertTrue(v300.compareTo(v211) > 0, "3.0.0 <= 2.1.1");
-
+
// test transitivity
assertTrue(v100a.compareTo(v100b11) < 0, "1.0.0-alpha >= 1.0.0-beta.11");
assertTrue(v100b.compareTo(v200) < 0, "1.0.0-beta >= 2.0.0");
assertTrue(v100.compareTo(v300) < 0, "1.0.0 >= 3.0.0");
assertTrue(v100a.compareTo(v300) < 0, "1.0.0-alpha >= 3.0.0");
-
+
// test metadata is ignored
assertEquals(0, v100.compareTo(v100plus), "Build metadata not ignored");
// test metadata is NOT ignored by alternative comparator
assertTrue(BUILD_METADATA_COMPARATOR.compare(v100, v100plus) > 0,
"Build metadata ignored by BUILD_METADATA_COMPARATOR");
}
-
+
/**
* Tests that simple stable versions can be created and their parts read
*
@@ -357,13 +357,13 @@ public final class SemanticVersionTest {
assertEquals(1, v100.majorVersion());
assertEquals(0, v100.minorVersion());
assertEquals(0, v100.patchVersion());
-
+
final SemanticVersionNumber v925 = stableVersion(9, 2, 5);
assertEquals(9, v925.majorVersion());
assertEquals(2, v925.minorVersion());
assertEquals(5, v925.patchVersion());
}
-
+
/**
* Tests that {@link SemanticVersionNumber#toString} works for simple version
* numbers
@@ -374,11 +374,11 @@ public final class SemanticVersionTest {
public void testSimpleToString() {
final SemanticVersionNumber v100 = stableVersion(1, 0, 0);
assertEquals("1.0.0", v100.toString());
-
+
final SemanticVersionNumber 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
*
diff --git a/src/test/java/sevenUnits/utils/UncertainDoubleTest.java b/src/test/java/sevenUnits/utils/UncertainDoubleTest.java
index 5ccef28..36b373b 100644
--- a/src/test/java/sevenUnits/utils/UncertainDoubleTest.java
+++ b/src/test/java/sevenUnits/utils/UncertainDoubleTest.java
@@ -43,36 +43,36 @@ class UncertainDoubleTest {
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
*/
@Test
final void testExactOperations() {
final UncertainDouble 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);
-
+
// get results
final UncertainDouble result1 = x.plusExact(Math.E).minusExact(Math.E);
final UncertainDouble 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}
*
@@ -82,29 +82,29 @@ class UncertainDoubleTest {
final void testFromRoundedString() {
assertEquals(of(12345.678, 0.001), fromRoundedString("12345.678"));
}
-
+
/**
* 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());
}
}