diff options
author | Adrien Hopkins <ahopk127@my.yorku.ca> | 2022-04-16 15:57:00 -0500 |
---|---|---|
committer | Adrien Hopkins <ahopk127@my.yorku.ca> | 2022-04-16 15:57:00 -0500 |
commit | 4aaf6a8b60fbec63c2e0bee624b3859ded0ecde3 (patch) | |
tree | 7499f304f4c849ded2f9035cb64f87a8cf85e608 /src/main/java/sevenUnitsGUI | |
parent | 4ad68a29f84538d3fb19eec8e0622731f5a5d7c8 (diff) |
Added a full suite of frontend tests
(Added tests for the settings and unit/prefix viewer parts of the GUI, which are
not yet implemented)
Diffstat (limited to 'src/main/java/sevenUnitsGUI')
-rw-r--r-- | src/main/java/sevenUnitsGUI/Presenter.java | 14 | ||||
-rw-r--r-- | src/main/java/sevenUnitsGUI/StandardDisplayRules.java | 26 | ||||
-rw-r--r-- | src/main/java/sevenUnitsGUI/ViewBot.java | 200 |
3 files changed, 234 insertions, 6 deletions
diff --git a/src/main/java/sevenUnitsGUI/Presenter.java b/src/main/java/sevenUnitsGUI/Presenter.java index b38f90b..5c8ce53 100644 --- a/src/main/java/sevenUnitsGUI/Presenter.java +++ b/src/main/java/sevenUnitsGUI/Presenter.java @@ -18,6 +18,7 @@ package sevenUnitsGUI; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Path; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -50,7 +51,8 @@ import sevenUnits.utils.UncertainDouble; */ public final class Presenter { /** The default place where settings are stored. */ - private static final String DEFAULT_SETTINGS_FILEPATH = "settings.txt"; + private static final Path DEFAULT_SETTINGS_FILEPATH = Path + .of("settings.txt"); /** The default place where units are stored. */ private static final String DEFAULT_UNITS_FILEPATH = "/unitsfile.txt"; /** The default place where dimensions are stored. */ @@ -406,17 +408,18 @@ public final class Presenter { * * @since 2022-03-30 */ - public boolean isOneWayConversionEnabled() { + public boolean oneWayConversionEnabled() { return this.oneWayConversionEnabled; } /** * Loads settings from the user's settings file and applies them to the * presenter. - * + * + * @param settingsFile file settings should be loaded from * @since 2021-12-15 */ - private void loadSettings() {} + void loadSettings(Path settingsFile) {} /** * Completes creation of the presenter. This part of the initialization @@ -438,9 +441,10 @@ public final class Presenter { /** * Saves the presenter's settings to the user settings file. * + * @param settingsFile file settings should be saved to * @since 2021-12-15 */ - private void saveSettings() {} + void saveSettings(Path settingsFile) {} /** * @param numberDisplayRule the new rule that will be used by this presenter diff --git a/src/main/java/sevenUnitsGUI/StandardDisplayRules.java b/src/main/java/sevenUnitsGUI/StandardDisplayRules.java index 331f598..f6272c8 100644 --- a/src/main/java/sevenUnitsGUI/StandardDisplayRules.java +++ b/src/main/java/sevenUnitsGUI/StandardDisplayRules.java @@ -45,6 +45,32 @@ final class StandardDisplayRules { }; /** + * Gets a display rule that rounds numbers to a fixed number of decimal + * places. + * + * @param decimalPlaces number of decimal places + * @return display rule + * @since 2022-04-16 + */ + public static final Function<UncertainDouble, String> getFixedPlacesRule( + int decimalPlaces) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + * Gets a display rule that rounds numbers to a fixed number of significant + * figures. + * + * @param significantFigures number of significant figures + * @return display rule + * @since 2022-04-16 + */ + public static final Function<UncertainDouble, String> getFixedPrecisionRule( + int significantFigures) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** * @return a rule that rounds using UncertainDouble's own toString(false) * function. * @since 2021-12-24 diff --git a/src/main/java/sevenUnitsGUI/ViewBot.java b/src/main/java/sevenUnitsGUI/ViewBot.java index 9f9a524..988d1bc 100644 --- a/src/main/java/sevenUnitsGUI/ViewBot.java +++ b/src/main/java/sevenUnitsGUI/ViewBot.java @@ -25,6 +25,7 @@ import java.util.Set; import sevenUnits.unit.UnitType; import sevenUnits.utils.NameSymbol; +import sevenUnits.utils.Nameable; /** * A class that simulates a View (supports both unit and expression conversion) @@ -34,6 +35,163 @@ import sevenUnits.utils.NameSymbol; * @since 2022-01-29 */ final class ViewBot implements UnitConversionView, ExpressionConversionView { + /** + * A record of the parameters given to + * {@link View#showPrefix(NameSymbol, String)}, for testing. + * + * @since 2022-04-16 + */ + public static final class PrefixViewingRecord implements Nameable { + private final NameSymbol nameSymbol; + private final String multiplierString; + + /** + * @param nameSymbol + * @param multiplierString + * @since 2022-04-16 + */ + public PrefixViewingRecord(NameSymbol nameSymbol, + String multiplierString) { + this.nameSymbol = nameSymbol; + this.multiplierString = multiplierString; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof PrefixViewingRecord)) + return false; + final PrefixViewingRecord other = (PrefixViewingRecord) obj; + return Objects.equals(this.multiplierString, other.multiplierString) + && Objects.equals(this.nameSymbol, other.nameSymbol); + } + + @Override + public NameSymbol getNameSymbol() { + return this.nameSymbol; + } + + @Override + public int hashCode() { + return Objects.hash(this.multiplierString, this.nameSymbol); + } + + public String multiplierString() { + return this.multiplierString; + } + + public NameSymbol nameSymbol() { + return this.nameSymbol; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("PrefixViewingRecord [nameSymbol="); + builder.append(this.nameSymbol); + builder.append(", multiplierString="); + builder.append(this.multiplierString); + builder.append("]"); + return builder.toString(); + } + } + + /** + * A record of the parameters given to + * {@link View#showUnit(NameSymbol, String, String, UnitType)}, for testing. + * + * @since 2022-04-16 + */ + public static final class UnitViewingRecord implements Nameable { + private final NameSymbol nameSymbol; + private final String definition; + private final String dimensionName; + private final UnitType unitType; + + /** + * @since 2022-04-16 + */ + public UnitViewingRecord(NameSymbol nameSymbol, String definition, + String dimensionName, UnitType unitType) { + this.nameSymbol = nameSymbol; + this.definition = definition; + this.dimensionName = dimensionName; + this.unitType = unitType; + } + + /** + * @return the definition + * @since 2022-04-16 + */ + public String definition() { + return this.definition; + } + + /** + * @return the dimensionName + * @since 2022-04-16 + */ + public String dimensionName() { + return this.dimensionName; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof UnitViewingRecord)) + return false; + final UnitViewingRecord other = (UnitViewingRecord) obj; + return Objects.equals(this.definition, other.definition) + && Objects.equals(this.dimensionName, other.dimensionName) + && Objects.equals(this.nameSymbol, other.nameSymbol) + && this.unitType == other.unitType; + } + + /** + * @return the nameSymbol + * @since 2022-04-16 + */ + @Override + public NameSymbol getNameSymbol() { + return this.nameSymbol; + } + + @Override + public int hashCode() { + return Objects.hash(this.definition, this.dimensionName, + this.nameSymbol, this.unitType); + } + + public NameSymbol nameSymbol() { + return this.nameSymbol; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("UnitViewingRecord [nameSymbol="); + builder.append(this.nameSymbol); + builder.append(", definition="); + builder.append(this.definition); + builder.append(", dimensionName="); + builder.append(this.dimensionName); + builder.append(", unitType="); + builder.append(this.unitType); + builder.append("]"); + return builder.toString(); + } + + /** + * @return the unitType + * @since 2022-04-16 + */ + public UnitType unitType() { + return this.unitType; + } + } + /** The presenter that works with this ViewBot */ private final Presenter presenter; @@ -62,6 +220,10 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView { private final List<UnitConversionRecord> unitConversions; /** Saved outputs of all unit expressions */ private final List<UnitConversionRecord> expressionConversions; + /** Saved outputs of all unit viewings */ + private final List<UnitViewingRecord> unitViewingRecords; + /** Saved outputs of all prefix viewings */ + private final List<PrefixViewingRecord> prefixViewingRecords; /** * Creates a new {@code ViewBot} with a new presenter. @@ -73,6 +235,8 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView { this.unitConversions = new ArrayList<>(); this.expressionConversions = new ArrayList<>(); + this.unitViewingRecords = new ArrayList<>(); + this.prefixViewingRecords = new ArrayList<>(); } /** @@ -80,7 +244,7 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView { * @since 2022-04-09 */ public List<UnitConversionRecord> expressionConversionList() { - return this.expressionConversions; + return Collections.unmodifiableList(this.expressionConversions); } /** @@ -158,6 +322,14 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView { throw new UnsupportedOperationException("Not implemented yet"); } + /** + * @return list of records of this viewBot's prefix views + * @since 2022-04-16 + */ + public List<PrefixViewingRecord> prefixViewList() { + return Collections.unmodifiableList(this.prefixViewingRecords); + } + @Override public void setDimensionNames(Set<String> dimensionNames) { this.dimensionNames = Objects.requireNonNull(dimensionNames, @@ -259,6 +431,24 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView { throw new UnsupportedOperationException("Not implemented yet"); } + public void setViewedPrefixName( + @SuppressWarnings("unused") Optional<String> viewedPrefixName) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public void setViewedPrefixName(String viewedPrefixName) { + this.setViewedPrefixName(Optional.of(viewedPrefixName)); + } + + public void setViewedUnitName( + @SuppressWarnings("unused") Optional<String> viewedUnitName) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public void setViewedUnitName(String viewedUnitName) { + this.setViewedUnitName(Optional.of(viewedUnitName)); + } + @Override public void showErrorMessage(String title, String message) { System.err.printf("%s: %s%n", title, message); @@ -299,4 +489,12 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView { public List<UnitConversionRecord> unitConversionList() { return Collections.unmodifiableList(this.unitConversions); } + + /** + * @return list of records of unit viewings made by this bot + * @since 2022-04-16 + */ + public List<UnitViewingRecord> unitViewList() { + return Collections.unmodifiableList(this.unitViewingRecords); + } } |