sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1773510 - in /sis/branches/JDK8/core/sis-utility/src: main/java/org/apache/sis/measure/UnitFormat.java test/java/org/apache/sis/measure/UnitFormatTest.java
Date Sat, 10 Dec 2016 09:23:50 GMT
Author: desruisseaux
Date: Sat Dec 10 09:23:50 2016
New Revision: 1773510

URL: http://svn.apache.org/viewvc?rev=1773510&view=rev
Log:
Add tests about units of measurement parsing with parenthesis, e.g. "kg∕(m⋅s²)".

Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitFormatTest.java

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java?rev=1773510&r1=1773509&r2=1773510&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
[UTF-8] Sat Dec 10 09:23:50 2016
@@ -969,11 +969,9 @@ scan:   for (int n; i < end; i += n) {
              * overridden by an explicit × or / symbol, which is what happened if we reach
this point (tip: look in
              * the above 'switch' statement all cases that end with 'break', not 'break scan'
or 'continue').
              */
-            if (operation == IMPLICIT) {
-                operation = next;
-                continue;
+            if (operation != IMPLICIT) {
+                unit = apply(operation, unit, parseSymbol(symbols, start, i));
             }
-            unit = apply(operation, unit, parseSymbol(symbols, start, i));
             operation = next;
             start = i + n;
         }

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitFormatTest.java?rev=1773510&r1=1773509&r2=1773510&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitFormatTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitFormatTest.java
[UTF-8] Sat Dec 10 09:23:50 2016
@@ -374,10 +374,23 @@ public final strictfp class UnitFormatTe
     public void testParseMultiplier() {
         final UnitFormat f = new UnitFormat(Locale.UK);
         assertSame(Units.MILLIMETRE, f.parse("m/1000"));
+        assertSame(Units.KILOMETRE,  f.parse( "1000*m"));
+        assertSame(Units.KILOMETRE,  f.parse( "1000.0*m"));
         ConventionalUnitTest.verify(Units.METRE, f.parse("10*-6⋅m"),   "µm", 1E-6);
         ConventionalUnitTest.verify(Units.METRE, f.parse("10*-6.m"),   "µm", 1E-6);
-        ConventionalUnitTest.verify(Units.METRE, f.parse( "1000*m"),   "km", 1E+3);
-        ConventionalUnitTest.verify(Units.METRE, f.parse( "1000.0*m"), "km", 1E+3);
         ConventionalUnitTest.verify(Units.METRE, f.parse( "100 feet"), null, 30.48);
     }
+
+    /**
+     * Tests parsing expressions containing parenthesis.
+     */
+    @Test
+    @DependsOnMethod("testParseMultiplier")
+    public void testParseWithParenthesis() {
+        final UnitFormat f = new UnitFormat(Locale.UK);
+        assertSame(Units.PASCAL, f.parse("kg∕(m⋅s²)"));
+        assertSame(Units.PASCAL, f.parse("(kg)∕m∕s²"));
+        assertSame(Units.VOLT,   f.parse("kg⋅m²∕(s³⋅A)"));
+        assertSame(Units.VOLT,   f.parse("(kg)m²∕(s³⋅A)"));
+    }
 }



Mime
View raw message