Skip to content

Commit 593d628

Browse files
committed
Add Symbol Aliases for better parsing
1 parent 6fd676a commit 593d628

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

unit-api-core/src/main/java/com/raynigon/unit/api/core/units/general/UnitScanUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private static Object createInstance(Constructor<?> it) {
3838
try {
3939
return it.newInstance();
4040
} catch (Exception e) {
41-
log.error("Unable to create Unit Instance for " + it.getName(), e);
41+
log.error("Unable to create Unit Instance for {}", it.getName(), e);
4242
return null;
4343
}
4444
}

unit-api-core/src/main/java/com/raynigon/unit/api/core/units/si/torque/NewtonMetre.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public NewtonMetre() {
1717

1818
@Override
1919
public String[] getSymbolAliases() {
20-
return new String[]{"N⋅m"};
20+
return new String[]{
21+
"N⋅m", // UTF-8 Middle Dot
22+
"N·m" // UTF-8 Interpunct
23+
};
2124
}
2225
}

unit-api-core/src/test/groovy/com/raynigon/unit/api/core/units/si/SISystemSpec.groovy

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.raynigon.unit.api.core.units.si
22

3+
import com.raynigon.unit.api.core.service.UnitsApiService
34
import com.raynigon.unit.api.core.units.si.acceleration.MetrePerSquaredSecond
45
import com.raynigon.unit.api.core.units.si.energy.Joule
56
import com.raynigon.unit.api.core.units.si.energy.KiloWattHour
@@ -17,12 +18,10 @@ import com.raynigon.unit.api.core.units.si.temperature.Kelvin
1718
import com.raynigon.unit.api.core.units.si.time.Hour
1819
import com.raynigon.unit.api.core.units.si.time.Minute
1920
import com.raynigon.unit.api.core.units.si.time.Second
21+
import com.raynigon.unit.api.core.units.si.torque.NewtonMetre
2022
import spock.lang.Specification
2123
import spock.lang.Unroll
2224

23-
import static com.raynigon.unit.api.core.service.UnitsApiService.quantity
24-
25-
2625
class SISystemSpec extends Specification {
2726

2827
@Unroll
@@ -59,54 +58,59 @@ class SISystemSpec extends Specification {
5958
"km/h" | new KilometrePerHour()
6059
// temperature
6160
"K" | new Kelvin()
61+
"°C" | new Celsius()
6262
"\u2103" | new Celsius()
6363
// time
6464
"s" | new Second()
6565
"min" | new Minute()
6666
"h" | new Hour()
67+
// torque
68+
"N m" | new NewtonMetre()
69+
"N·m" | new NewtonMetre()
70+
"N⋅m" | new NewtonMetre()
6771
}
6872

6973
def 'metre conversion'() {
7074

7175
when:
72-
def quantity = quantity(initialValue, unit)
76+
def quantity = UnitsApiService.quantity(initialValue, unit)
7377

7478
then:
7579
expectedValue == quantity.to(new Metre()).value.intValue()
7680

7781
where:
7882
unit | initialValue | expectedValue
79-
new Metre() | 1 | 1
80-
new Millimetre() | 1000 | 1
81-
new Kilometre() | 1 | 1000
83+
new Metre() | 1 | 1
84+
new Millimetre() | 1000 | 1
85+
new Kilometre() | 1 | 1000
8286
}
8387

8488
def 'energy conversion'() {
8589

8690
when:
87-
def quantity = quantity(initialValue, unit)
91+
def quantity = UnitsApiService.quantity(initialValue, unit)
8892

8993
then:
9094
expectedValue == quantity.to(new Joule()).value.intValue()
9195

9296
where:
9397
unit | initialValue | expectedValue
94-
new Joule() | 1 | 1
95-
new WattHour() | 1 | 3600
96-
new KiloWattHour() | 1 | 3600000
98+
new Joule() | 1 | 1
99+
new WattHour() | 1 | 3600
100+
new KiloWattHour() | 1 | 3600000
97101
}
98102

99103
def 'speed conversion'() {
100104

101105
when:
102-
def quantity = quantity(initialValue, unit)
106+
def quantity = UnitsApiService.quantity(initialValue, unit)
103107

104108
then:
105109
expectedValue == quantity.to(new MetrePerSecond()).value.intValue()
106110

107111
where:
108112
unit | initialValue | expectedValue
109-
new MetrePerSecond() | 1 | 1
110-
new KilometrePerHour() | 36 | 10
113+
new MetrePerSecond() | 1 | 1
114+
new KilometrePerHour() | 36 | 10
111115
}
112116
}

0 commit comments

Comments
 (0)