summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/sevenUnits/unit/UnitDatabaseTest.java45
-rw-r--r--src/test/java/sevenUnits/unit/UnitTest.java106
-rw-r--r--src/test/java/sevenUnits/unit/UnitValueTest.java2
-rw-r--r--src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java57
-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.java74
-rw-r--r--src/test/java/sevenUnits/utils/UncertainDoubleTest.java44
-rw-r--r--src/test/java/sevenUnitsGUI/I18nTest.java37
-rw-r--r--src/test/java/sevenUnitsGUI/PrefixRepetitionTest.java8
-rw-r--r--src/test/java/sevenUnitsGUI/PrefixSearchTest.java16
-rw-r--r--src/test/java/sevenUnitsGUI/RoundingTest.java10
-rw-r--r--src/test/java/sevenUnitsGUI/TabbedViewTest.java28
14 files changed, 282 insertions, 309 deletions
diff --git a/src/test/java/sevenUnits/unit/UnitDatabaseTest.java b/src/test/java/sevenUnits/unit/UnitDatabaseTest.java
index 800d13d..3d6d663 100644
--- a/src/test/java/sevenUnits/unit/UnitDatabaseTest.java
+++ b/src/test/java/sevenUnits/unit/UnitDatabaseTest.java
@@ -58,7 +58,6 @@ class UnitDatabaseTest {
private V value;
/**
- *
* @since 2021-10-07
* @since v0.3.2
*/
@@ -190,7 +189,7 @@ class UnitDatabaseTest {
}
private static final Stream<Arguments> testEvaluateExpressionValid() {
- UncertainDouble uncertainTwoThirds = UncertainDouble.of(2.0, 1.0)
+ final var uncertainTwoThirds = UncertainDouble.of(2.0, 1.0)
.dividedBy(UncertainDouble.of(3.0, 1.0));
return Stream.of(
Arguments.of("J + (2 * 3) J + (20 / 4) J",
@@ -206,19 +205,14 @@ class UnitDatabaseTest {
Arguments.of("2 J / 3 J",
LinearUnitValue.of(J.dividedBy(J), uncertainTwoThirds)));
}
-
+
private static final Stream<Arguments> testFormatExpression() {
- return Stream.of(
- Arguments.of("1*2", "1 * 2"),
- Arguments.of("1/2", "1 / 2"),
- Arguments.of("1|2", "1 | 2"),
- Arguments.of("1^2", "1 ^ 2"),
- Arguments.of("1 * 2", "1 * 2"),
- Arguments.of("+1", "+1"),
- Arguments.of("-1", "-1"),
+ return Stream.of(Arguments.of("1*2", "1 * 2"),
+ Arguments.of("1/2", "1 / 2"), Arguments.of("1|2", "1 | 2"),
+ Arguments.of("1^2", "1 ^ 2"), Arguments.of("1 * 2", "1 * 2"),
+ Arguments.of("+1", "+1"), Arguments.of("-1", "-1"),
Arguments.of("1.1e+5", "1.1e+5"),
- Arguments.of("1.25e-5", "1.25e-5")
- );
+ Arguments.of("1.25e-5", "1.25e-5"));
}
/**
@@ -266,15 +260,14 @@ class UnitDatabaseTest {
database.addPrefix("B", B);
database.addPrefix("C", C);
- final var actual = database
- .evaluateUnitExpression(expression);
+ final var actual = database.evaluateUnitExpression(expression);
assertEquals(expected, actual);
final var expectedU = expected.getUnit().times(expected.getValueExact());
final var actualU = database.getUnitFromExpression(expression);
assertEquals(expectedU, actualU);
}
-
+
@ParameterizedTest
@MethodSource
public void testFormatExpression(String expression, String expected) {
@@ -335,8 +328,7 @@ class UnitDatabaseTest {
infiniteDatabase.addPrefix("B", B);
infiniteDatabase.addPrefix("C", C);
- final var entrySet = infiniteDatabase.unitMap()
- .entrySet();
+ final var entrySet = infiniteDatabase.unitMap().entrySet();
final var keySet = infiniteDatabase.unitMap().keySet();
assertThrows(IllegalStateException.class, () -> entrySet.toArray());
assertThrows(IllegalStateException.class, () -> keySet.toArray());
@@ -376,8 +368,7 @@ class UnitDatabaseTest {
@ValueSource(ints = { 1, 2, 3, 4, 5 })
public void testLoadingInvalidUnitFile(int num) {
final var database = new UnitDatabase();
- final var filename = String.format("/test-unitsfile-invalid%d.txt",
- num);
+ final var filename = String.format("/test-unitsfile-invalid%d.txt", num);
final var errs = loadUnitsFile(database, filename);
assertFalse(errs.isEmpty(), "no error from invalid file " + filename);
final var e = errs.get(0).problem();
@@ -418,7 +409,7 @@ class UnitDatabaseTest {
assertEquals(7, database.getPrefix("A").getMultiplier());
assertEquals(11, database.getPrefix("B").getMultiplier());
assertEquals(13, database.getPrefix("C").getMultiplier());
-
+
// test invalid prefixes
assertThrows(NoSuchElementException.class,
() -> database.getPrefix("N/A"));
@@ -487,8 +478,7 @@ class UnitDatabaseTest {
final var map1 = database1.unitMap();
final var keyIterator1 = map1.keySet().iterator();
- final var entryIterator1 = map1.entrySet()
- .iterator();
+ final var entryIterator1 = map1.entrySet().iterator();
final Set<String> expectedKeys = Set.of("U", "V", "W");
final Set<String> actualKeys = new HashSet<>();
@@ -552,8 +542,7 @@ class UnitDatabaseTest {
@Test
public void testPrefixlessUnitMap() {
final var database = new UnitDatabase();
- final var prefixlessUnits = database
- .unitMapPrefixless(true);
+ final var prefixlessUnits = database.unitMapPrefixless(true);
database.addUnit("U", U);
database.addUnit("V", V);
@@ -690,10 +679,8 @@ class UnitDatabaseTest {
final var NUM_UNITS = database.unitMapPrefixless(true).size();
final var NUM_PREFIXES = database.prefixMap(true).size();
- final var nameIterator = database.unitMap().keySet()
- .iterator();
- final var entryIterator = database.unitMap()
- .entrySet().iterator();
+ final var nameIterator = database.unitMap().keySet().iterator();
+ final var entryIterator = database.unitMap().entrySet().iterator();
var expectedLength = 1;
var unitsWithThisLengthSoFar = 0;
diff --git a/src/test/java/sevenUnits/unit/UnitTest.java b/src/test/java/sevenUnits/unit/UnitTest.java
index 4d9a103..7ae550f 100644
--- a/src/test/java/sevenUnits/unit/UnitTest.java
+++ b/src/test/java/sevenUnits/unit/UnitTest.java
@@ -32,7 +32,7 @@ import sevenUnits.utils.NameSymbol;
/**
* Testing the various Unit classes. This is NOT part of this program's public
* API.
- *
+ *
* @author Adrien Hopkins
* @since 2018-12-22
* @since v0.1.0
@@ -40,119 +40,121 @@ import sevenUnits.utils.NameSymbol;
class UnitTest {
/** A random number generator */
private static final Random rng = ThreadLocalRandom.current();
-
+
@Test
public void testAdditionAndSubtraction() {
- final LinearUnit inch = Metric.METRE.times(0.0254)
+ final var inch = Metric.METRE.times(0.0254)
.withName(NameSymbol.of("inch", "in"));
- final LinearUnit foot = Metric.METRE.times(0.3048)
+ final var foot = Metric.METRE.times(0.3048)
.withName(NameSymbol.of("foot", "ft"));
-
- assertTrue(inch.plus(foot).equalsApproximately(Metric.METRE.times(0.3302)),
- String.format("Expected: %s, Actual: %s",
- inch.plus(foot), Metric.METRE.times(0.3302)));
- assertTrue(foot.minus(inch).equalsApproximately(Metric.METRE.times(0.2794)),
- String.format("Expected: %s, Actual: %s",
- foot.minus(inch), Metric.METRE.times(0.2794)));
-
+
+ assertTrue(
+ inch.plus(foot).equalsApproximately(Metric.METRE.times(0.3302)),
+ String.format("Expected: %s, Actual: %s", inch.plus(foot),
+ Metric.METRE.times(0.3302)));
+ assertTrue(
+ foot.minus(inch).equalsApproximately(Metric.METRE.times(0.2794)),
+ String.format("Expected: %s, Actual: %s", foot.minus(inch),
+ Metric.METRE.times(0.2794)));
+
// test with LinearUnitValue
- final LinearUnitValue value1 = LinearUnitValue.getExact(Metric.METRE, 15);
- final LinearUnitValue value2 = LinearUnitValue.getExact(foot, 120);
- final LinearUnitValue value3 = LinearUnitValue.getExact(Metric.METRE,
+ final var value1 = LinearUnitValue.getExact(Metric.METRE, 15);
+ final var value2 = LinearUnitValue.getExact(foot, 120);
+ final var value3 = LinearUnitValue.getExact(Metric.METRE,
0.5);
- final LinearUnitValue value4 = LinearUnitValue.getExact(Metric.KILOGRAM,
+ final var value4 = LinearUnitValue.getExact(Metric.KILOGRAM,
60);
-
+
// make sure addition is done correctly
assertEquals(51.576, value1.plus(value2).getValueExact(), 0.001);
assertEquals(15.5, value1.plus(value3).getValueExact());
assertEquals(52.076, value1.plus(value2).plus(value3).getValueExact(),
0.001);
-
+
// make sure addition uses the correct unit, and is still associative
// (ignoring floating-point rounding errors)
assertEquals(Metric.METRE, value1.plus(value2).getUnit());
assertEquals(Metric.METRE, value1.plus(value2).plus(value3).getUnit());
assertEquals(foot, value2.plus(value1).getUnit());
assertTrue(value1.plus(value2).equals(value2.plus(value1), true));
-
+
// make sure errors happen when they should
assertThrows(IllegalArgumentException.class, () -> value1.plus(value4));
assertThrows(IllegalArgumentException.class, () -> value1.minus(value4));
}
-
+
@Test
public void testConversion() {
- final LinearUnit metre = Metric.METRE;
+ final var metre = Metric.METRE;
final Unit inch = metre.times(0.0254);
-
- final UnitValue value = UnitValue.of(inch, 75);
-
+
+ final var value = UnitValue.of(inch, 75);
+
assertEquals(1.9, inch.convertTo(metre, 75), 0.01);
assertEquals(1.9, value.convertTo(metre).getValue(), 0.01);
-
+
// try random stuff
- for (int i = 0; i < 1000; i++) {
+ for (var i = 0; i < 1000; i++) {
// initiate random values
- final double conversionFactor = UnitTest.rng.nextDouble() * 1000000;
- final double testValue = UnitTest.rng.nextDouble() * 1000000;
- final double expected = testValue * conversionFactor;
-
+ final var conversionFactor = UnitTest.rng.nextDouble() * 1000000;
+ final var testValue = UnitTest.rng.nextDouble() * 1000000;
+ final var expected = testValue * conversionFactor;
+
// test
final Unit unit = Metric.METRE.times(conversionFactor);
- final double actual = unit.convertToBase(testValue);
-
+ final var actual = unit.convertToBase(testValue);
+
assertEquals(actual, expected,
expected * DecimalComparison.DOUBLE_EPSILON);
}
}
-
+
@Test
public void testEquals() {
- final LinearUnit metre = Metric.METRE;
+ final var metre = Metric.METRE;
final Unit meter = Metric.BaseUnits.METRE.asLinearUnit();
-
+
assertEquals(metre, meter);
}
-
+
@Test
public void testIsMetric() {
final Unit metre = Metric.METRE;
final Unit megasecond = Metric.SECOND.withPrefix(Metric.MEGA);
final Unit hour = Metric.HOUR;
-
+
assertTrue(metre.isMetric());
assertTrue(megasecond.isMetric());
assertFalse(hour.isMetric());
}
-
+
@Test
public void testMultiplicationAndDivision() {
// test unit-times-unit multiplication
- final LinearUnit generatedJoule = Metric.KILOGRAM
+ final var generatedJoule = Metric.KILOGRAM
.times(Metric.METRE.toExponent(2))
.dividedBy(Metric.SECOND.toExponent(2));
- final LinearUnit actualJoule = Metric.JOULE;
-
+ final var actualJoule = Metric.JOULE;
+
assertEquals(generatedJoule, actualJoule);
-
+
// test multiplication by conversion factors
- final LinearUnit kilometre = Metric.METRE.times(1000);
- final LinearUnit hour = Metric.SECOND.times(3600);
- final LinearUnit generatedKPH = kilometre.dividedBy(hour);
-
- final LinearUnit actualKPH = Metric.METRE.dividedBy(Metric.SECOND)
+ final var kilometre = Metric.METRE.times(1000);
+ final var hour = Metric.SECOND.times(3600);
+ final var generatedKPH = kilometre.dividedBy(hour);
+
+ final var actualKPH = Metric.METRE.dividedBy(Metric.SECOND)
.dividedBy(3.6);
-
+
assertEquals(generatedKPH, actualKPH);
}
-
+
@Test
public void testPrefixes() {
- final LinearUnit generatedKilometre = Metric.METRE
+ final var generatedKilometre = Metric.METRE
.withPrefix(Metric.KILO);
- final LinearUnit actualKilometre = Metric.METRE.times(1000);
-
+ final var actualKilometre = Metric.METRE.times(1000);
+
assertEquals(generatedKilometre, actualKilometre);
}
}
diff --git a/src/test/java/sevenUnits/unit/UnitValueTest.java b/src/test/java/sevenUnits/unit/UnitValueTest.java
index 6182b20..3679703 100644
--- a/src/test/java/sevenUnits/unit/UnitValueTest.java
+++ b/src/test/java/sevenUnits/unit/UnitValueTest.java
@@ -36,7 +36,7 @@ import sevenUnits.utils.UncertainDouble;
/**
* Tests for the UnitValue and LinearUnitValue classes
- *
+ *
* @since v1.0.0
*/
public final class UnitValueTest {
diff --git a/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java b/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java
index ea96574..f203fad 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,59 +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
+ final var testIterator = this
.getTestIterator();
assertTrue(testIterator.hasNext);
@@ -150,22 +139,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..047f0b5 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,32 +66,32 @@ 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)
+ 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)
+ 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)
+ final var v1 = builder(1, 2, 3).preRelease(1, 2, 3)
.build();
assertEquals(1, v1.majorVersion());
assertEquals(2, v1.minorVersion());
@@ -99,7 +99,7 @@ public final class SemanticVersionTest {
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,7 +107,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)
+ final var v3 = builder(1, 0, 0)
.preRelease("x-y-z", "--").build();
assertEquals(1, v3.majorVersion());
assertEquals(0, v3.minorVersion());
@@ -118,7 +118,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 +158,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 +202,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 +268,7 @@ public final class SemanticVersionTest {
/**
* Test for {@link SemanticVersionNumber#isStable}
- *
+ *
* @since 2022-02-19
* @since v0.4.0
*/
@@ -294,30 +292,30 @@ 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")
+ final var 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)
+ 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 SemanticVersionNumber v100b = builder(1, 0, 0).preRelease("beta")
+ final var 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 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 +353,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 +373,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..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());
diff --git a/src/test/java/sevenUnitsGUI/I18nTest.java b/src/test/java/sevenUnitsGUI/I18nTest.java
index 78f5da4..2f90d76 100644
--- a/src/test/java/sevenUnitsGUI/I18nTest.java
+++ b/src/test/java/sevenUnitsGUI/I18nTest.java
@@ -28,68 +28,67 @@ import org.junit.jupiter.params.provider.MethodSource;
/**
* Tests for the internationalization system.
- *
+ *
* @since v1.0.0
*/
class I18nTest {
+ private static final Stream<String> testLocaleSupported() {
+ return Stream.of("en", "fr");
+ }
+
private static final Stream<Arguments> testLocalization() {
- return Stream.of(
- Arguments.of("tv.title", "en", "7Units [v]"),
+ return Stream.of(Arguments.of("tv.title", "en", "7Units [v]"),
Arguments.of("tv.title", "fr", "7Unités [v]"),
Arguments.of("tv.convert_units.title", "en", "Convert Units"),
Arguments.of("tv.convert_units.title", "fr", "Convertir Unités"));
}
-
- private static final Stream<String> testLocaleSupported() {
- return Stream.of("en", "fr");
- }
/**
* Tests that the default locale is supported.
- *
+ *
* @since v1.0.0
* @see Presenter#DEFAULT_LOCALE
*/
@Test
void testDefaultLocaleSupported() {
- Presenter p = new Presenter(new ViewBot());
+ final var p = new Presenter(new ViewBot());
assertNotNull(p.locales.get(Presenter.DEFAULT_LOCALE),
"Default locale is not supported.");
}
-
+
/**
* Ensures that the system supports the provided locale.
- *
+ *
* @param localeName locale to test for support
- *
+ *
* @since 2025-06-04
* @since v1.0.0
*/
@ParameterizedTest
@MethodSource
void testLocaleSupported(String localeName) {
- Presenter p = new Presenter(new ViewBot());
+ final var p = new Presenter(new ViewBot());
assertNotNull(p.locales.get(localeName),
"Locale \"" + localeName + "\" is not supported.");
}
/**
- * Tests that the system can correctly localize text,
- * using the default locales.
- *
+ * Tests that the system can correctly localize text, using the default
+ * locales.
+ *
* @param key key of text to localize
* @param locale locale to use
* @param expected expected value of output text
- *
+ *
* @since 2025-06-04
* @since v1.0.0
*/
@ParameterizedTest
@MethodSource
void testLocalization(String key, String locale, String expected) {
- Presenter p = new Presenter(new ViewBot());
+ final var p = new Presenter(new ViewBot());
p.setUserLocale(locale);
- String actual = p.getLocalizedText(key);
+ final var actual = p.getLocalizedText(key);
assertEquals(expected, actual);
}
diff --git a/src/test/java/sevenUnitsGUI/PrefixRepetitionTest.java b/src/test/java/sevenUnitsGUI/PrefixRepetitionTest.java
index 50b390b..ead5f4a 100644
--- a/src/test/java/sevenUnitsGUI/PrefixRepetitionTest.java
+++ b/src/test/java/sevenUnitsGUI/PrefixRepetitionTest.java
@@ -37,7 +37,7 @@ import sevenUnits.unit.Metric;
class PrefixRepetitionTest {
/**
* Ensures that the complex repetition rule disallows invalid prefix lists.
- *
+ *
* @since 2022-07-17
* @since v0.4.0
*/
@@ -57,7 +57,7 @@ class PrefixRepetitionTest {
/**
* Tests the {@code NO_REPETITION} rule.
- *
+ *
* @since 2022-07-17
* @since v0.4.0
*/
@@ -71,7 +71,7 @@ class PrefixRepetitionTest {
/**
* Tests the {@code NO_RESTRICTION} rule.
- *
+ *
* @since 2022-07-17
* @since v0.4.0
*/
@@ -85,7 +85,7 @@ class PrefixRepetitionTest {
/**
* Ensures that the complex repetition rule allows valid prefix lists.
- *
+ *
* @since 2022-07-17
* @since v0.4.0
*/
diff --git a/src/test/java/sevenUnitsGUI/PrefixSearchTest.java b/src/test/java/sevenUnitsGUI/PrefixSearchTest.java
index b605d05..00dd960 100644
--- a/src/test/java/sevenUnitsGUI/PrefixSearchTest.java
+++ b/src/test/java/sevenUnitsGUI/PrefixSearchTest.java
@@ -40,9 +40,7 @@ import sevenUnits.unit.Metric;
* @since v0.4.0
*/
class PrefixSearchTest {
- /**
- * A method that creates duplicate copies of the common prefix rule.
- */
+ /** A method that creates duplicate copies of the common prefix rule. */
private static final PrefixSearchRule getCommonRuleCopy() {
return getCoherentOnlyRule(Set.of(Metric.KILO, Metric.MILLI));
}
@@ -110,7 +108,7 @@ class PrefixSearchTest {
/**
* Tests prefix searching for a non-coherent unit and
* {@link PrefixSearchRule#COMMON_PREFIXES}.
- *
+ *
* @since 2022-07-17
* @since v0.4.0
*/
@@ -125,7 +123,7 @@ class PrefixSearchTest {
/**
* Tests that {@link PrefixSearchRule#NO_PREFIXES} returns the original unit.
- *
+ *
* @since 2022-07-17
* @since v0.4.0
*/
@@ -151,10 +149,10 @@ class PrefixSearchTest {
*/
@Test
final void testToString() {
- final String toString = COMMON_PREFIXES.toString();
- final String valid1 = "Apply the following prefixes: [kilo (\u00D7 1000.0), milli (\u00D7 0.001)]";
- final String valid2 = "Apply the following prefixes: [milli (\u00D7 0.001), kilo (\u00D7 1000.0)]";
-
+ final var toString = COMMON_PREFIXES.toString();
+ final var valid1 = "Apply the following prefixes: [kilo (\u00D7 1000.0), milli (\u00D7 0.001)]";
+ final var valid2 = "Apply the following prefixes: [milli (\u00D7 0.001), kilo (\u00D7 1000.0)]";
+
assertTrue(valid1.equals(toString) || valid2.equals(toString),
"COMMON_PREFIXES.toString invalid (was \"" + toString + "\").");
}
diff --git a/src/test/java/sevenUnitsGUI/RoundingTest.java b/src/test/java/sevenUnitsGUI/RoundingTest.java
index e6453f2..589b8d0 100644
--- a/src/test/java/sevenUnitsGUI/RoundingTest.java
+++ b/src/test/java/sevenUnitsGUI/RoundingTest.java
@@ -137,7 +137,7 @@ class RoundingTest {
/**
* Tests that the rounding methods' equals() methods work.
- *
+ *
* @since 2022-07-17
* @since v0.4.0
*/
@@ -161,7 +161,7 @@ class RoundingTest {
// test that FixedDecimals is never equal to FixedPrecision
// this unlikely argument is the test - the equals should return false!
@SuppressWarnings("unlikely-arg-type")
- final boolean differentRulesEqual = Objects.equals(fixedDecimals(4),
+ final var differentRulesEqual = Objects.equals(fixedDecimals(4),
fixedPrecision(4));
assertFalse(differentRulesEqual, "fixedDecimals(4) == fixedPrecision(4)");
}
@@ -226,7 +226,7 @@ class RoundingTest {
/**
* Tests that {@link StandardDisplayRules#getStandardRule} gets rounding
* rules as intended.
- *
+ *
* @since 2022-07-17
* @since v0.4.0
*/
@@ -244,7 +244,7 @@ class RoundingTest {
/**
* Tests that the rounding methods' equals() methods work.
- *
+ *
* @since 2022-07-17
* @since v0.4.0
*/
@@ -258,7 +258,7 @@ class RoundingTest {
/**
* Tests that the {@code toString()} methods of the three rounding rule
* classes work correctly.
- *
+ *
* @since 2022-07-17
* @since v0.4.0
*/
diff --git a/src/test/java/sevenUnitsGUI/TabbedViewTest.java b/src/test/java/sevenUnitsGUI/TabbedViewTest.java
index 3716673..b32579c 100644
--- a/src/test/java/sevenUnitsGUI/TabbedViewTest.java
+++ b/src/test/java/sevenUnitsGUI/TabbedViewTest.java
@@ -33,67 +33,67 @@ import org.junit.jupiter.api.Timeout;
class TabbedViewTest {
/**
* @return a view with all settings set to standard values
- *
+ *
* @since 2022-07-17
* @since v0.4.0
*/
private static final TabbedView setupView() {
final var view = new TabbedView();
final var presenter = view.getPresenter();
-
+
presenter.setNumberDisplayRule(StandardDisplayRules.uncertaintyBased());
presenter.setPrefixRepetitionRule(
DefaultPrefixRepetitionRule.NO_RESTRICTION);
presenter.setSearchRule(PrefixSearchRule.COMMON_PREFIXES);
presenter.setOneWayConversionEnabled(false);
presenter.setShowDuplicates(true);
-
+
return view;
}
-
+
/**
* Simulates an expression conversion operation, and ensures it works
* properly.
- *
+ *
* @since 2022-07-17
* @since v0.4.0
*/
@Test
void testExpressionConversion() {
final var view = setupView();
-
+
// prepare for unit conversion
view.masterPane.setSelectedIndex(1);
view.fromEntry.setText("250.0 inch");
view.toEntry.setText("metre");
-
+
view.convertExpressionButton.doClick();
-
+
// check result of conversion
assertEquals("250.0 inch = 6.350 metre", view.expressionOutput.getText());
}
-
+
/**
* Simulates a unit conversion operation, and ensures it works properly.
- *
+ *
* @since 2022-07-17
* @since v0.4.0
*/
@Test
void testUnitConversion() {
final var view = setupView();
-
+
// prepare for unit conversion
view.masterPane.setSelectedIndex(0);
view.dimensionSelector.setSelectedItem("Length");
view.fromSearch.getSearchList().setSelectedValue("inch", true);
view.toSearch.getSearchList().setSelectedValue("metre", true);
view.valueInput.setText("250.0");
-
+
view.convertUnitButton.doClick();
-
+
// check result of conversion
assertEquals("250.0 inch = 6.350 metre", view.unitOutput.getText());
}
-
+
}