diff options
Diffstat (limited to 'src/test/java/sevenUnitsGUI')
-rw-r--r-- | src/test/java/sevenUnitsGUI/PrefixRepetitionTest.java | 10 | ||||
-rw-r--r-- | src/test/java/sevenUnitsGUI/PrefixSearchTest.java | 22 | ||||
-rw-r--r-- | src/test/java/sevenUnitsGUI/PresenterTest.java | 94 | ||||
-rw-r--r-- | src/test/java/sevenUnitsGUI/RoundingTest.java | 36 | ||||
-rw-r--r-- | src/test/java/sevenUnitsGUI/TabbedViewTest.java | 22 |
5 files changed, 92 insertions, 92 deletions
diff --git a/src/test/java/sevenUnitsGUI/PrefixRepetitionTest.java b/src/test/java/sevenUnitsGUI/PrefixRepetitionTest.java index 8ea3fd0..476e407 100644 --- a/src/test/java/sevenUnitsGUI/PrefixRepetitionTest.java +++ b/src/test/java/sevenUnitsGUI/PrefixRepetitionTest.java @@ -54,7 +54,7 @@ class PrefixRepetitionTest { assertFalse(COMPLEX_REPETITION.test(List.of(Metric.YOTTA, Metric.MILLI)), "Complex repetition does not factor direction of prefixes"); } - + /** * Tests the {@code NO_REPETITION} rule. * @@ -68,7 +68,7 @@ class PrefixRepetitionTest { assertTrue(NO_REPETITION.test(List.of(Metric.MILLI))); assertTrue(NO_REPETITION.test(List.of()), "Empty list yields false"); } - + /** * Tests the {@code NO_RESTRICTION} rule. * @@ -82,7 +82,7 @@ class PrefixRepetitionTest { assertTrue(NO_RESTRICTION.test(List.of(Metric.MILLI))); assertTrue(NO_RESTRICTION.test(List.of())); } - + /** * Ensures that the complex repetition rule allows valid prefix lists. * @@ -95,7 +95,7 @@ class PrefixRepetitionTest { assertTrue(COMPLEX_REPETITION.test(List.of(Metric.KILO)), "Single prefix not allowed"); assertTrue(COMPLEX_REPETITION.test(List.of()), "No prefixes not allowed"); - + // valid complex repetition assertTrue(COMPLEX_REPETITION.test(List.of(Metric.YOTTA, Metric.KILO)), "Valid complex repetition (kiloyotta) not allowed"); @@ -109,7 +109,7 @@ class PrefixRepetitionTest { COMPLEX_REPETITION.test(List.of(Metric.YOTTA, Metric.YOTTA, Metric.KILO, Metric.DEKA)), "Valid complex repetition (dekakiloyottayotta) not allowed"); - + // valid with negative prefixes assertTrue(COMPLEX_REPETITION.test(List.of(Metric.YOCTO, Metric.MILLI)), "Valid complex repetition (milliyocto) not allowed"); diff --git a/src/test/java/sevenUnitsGUI/PrefixSearchTest.java b/src/test/java/sevenUnitsGUI/PrefixSearchTest.java index ca238fe..305d0d7 100644 --- a/src/test/java/sevenUnitsGUI/PrefixSearchTest.java +++ b/src/test/java/sevenUnitsGUI/PrefixSearchTest.java @@ -45,7 +45,7 @@ class PrefixSearchTest { private static final PrefixSearchRule getCommonRuleCopy() { return getCoherentOnlyRule(Set.of(Metric.KILO, Metric.MILLI)); } - + /** * Test method for * {@link sevenUnitsGUI.PrefixSearchRule#apply(java.util.Map.Entry)}, for a @@ -60,11 +60,11 @@ class PrefixSearchTest { Metric.KILOMETRE, "millimetre", Metric.MILLIMETRE); final var actual = COMMON_PREFIXES .apply(Map.entry("metre", Metric.METRE)); - + assertEquals(expected, actual, "Prefixes not correctly applied to coherent unit."); } - + /** * Test method for * {@link sevenUnitsGUI.PrefixSearchRule#equals(java.lang.Object)}. @@ -76,11 +76,11 @@ class PrefixSearchTest { final void testEquals() { assertEquals(getCommonRuleCopy(), getCommonRuleCopy(), "equals considers something other than prefixes/rule"); - + assertNotEquals(getCoherentOnlyRule(Set.of()), getUniversalRule(Set.of()), "equals ignores rule"); } - + /** * Test method for {@link sevenUnitsGUI.PrefixSearchRule#getPrefixes()}. * @@ -93,7 +93,7 @@ class PrefixSearchTest { assertEquals(Metric.ALL_PREFIXES, PrefixSearchRule.ALL_METRIC_PREFIXES.getPrefixes()); } - + /** * Test method for {@link sevenUnitsGUI.PrefixSearchRule#hashCode()}. * @@ -105,7 +105,7 @@ class PrefixSearchTest { assertEquals(getCommonRuleCopy().hashCode(), getCommonRuleCopy().hashCode()); } - + /** * Tests prefix searching for a non-coherent unit and * {@link PrefixSearchRule#COMMON_PREFIXES}. @@ -118,10 +118,10 @@ class PrefixSearchTest { final var input = Map.entry("inch", BritishImperial.Length.INCH); final var expected = Map.ofEntries(input); final var actual = COMMON_PREFIXES.apply(input); - + assertEquals(expected, actual, "Prefixes applied to non-coherent unit."); } - + /** * Tests that {@link PrefixSearchRule#NO_PREFIXES} returns the original unit. * @@ -141,7 +141,7 @@ class PrefixSearchTest { } } } - + /** * Test method for {@link sevenUnitsGUI.PrefixSearchRule#toString()}. * @@ -154,5 +154,5 @@ class PrefixSearchTest { "Apply the following prefixes: [kilo (\u00D7 1000.0), milli (\u00D7 0.001)]", COMMON_PREFIXES.toString()); } - + } diff --git a/src/test/java/sevenUnitsGUI/PresenterTest.java b/src/test/java/sevenUnitsGUI/PresenterTest.java index 5755701..9e25a08 100644 --- a/src/test/java/sevenUnitsGUI/PresenterTest.java +++ b/src/test/java/sevenUnitsGUI/PresenterTest.java @@ -64,14 +64,14 @@ public final class PresenterTest { "test-settings.txt"); static final Set<Unit> testUnits = Set.of(Metric.METRE, Metric.KILOMETRE, Metric.METRE_PER_SECOND, Metric.KILOMETRE_PER_HOUR); - + static final Set<ObjectProduct<BaseDimension>> testDimensions = Set .of(Metric.Dimensions.LENGTH, Metric.Dimensions.VELOCITY); - + private static final Stream<Function<Map.Entry<String, LinearUnit>, Map<String, LinearUnit>>> SEARCH_RULES = Stream .of(PrefixSearchRule.NO_PREFIXES, PrefixSearchRule.COMMON_PREFIXES, PrefixSearchRule.ALL_METRIC_PREFIXES); - + /** * @return rounding rules used by {@link #testRoundingRules} * @since v0.4.0 @@ -81,18 +81,18 @@ public final class PresenterTest { final var SCIENTIFIC_ROUNDING = StandardDisplayRules.uncertaintyBased(); final var INTEGER_ROUNDING = StandardDisplayRules.fixedDecimals(0); final var SIG_FIG_ROUNDING = StandardDisplayRules.fixedPrecision(4); - + return Stream.of(SCIENTIFIC_ROUNDING, INTEGER_ROUNDING, SIG_FIG_ROUNDING); } - + private static final Stream<Function<Map.Entry<String, LinearUnit>, Map<String, LinearUnit>>> getSearchRules() { return SEARCH_RULES; } - + private static final Set<String> names(Set<? extends Nameable> units) { return units.stream().map(Nameable::getName).collect(Collectors.toSet()); } - + /** * Test method for {@link Presenter#convertExpressions} * @@ -104,20 +104,20 @@ public final class PresenterTest { // setup final ViewBot viewBot = new ViewBot(); final Presenter presenter = new Presenter(viewBot); - + viewBot.setFromExpression("10000.0 m"); viewBot.setToExpression("km"); - + // convert expression presenter.convertExpressions(); - + // test result final List<UnitConversionRecord> outputs = viewBot .expressionConversionList(); assertEquals("10000.0 m = 10.00000 km", outputs.get(outputs.size() - 1).toString()); } - + /** * Tests that unit-conversion Views can correctly convert units * @@ -129,16 +129,16 @@ public final class PresenterTest { // setup final ViewBot viewBot = new ViewBot(); final Presenter presenter = new Presenter(viewBot); - + viewBot.setFromUnitNames(names(testUnits)); viewBot.setToUnitNames(names(testUnits)); viewBot.setFromSelection("metre"); viewBot.setToSelection("kilometre"); viewBot.setInputValue("10000.0"); - + // convert units presenter.convertUnits(); - + /* * use result from system as expected - I'm not testing unit conversion * here (that's for the backend tests), I'm just testing that it correctly @@ -154,7 +154,7 @@ public final class PresenterTest { expectedOutput.getValue().toString(false, RoundingMode.HALF_EVEN)); assertEquals(List.of(expectedUC), viewBot.unitConversionList()); } - + /** * Tests that duplicate units are successfully removed, if that is asked for * @@ -165,7 +165,7 @@ public final class PresenterTest { void testDuplicateUnits() { final var metre = Metric.METRE; final var meter = Metric.METRE.withName(NameSymbol.of("meter", "m")); - + // load 2 duplicate units final var viewBot = new ViewBot(); final var presenter = new Presenter(viewBot); @@ -174,20 +174,20 @@ public final class PresenterTest { presenter.database.addUnit("meter", meter); presenter.setOneWayConversionEnabled(false); presenter.setSearchRule(PrefixSearchRule.NO_PREFIXES); - + // test that only one of them is included if duplicate units disabled presenter.setShowDuplicates(false); presenter.updateView(); assertEquals(1, viewBot.getFromUnitNames().size()); assertEquals(1, viewBot.getToUnitNames().size()); - + // test that both of them is included if duplicate units enabled presenter.setShowDuplicates(true); presenter.updateView(); assertEquals(2, viewBot.getFromUnitNames().size()); assertEquals(2, viewBot.getToUnitNames().size()); } - + /** * Tests that one-way conversion correctly filters From and To units * @@ -200,7 +200,7 @@ public final class PresenterTest { final var allNames = Set.of("metre", "inch", "tempC"); final var metricNames = Set.of("metre", "tempC"); final var nonMetricNames = Set.of("inch", "tempC"); - + // load view with one metric and one non-metric unit final var viewBot = new ViewBot(); final var presenter = new Presenter(viewBot); @@ -209,19 +209,19 @@ public final class PresenterTest { presenter.database.addUnit("inch", BritishImperial.Length.INCH); presenter.database.addUnit("tempC", Metric.CELSIUS); presenter.setSearchRule(PrefixSearchRule.NO_PREFIXES); - + // test that units are removed from each side when one-way conversion is // enabled presenter.setOneWayConversionEnabled(true); assertEquals(nonMetricNames, viewBot.getFromUnitNames()); assertEquals(metricNames, viewBot.getToUnitNames()); - + // test that units are kept when one-way conversion is disabled presenter.setOneWayConversionEnabled(false); assertEquals(allNames, viewBot.getFromUnitNames()); assertEquals(allNames, viewBot.getToUnitNames()); } - + /** * Tests the prefix-viewing functionality. * @@ -235,23 +235,23 @@ public final class PresenterTest { final var presenter = new Presenter(viewBot); viewBot.setViewablePrefixNames(Set.of("kilo", "milli")); presenter.setNumberDisplayRule(UncertainDouble::toString); - + // view prefix viewBot.setViewedPrefixName("kilo"); presenter.prefixSelected(); // just in case - + // get correct values final var expectedNameSymbol = presenter.database.getPrefix("kilo") .getNameSymbol(); final var expectedMultiplierString = String .valueOf(Metric.KILO.getMultiplier()); - + // test that presenter's values are correct final var prefixRecord = viewBot.prefixViewList().get(0); assertEquals(expectedNameSymbol, prefixRecord.getNameSymbol()); assertEquals(expectedMultiplierString, prefixRecord.multiplierString()); } - + /** * Tests that rounding rules are used correctly. * @@ -265,13 +265,13 @@ public final class PresenterTest { final var viewBot = new ViewBot(); final var presenter = new Presenter(viewBot); presenter.setNumberDisplayRule(roundingRule); - + // convert and round viewBot.setInputValue("12345.6789"); viewBot.setFromSelection("metre"); viewBot.setToSelection("kilometre"); presenter.convertUnits(); - + // test the result of the rounding final String expectedOutputString = roundingRule .apply(UncertainDouble.fromRoundedString("12.3456789")); @@ -279,7 +279,7 @@ public final class PresenterTest { .outputValueString(); assertEquals(expectedOutputString, actualOutputString); } - + /** * Tests that the Presenter correctly applies search rules. * @@ -294,15 +294,15 @@ public final class PresenterTest { // setup final var viewBot = new ViewBot(); final var presenter = new Presenter(viewBot); - + presenter.setSearchRule(searchRule); presenter.setOneWayConversionEnabled(false); - + presenter.database.clear(); presenter.database.addUnit("metre", Metric.METRE); presenter.database.addUnit("inch", BritishImperial.Length.INCH); presenter.updateView(); - + // create expected output based on rule final Set<String> expectedOutput = new HashSet<>(); expectedOutput.addAll(searchRule @@ -310,11 +310,11 @@ public final class PresenterTest { expectedOutput.addAll( searchRule.apply(Map.entry("metre", Metric.METRE)).keySet()); final Set<String> actualOutput = viewBot.getFromUnitNames(); - + // test output assertEquals(expectedOutput, actualOutput); } - + /** * Tests that settings can be saved to and loaded from a file. * @@ -326,7 +326,7 @@ public final class PresenterTest { // setup final var viewBot = new ViewBot(); final var presenter = new Presenter(viewBot); - + // set and save custom settings presenter.setOneWayConversionEnabled(true); presenter.setShowDuplicates(true); @@ -335,12 +335,12 @@ public final class PresenterTest { DefaultPrefixRepetitionRule.COMPLEX_REPETITION); assumeTrue(presenter.writeSettings(TEST_SETTINGS), "Could not write to settings file."); - + // overwrite custom settings presenter.setOneWayConversionEnabled(false); presenter.setShowDuplicates(false); presenter.setNumberDisplayRule(StandardDisplayRules.uncertaintyBased()); - + // load settings & test that they're the same presenter.loadSettings(TEST_SETTINGS); assertTrue(presenter.oneWayConversionEnabled()); @@ -348,7 +348,7 @@ public final class PresenterTest { assertEquals(StandardDisplayRules.fixedPrecision(11), presenter.getNumberDisplayRule()); } - + /** * Ensures the Presenter generates the correct data upon a unit-viewing. * @@ -361,12 +361,12 @@ public final class PresenterTest { final var viewBot = new ViewBot(); final var presenter = new Presenter(viewBot); viewBot.setViewableUnitNames(names(testUnits)); - + // view unit viewBot.setViewedUnitName("metre"); presenter.unitNameSelected(); // just in case this isn't triggered // automatically - + // get correct values final var expectedNameSymbol = presenter.database.getUnit("metre") .getNameSymbol(); @@ -374,7 +374,7 @@ public final class PresenterTest { final var expectedDimensionName = presenter .getDimensionName(Metric.METRE.getDimension()); final var expectedUnitType = UnitType.METRIC; - + // test for correctness final var viewRecord = viewBot.unitViewList().get(0); assertEquals(expectedNameSymbol, viewRecord.getNameSymbol()); @@ -382,7 +382,7 @@ public final class PresenterTest { assertEquals(expectedDimensionName, viewRecord.dimensionName()); assertEquals(expectedUnitType, viewRecord.unitType()); } - + /** * Test for {@link Presenter#updateView()} * @@ -396,7 +396,7 @@ public final class PresenterTest { final Presenter presenter = new Presenter(viewBot); presenter.setOneWayConversionEnabled(false); presenter.setSearchRule(PrefixSearchRule.NO_PREFIXES); - + // override default database units presenter.database.clear(); for (final Unit unit : testUnits) { @@ -406,18 +406,18 @@ public final class PresenterTest { presenter.database.addDimension( dimension.getPrimaryName().orElseThrow(), dimension); } - + // set from and to units viewBot.setFromUnitNames(names(testUnits)); viewBot.setToUnitNames(names(testUnits)); viewBot.setDimensionNames(names(testDimensions)); viewBot.setSelectedDimensionName(Metric.Dimensions.LENGTH.getName()); - + // filter to length units only, then get the filtered sets of units presenter.updateView(); final Set<String> fromUnits = viewBot.getFromUnitNames(); final Set<String> toUnits = viewBot.getToUnitNames(); - + // test that fromUnits/toUnits is [METRE, KILOMETRE] assertEquals(Set.of("metre", "kilometre"), fromUnits); assertEquals(Set.of("metre", "kilometre"), toUnits); diff --git a/src/test/java/sevenUnitsGUI/RoundingTest.java b/src/test/java/sevenUnitsGUI/RoundingTest.java index ca1a272..f749f85 100644 --- a/src/test/java/sevenUnitsGUI/RoundingTest.java +++ b/src/test/java/sevenUnitsGUI/RoundingTest.java @@ -49,13 +49,13 @@ class RoundingTest { private static final FixedDecimals ZERO_DECIMALS = fixedDecimals(0); private static final FixedDecimals TWO_DECIMALS = fixedDecimals(2); private static final FixedDecimals SIX_DECIMALS = fixedDecimals(6); - + private static final FixedPrecision ONE_SIG_FIG = fixedPrecision(1); private static final FixedPrecision THREE_SIG_FIGS = fixedPrecision(3); private static final FixedPrecision TWELVE_SIG_FIGS = fixedPrecision(12); - + private static final UncertaintyBased UNCERTAINTY_BASED = uncertaintyBased(); - + // numbers to test rounding with private static final UncertainDouble INPUT1 = UncertainDouble.of(12.3456789, 0.0); @@ -65,7 +65,7 @@ class RoundingTest { 0.0); private static final UncertainDouble INPUT4 = UncertainDouble.of(0.00001234, 0.000001); - + /** * @return arguments for * {@link #testFixedDecimalRounding(UncertainDouble, String, String, String)} @@ -79,7 +79,7 @@ class RoundingTest { Arguments.of(INPUT3, "12345432", "12345432.10", "12345432.100000"), Arguments.of(INPUT4, "0", "0.00", "0.000012")); } - + /** * @return arguments for * {@link #testFixedPrecisionRounding(UncertainDouble, String, String, String)} @@ -93,7 +93,7 @@ class RoundingTest { Arguments.of(INPUT3, "1E+7", "1.23E+7", "12345432.1000"), Arguments.of(INPUT4, "0.00001", "0.0000123", "0.0000123400000000")); } - + /** * @return arguments for * {@link #testUncertaintyRounding(UncertainDouble, String)} @@ -107,7 +107,7 @@ class RoundingTest { Arguments.of(INPUT3, "1.23454321E7"), Arguments.of(INPUT4, "0.0000123")); } - + /** * Test for {@link FixedDecimals#decimalPlaces()} and * {@link FixedPrecision#significantFigures()}. @@ -124,7 +124,7 @@ class RoundingTest { "TWO_DECIMALS has " + TWO_DECIMALS.decimalPlaces() + " decimals"); assertEquals(6, SIX_DECIMALS.decimalPlaces(), "SIX_DECIMALS has " + SIX_DECIMALS.decimalPlaces() + " decimals"); - + // ensure # of sig figs can be accessed assertEquals(1, ONE_SIG_FIG.significantFigures(), "ONE_SIG_FIG has " + ONE_SIG_FIG.significantFigures() + " significant figures"); @@ -134,7 +134,7 @@ class RoundingTest { "TWELVE_SIG_FIGS has " + TWELVE_SIG_FIGS.significantFigures() + " significant figures"); } - + /** * Tests that the rounding methods' equals() methods work. * @@ -150,14 +150,14 @@ class RoundingTest { "TWO_DECIMALS == SIX_DECIMALS"); assertTrue(Objects.equals(fixedDecimals(0), fixedDecimals(0)), "FixedDecimals.equals() depends on something other than decimal places."); - + assertTrue(ONE_SIG_FIG.equals(ONE_SIG_FIG), "ONE_SIG_FIG does not equal itself"); assertFalse(THREE_SIG_FIGS.equals(TWELVE_SIG_FIGS), "THREE_SIG_FIGS == TWELVE_SIG_FIGS"); assertTrue(Objects.equals(fixedPrecision(1), fixedPrecision(1)), "FixedPrecision.equals() depends on something other than significant figures."); - + // test that FixedDecimals is never equal to FixedPrecision // this unlikely argument is the test - the equals should return false! @SuppressWarnings("unlikely-arg-type") @@ -165,7 +165,7 @@ class RoundingTest { fixedPrecision(4)); assertFalse(differentRulesEqual, "fixedDecimals(4) == fixedPrecision(4)"); } - + /** * Ensures that fixed decimal rounding works as expected * @@ -192,7 +192,7 @@ class RoundingTest { "TWO_DECIMALS rounded " + input + " as " + SIX_DECIMALS.apply(input) + " (should be " + sixDecimalString + ")"); } - + /** * Ensures that fixed precision rounding works as expected * @@ -221,7 +221,7 @@ class RoundingTest { + TWELVE_SIG_FIGS.apply(input) + " (should be " + twelveSigFigString + ")"); } - + /** * Tests that {@link StandardDisplayRules#getStandardRule} gets rounding * rules as intended. @@ -236,11 +236,11 @@ class RoundingTest { getStandardRule("Round to 3 significant figures")); assertEquals(UNCERTAINTY_BASED, getStandardRule("Uncertainty-Based Rounding")); - + assertThrows(IllegalArgumentException.class, () -> getStandardRule("Not a rounding rule")); } - + /** * Tests that the rounding methods' equals() methods work. * @@ -253,7 +253,7 @@ class RoundingTest { assertEquals(ONE_SIG_FIG.hashCode(), ONE_SIG_FIG.hashCode()); assertEquals(UNCERTAINTY_BASED.hashCode(), UNCERTAINTY_BASED.hashCode()); } - + /** * Tests that the {@code toString()} methods of the three rounding rule * classes work correctly. @@ -267,7 +267,7 @@ class RoundingTest { assertEquals("Round to 3 significant figures", THREE_SIG_FIGS.toString()); assertEquals("Uncertainty-Based Rounding", UNCERTAINTY_BASED.toString()); } - + /** * Tests that Uncertainty Rounding works as expected * diff --git a/src/test/java/sevenUnitsGUI/TabbedViewTest.java b/src/test/java/sevenUnitsGUI/TabbedViewTest.java index 00092a4..165718f 100644 --- a/src/test/java/sevenUnitsGUI/TabbedViewTest.java +++ b/src/test/java/sevenUnitsGUI/TabbedViewTest.java @@ -36,17 +36,17 @@ class TabbedViewTest { 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. @@ -57,18 +57,18 @@ class TabbedViewTest { @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. * @@ -78,18 +78,18 @@ class TabbedViewTest { @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()); } - + } |