diff --git a/src/main/resources/tech/units/indriya/format/messages_ar.properties b/src/main/resources/tech/units/indriya/format/messages_ar.properties index d49e3fdf..91b4d948 100644 --- a/src/main/resources/tech/units/indriya/format/messages_ar.properties +++ b/src/main/resources/tech/units/indriya/format/messages_ar.properties @@ -2,5 +2,12 @@ # Arabic # +# SI Prefixes +javax.measure.MetricPrefix.KILO = \u0643\u064A\u0644\u0648 +javax.measure.MetricPrefix.MEGA = \u0645\u064A\u063A\u0627 +javax.measure.MetricPrefix.MICRO = \u0645\u064A\u0643\u0631\u0648 +javax.measure.MetricPrefix.NANO = \u0646\u0627\u0646\u0648 +javax.measure.MetricPrefix.PICO = \u0628\u064A\u0643\u0648 + # Common Units tech.units.indriya.unit.Units.KILOMETRE_PER_HOUR = \u0643\u0645/\u0633 \ No newline at end of file diff --git a/src/main/resources/tech/units/indriya/format/messages_cn.properties b/src/main/resources/tech/units/indriya/format/messages_cn.properties index 75acbdfd..a90eed73 100644 --- a/src/main/resources/tech/units/indriya/format/messages_cn.properties +++ b/src/main/resources/tech/units/indriya/format/messages_cn.properties @@ -1,14 +1,17 @@ tech.units.indriya.unit.Units.CELSIUS.2 = \u6442\u6C0F\u6E29\u5EA6 tech.units.indriya.unit.Units.GRAM = \u514B +tech.units.indriya.unit.Units.LITRE = \u4F53\u79EF tech.units.indriya.unit.Units.HERTZ.2 = \u30D8\u30EB\u30C4 tech.units.indriya.unit.Units.METRE = \u7C73 #tech.units.indriya.unit.Units.ROENTGEN = \u306E tech.units.indriya.unit.Units.SECOND = \u79D2 + +# SI Prefixes javax.measure.MetricPrefix.CENTI = \u5398 javax.measure.MetricPrefix.DECI = \u5206 javax.measure.MetricPrefix.DECA = \u5341 javax.measure.MetricPrefix.HECTO = \u767E javax.measure.MetricPrefix.KILO = \u5343 -javax.measure.MetricPrefix.MEGA = M +javax.measure.MetricPrefix.MEGA = \u5146 javax.measure.MetricPrefix.MICRO = \u5FAE javax.measure.MetricPrefix.MILLI = \u6BEB diff --git a/src/main/resources/tech/units/indriya/format/messages_en.properties b/src/main/resources/tech/units/indriya/format/messages_en.properties index 9ec04232..f48f2625 100644 --- a/src/main/resources/tech/units/indriya/format/messages_en.properties +++ b/src/main/resources/tech/units/indriya/format/messages_en.properties @@ -101,49 +101,3 @@ tech.units.indriya.unit.Units.PERCENT = % tech.units.indriya.unit.Units.MINUTE = min tech.units.indriya.unit.Units.HOUR = h tech.units.indriya.unit.Units.DAY = d - -# British Imperial Units -#systems.uom.common.Imperial.PINT=pt - -# US Units -#tech.units.indriya.unit.US.ACRE = ac -#tech.units.indriya.unit.US.ARE = a -#tech.units.indriya.unit.US.CENTIRADIAN = crad -#tech.units.indriya.unit.US.FAHRENHEIT = \u00B0F -#tech.units.indriya.unit.US.FAHRENHEIT.1 = \u00B0F -#tech.units.indriya.unit.US.FAHRENHEIT.2 = Fahrenheit -#tech.units.indriya.unit.US.GRADE = grad -#tech.units.indriya.unit.US.HECTARE = ha -#tech.units.indriya.unit.US.HORSEPOWER = HP -#tech.units.indriya.unit.US.INCH = in -#tech.units.indriya.unit.US.MILE = mil -#tech.units.indriya.unit.US.POUND = lb -#tech.units.indriya.unit.US.MILES_PER_HOUR = mph -#tech.units.indriya.unit.US.YARD = yd - -# UCUM Units -#tech.units.indriya.unit.ucum.UCUM.ARE = a -#tech.units.indriya.unit.ucum.UCUM.BTU = BTU -#tech.units.indriya.unit.ucum.UCUM.FAHRENHEIT = \u00B0F -#tech.units.indriya.unit.ucum.UCUM.FAHRENHEIT.1 = \u00B0F -#tech.units.indriya.unit.ucum.UCUM.FAHRENHEIT.2 = Fahrenheit -#tech.units.indriya.unit.ucum.UCUM.FLUID_DRAM = fl_dr -#tech.units.indriya.unit.ucum.UCUM.FOOT = ft -#tech.units.indriya.unit.ucum.UCUM.FOOT_SURVEY = ft_survey -#tech.units.indriya.unit.ucum.UCUM.GALLON_DRY = gallon_dry -#tech.units.indriya.unit.ucum.UCUM.GALLON_LIQUID = gal -#tech.units.indriya.unit.ucum.UCUM.LITER = l -#tech.units.indriya.unit.ucum.UCUM.METER = m -#tech.units.indriya.unit.ucum.UCUM.MILES_PER_HOUR = mph -#tech.units.indriya.unit.ucum.UCUM.MINIM = min -#tech.units.indriya.unit.ucum.UCUM.BARREL = bbl -#tech.units.indriya.unit.ucum.UCUM.OUNCE = oz -#tech.units.indriya.unit.ucum.UCUM.OUNCE_LIQUID = fl_oz -#tech.units.indriya.unit.ucum.UCUM.RANKINE = \u00B0R -#tech.units.indriya.unit.ucum.UCUM.RANKINE.1 = \u00B0R -#tech.units.indriya.unit.ucum.UCUM.RANKINE.2 = Rankine -#tech.units.indriya.unit.ucum.UCUM.TABLESPOON = Tbsp -#tech.units.indriya.unit.ucum.UCUM.TABLESPOON.2 = Tablespoon -#tech.units.indriya.unit.ucum.UCUM.TEASPOON = tsp -#tech.units.indriya.unit.ucum.UCUM.TEASPOON.2 = Teaspoon -#tech.units.indriya.unit.ucum.UCUM.TON = ton diff --git a/src/test/java/tech/units/indriya/format/LocalUnitFormatTest.java b/src/test/java/tech/units/indriya/format/LocalUnitFormatTest.java index 65d0d266..e43e8f24 100644 --- a/src/test/java/tech/units/indriya/format/LocalUnitFormatTest.java +++ b/src/test/java/tech/units/indriya/format/LocalUnitFormatTest.java @@ -40,7 +40,6 @@ import javax.measure.Unit; import javax.measure.format.UnitFormat; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -61,9 +60,6 @@ public void testFormatPrefixGmps() { } @Test - @Disabled - // TODO LocalUnitFormat won't parse mixed units, EBNF does, also see - // https://github.com/unitsofmeasurement/uom-se/issues/145 public void testPrefixKm() { final UnitFormat format = LocalUnitFormat.getInstance(); Unit u = format.parse("km"); @@ -77,6 +73,13 @@ public void testFormatKm() { String s = format.format(KILO(METRE)); assertEquals("km", s); } + + @Test + public void testFormatKmCn() { + final UnitFormat localFormat = LocalUnitFormat.getInstance(new Locale("cn")); + String s = localFormat.format(KILO(METRE)); + assertEquals("千米", s); + } @Test public void testFormatN() { diff --git a/src/test/java/tech/units/indriya/format/LocalUnitPrefixOtherLocalesTest.java b/src/test/java/tech/units/indriya/format/LocalUnitPrefixOtherLocalesTest.java new file mode 100644 index 00000000..5130ebef --- /dev/null +++ b/src/test/java/tech/units/indriya/format/LocalUnitPrefixOtherLocalesTest.java @@ -0,0 +1,261 @@ +/* + * Units of Measurement Reference Implementation + * Copyright (c) 2005-2024, Jean-Marie Dautelle, Werner Keil, Otavio Santana. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of JSR-385, Indriya nor the names of their contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package tech.units.indriya.format; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.junit.jupiter.api.Assertions.*; +import static javax.measure.BinaryPrefix.EXBI; +import static javax.measure.BinaryPrefix.GIBI; +import static javax.measure.BinaryPrefix.KIBI; +import static javax.measure.BinaryPrefix.MEBI; +import static javax.measure.BinaryPrefix.PEBI; +import static javax.measure.BinaryPrefix.TEBI; +import static javax.measure.BinaryPrefix.YOBI; +import static javax.measure.BinaryPrefix.ZEBI; +import static javax.measure.MetricPrefix.*; +import static tech.units.indriya.NumberAssertions.assertNumberEquals; +import static tech.units.indriya.unit.Units.*; + +import java.util.Locale; + +import javax.measure.Quantity; +import javax.measure.format.UnitFormat; +import javax.measure.quantity.Length; +import javax.measure.quantity.Mass; +import javax.measure.quantity.Volume; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import tech.units.indriya.quantity.Quantities; +import tech.units.indriya.unit.Units; + +/** + * @author Werner Keil + * + */ +// TODO put those tests on a separate tag like "slow", "heavy", etc. +@Tag("l10n") +public class LocalUnitPrefixOtherLocalesTest { + + private static UnitFormat format; + + @BeforeAll + static void init() { + // TODO remove like LocalUnitFormatTest + format = LocalUnitFormat.getInstance(); + } + + @AfterAll + static void deInit() { + format = null; + } + + @Test + public void testKilo() { + assertEquals(format.format(KILOGRAM), format.format(KILO(GRAM))); + } + + @Test + public void testMegaCn() { + final UnitFormat localFormat = LocalUnitFormat.getInstance(new Locale("cn")); + Quantity m1 = Quantities.getQuantity(1.0, MEGA(Units.GRAM)); + assertNumberEquals(1d, m1.getValue(), 1E-12); + assertEquals("\u5146\u514B", localFormat.format(m1.getUnit())); + } + + @Test + public void testCentiCn() { + final UnitFormat localFormat = LocalUnitFormat.getInstance(new Locale("cn")); + Quantity m1 = Quantities.getQuantity(1.0, LITRE); + assertNumberEquals(1d, m1.getValue(), 1E-12); + assertEquals("体积", localFormat.format(m1.getUnit())); + + Quantity m2 = m1.to(CENTI(LITRE)); + assertNumberEquals(100, m2.getValue(), 1E-12); + assertEquals("\u5398体积", localFormat.format(m2.getUnit())); + } + + @Test + public void testDeciCn() { + final UnitFormat localFormat = LocalUnitFormat.getInstance(new Locale("cn")); + Quantity m1 = Quantities.getQuantity(1.0, LITRE); + assertNumberEquals(1d, m1.getValue(), 1E-12); + assertEquals("体积", localFormat.format(m1.getUnit())); + + Quantity m2 = m1.to(DECI(LITRE)); + assertNumberEquals(10, m2.getValue(), 1E-12); + assertEquals("\u5206体积", localFormat.format(m2.getUnit())); + } + + @Test + public void testMilliCn() { + final UnitFormat localFormat = LocalUnitFormat.getInstance(new Locale("cn")); + Quantity m1 = Quantities.getQuantity(1.0, MILLI(Units.GRAM)); + assertNumberEquals(1d, m1.getValue(), 1E-12); + assertEquals("毫\u514B", localFormat.format(m1.getUnit())); + } + + @Test + public void testMilli2Cn() { + final UnitFormat localFormat = LocalUnitFormat.getInstance(new Locale("cn")); + Quantity m1 = Quantities.getQuantity(10, MILLI(LITRE)); + assertNumberEquals(10, m1.getValue(), 1E-12); + assertEquals("毫体积", localFormat.format(m1.getUnit())); + } + + @Test + public void testMilli3() { + Quantity m1 = Quantities.getQuantity(1.0, LITRE); + assertNumberEquals(1d, m1.getValue(), 1E-12); + assertEquals("l", format.format(m1.getUnit())); + + Quantity m2 = m1.to(MILLI(LITRE)); + assertNumberEquals(1000L, m2.getValue(), 1E-12); + assertEquals("ml", format.format(m2.getUnit())); + } + + @Test + public void testMilli4() { + Quantity m1 = Quantities.getQuantity(1.0, MILLI(LITRE)); + assertNumberEquals(1d, m1.getValue(), 1E-12); + assertEquals("ml", format.format(m1.getUnit())); + + Quantity m2 = m1.to(LITRE); + assertNumberEquals(0.001d, m2.getValue(), 1E-12); + assertEquals("l", format.format(m2.getUnit())); + } + + @Test + public void testMicro2() { + Quantity m1 = Quantities.getQuantity(1.0, Units.METRE); + assertNumberEquals(1d, m1.getValue(), 1E-12); + assertEquals("m", format.format(m1.getUnit())); + + final Quantity m2 = m1.to(MICRO(Units.METRE)); + assertNumberEquals(1000_000L, m2.getValue(), 1E-12); + assertEquals("µm", format.format(m2.getUnit())); + } + + @Test + public void testNano() { + Quantity m1 = Quantities.getQuantity(1.0, Units.GRAM); + assertNumberEquals(1d, m1.getValue(), 1E-12); + assertEquals("g", format.format(m1.getUnit())); + + final Quantity m2 = m1.to(NANO(Units.GRAM)); + assertNumberEquals(1000_000_000L, m2.getValue(), 1E-12); + assertEquals("ng", format.format(m2.getUnit())); + } + + @Test + public void testNano2() { + Quantity m1 = Quantities.getQuantity(1.0, Units.METRE); + assertNumberEquals(1d, m1.getValue(), 1E-12); + assertEquals("m", format.format(m1.getUnit())); + + final Quantity m2 = m1.to(NANO(Units.METRE)); + assertNumberEquals(1000000000L, m2.getValue(), 1E-12); + assertEquals("nm", format.format(m2.getUnit())); + } + + @Test + public void testHashMapAccessingMap() { + assertThat(LITRE.toString(), is("l")); + assertThat(MILLI(LITRE).toString(), is("ml")); + assertThat(MILLI(GRAM).toString(), is("mg")); + } + + @Test + public void testKibi() { + final String s = format.format(KIBI(METRE)); + assertEquals("Kim", s); + } + + @Test + public void testKibiL() { + final String s = format.format(KIBI(LITRE)); + assertEquals("Kil", s); + } + + @Test + public void testKibiG() { + final String s = format.format(KIBI(GRAM)); + assertEquals("Kig", s); + } + + @Test + public void testMebi() { + assertEquals("Mim", format.format(MEBI(METRE))); + } + + @Test + public void testGibi() { + assertEquals("Gim", format.format(GIBI(METRE))); + } + + @Test + public void testTebi() { + assertEquals("Til", format.format(TEBI(LITRE))); + } + + @Test + public void testPebi() { + assertEquals("Pil", format.format(PEBI(LITRE))); + } + + @Test + public void testExbi() { + assertEquals("Eig", format.format(EXBI(GRAM))); + } + + @Test + public void testZebi() { + assertEquals("Zig", format.format(ZEBI(GRAM))); + } + + @Test + public void testYobi() { + assertEquals("Yig", format.format(YOBI(GRAM))); + } + + @Test + public void testQuetta() { + assertEquals("Ql", format.format(QUETTA(LITRE))); + } + + @Test + public void testRonto() { + assertEquals("rg", format.format(RONTO(GRAM))); + } +} diff --git a/src/test/java/tech/units/indriya/format/LocalUnitPrefixTest.java b/src/test/java/tech/units/indriya/format/LocalUnitPrefixTest.java index d92c175b..193d5aaf 100644 --- a/src/test/java/tech/units/indriya/format/LocalUnitPrefixTest.java +++ b/src/test/java/tech/units/indriya/format/LocalUnitPrefixTest.java @@ -90,6 +90,17 @@ public void testMega() { assertEquals("Mg", format.format(m1.getUnit())); } + @Test + public void testCenti() { + Quantity m1 = Quantities.getQuantity(1.0, LITRE); + assertNumberEquals(1d, m1.getValue(), 1E-12); + assertEquals("l", format.format(m1.getUnit())); + + Quantity m2 = m1.to(CENTI(LITRE)); + assertNumberEquals(100, m2.getValue(), 1E-12); + assertEquals("cl", format.format(m2.getUnit())); + } + @Test public void testDeci() { Quantity m1 = Quantities.getQuantity(1.0, LITRE); @@ -229,4 +240,14 @@ public void testZebi() { public void testYobi() { assertEquals("Yig", format.format(YOBI(GRAM))); } + + @Test + public void testQuetta() { + assertEquals("Ql", format.format(QUETTA(LITRE))); + } + + @Test + public void testRonto() { + assertEquals("rg", format.format(RONTO(GRAM))); + } }