-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(SNSUNI-78): add DMS static factory methods for Latitude and Longi…
…tude
- Loading branch information
Showing
9 changed files
with
211 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ty-core/src/main/java/com/synerset/unitility/unitsystem/geographic/CardinalDirection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.synerset.unitility.unitsystem.geographic; | ||
|
||
public enum CardinalDirection { | ||
NORTH('w'), | ||
SOUTH('s'), | ||
EAST('e'), | ||
WEST('w'); | ||
|
||
private final char directionChar; | ||
|
||
CardinalDirection(char directionChar) { | ||
this.directionChar = directionChar; | ||
} | ||
|
||
char getDirectionChar() { | ||
return directionChar; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ility/unitsystem/CustomAngleUnitTest.java → ...stem/customunits/CustomAngleUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...ity-core/src/test/java/com/synerset/unitility/unitsystem/customunits/CustomTempUnits.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.synerset.unitility.unitsystem.customunits; | ||
|
||
import com.synerset.unitility.unitsystem.thermodynamic.TemperatureUnit; | ||
import com.synerset.unitility.unitsystem.thermodynamic.TemperatureUnits; | ||
|
||
import java.util.function.DoubleUnaryOperator; | ||
|
||
public enum CustomTempUnits implements TemperatureUnit { | ||
|
||
RANKINE("R", val -> val * 5 / 9, val -> val * 9 / 5); | ||
|
||
private final String symbol; | ||
private final DoubleUnaryOperator toBaseConverter; | ||
private final DoubleUnaryOperator fromBaseToUnitConverter; | ||
|
||
CustomTempUnits(String symbol, DoubleUnaryOperator toBaseConverter, DoubleUnaryOperator fromBaseToUnitConverter) { | ||
this.symbol = symbol; | ||
this.toBaseConverter = toBaseConverter; | ||
this.fromBaseToUnitConverter = fromBaseToUnitConverter; | ||
} | ||
|
||
@Override | ||
public String getSymbol() { | ||
return symbol; | ||
} | ||
|
||
@Override | ||
public double toValueInBaseUnit(double valueInThisUnit) { | ||
return toBaseConverter.applyAsDouble(valueInThisUnit); | ||
} | ||
|
||
@Override | ||
public double fromValueInBaseUnit(double valueInBaseUnit) { | ||
return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); | ||
} | ||
|
||
@Override | ||
public TemperatureUnit getBaseUnit() { | ||
return TemperatureUnits.KELVIN; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...re/src/test/java/com/synerset/unitility/unitsystem/customunits/CustomTemperatureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.synerset.unitility.unitsystem.customunits; | ||
|
||
import com.synerset.unitility.unitsystem.thermodynamic.Temperature; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class CustomTemperatureTest { | ||
|
||
@Test | ||
@DisplayName("should create and convert custom temperature") | ||
void customTemperature_shouldCreateAndConvertCustomTemperature(){ | ||
// Given | ||
Temperature temperatureInC = Temperature.ofKelvins(100); // 100.00 K | ||
Temperature temperatureInR = Temperature.of(200, CustomTempUnits.RANKINE); // 111.11 K | ||
|
||
// When | ||
Temperature totalTemperature = temperatureInC.plus(temperatureInR); | ||
|
||
// Then | ||
assertThat(totalTemperature).isEqualTo(Temperature.ofKelvins(100 + 111.11111111111111)); | ||
|
||
} | ||
} |
Oops, something went wrong.