From 3fdec81df17fd554951e191731413326b1dbdcd7 Mon Sep 17 00:00:00 2001 From: Younies Mahmoud Date: Mon, 20 Jan 2025 12:30:21 +0100 Subject: [PATCH] Added additional test cases for different units and scenarios, including edge cases and notes regarding CLDR handling. --- .../icu/dev/test/format/MeasureUnitTest.java | 61 +++++++++++++------ 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/icu4j/main/common_tests/src/test/java/com/ibm/icu/dev/test/format/MeasureUnitTest.java b/icu4j/main/common_tests/src/test/java/com/ibm/icu/dev/test/format/MeasureUnitTest.java index b817bd3e85be..bc64d401d23c 100644 --- a/icu4j/main/common_tests/src/test/java/com/ibm/icu/dev/test/format/MeasureUnitTest.java +++ b/icu4j/main/common_tests/src/test/java/com/ibm/icu/dev/test/format/MeasureUnitTest.java @@ -1316,7 +1316,7 @@ class TestCase { } @Test - public void TestConstantDenominator() { + public void TestAcceptableConstantDenominator() { class ConstantDenominatorTestCase { String identifier; long expectedConstantDenominator; @@ -1334,25 +1334,46 @@ class ConstantDenominatorTestCase { new ConstantDenominatorTestCase("second-per-1000-minute", 1000), new ConstantDenominatorTestCase("gram-per-1000-kilogram", 1000), new ConstantDenominatorTestCase("meter-per-100", 100), - new ConstantDenominatorTestCase("meter-per-1", 1), - new ConstantDenominatorTestCase("meter-per-10", 10), - new ConstantDenominatorTestCase("meter-per-100", 100), - new ConstantDenominatorTestCase("meter-per-1000", 1000), - new ConstantDenominatorTestCase("meter-per-10000", 10000), - new ConstantDenominatorTestCase("meter-per-100000", 100000), - new ConstantDenominatorTestCase("meter-per-1000000", 1000000), - new ConstantDenominatorTestCase("meter-per-10000000", 10000000), - new ConstantDenominatorTestCase("meter-per-100000000", 100000000), - new ConstantDenominatorTestCase("meter-per-1000000000", 1000000000), - new ConstantDenominatorTestCase("meter-per-10000000000", 10000000000L), - new ConstantDenominatorTestCase("meter-per-100000000000", 100000000000L), - new ConstantDenominatorTestCase("meter-per-1000000000000", 1000000000000L), - new ConstantDenominatorTestCase("meter-per-10000000000000", 10000000000000L), - new ConstantDenominatorTestCase("meter-per-100000000000000", 100000000000000L), - new ConstantDenominatorTestCase("meter-per-1000000000000000", 1000000000000000L), - new ConstantDenominatorTestCase("meter-per-10000000000000000", 10000000000000000L), - new ConstantDenominatorTestCase("meter-per-100000000000000000", 100000000000000000L), - new ConstantDenominatorTestCase("meter-per-1000000000000000000", 1000000000000000000L)); + new ConstantDenominatorTestCase("portion-per-1", 1), + new ConstantDenominatorTestCase("portion-per-10", 10), + new ConstantDenominatorTestCase("portion-per-100", 100), + new ConstantDenominatorTestCase("portion-per-1000", 1000), + new ConstantDenominatorTestCase("portion-per-10000", 10000), + new ConstantDenominatorTestCase("portion-per-100000", 100000), + new ConstantDenominatorTestCase("portion-per-1000000", 1000000), + new ConstantDenominatorTestCase("portion-per-10000000", 10000000), + new ConstantDenominatorTestCase("portion-per-100000000", 100000000), + new ConstantDenominatorTestCase("portion-per-1000000000", 1000000000), + new ConstantDenominatorTestCase("portion-per-10000000000", 10000000000L), + new ConstantDenominatorTestCase("portion-per-100000000000", 100000000000L), + new ConstantDenominatorTestCase("portion-per-1000000000000", 1000000000000L), + new ConstantDenominatorTestCase("portion-per-10000000000000", 10000000000000L), + new ConstantDenominatorTestCase("portion-per-100000000000000", 100000000000000L), + new ConstantDenominatorTestCase("portion-per-1000000000000000", 1000000000000000L), + new ConstantDenominatorTestCase("portion-per-10000000000000000", 10000000000000000L), + new ConstantDenominatorTestCase("portion-per-100000000000000000", 100000000000000000L), + new ConstantDenominatorTestCase("portion-per-1000000000000000000", 1000000000000000000L), + new ConstantDenominatorTestCase("portion-per-1e9", 1000000000L), + new ConstantDenominatorTestCase("portion-per-1E9", 1000000000L), + new ConstantDenominatorTestCase("portion-per-10e9", 10000000000L), + new ConstantDenominatorTestCase("portion-per-10E9", 10000000000L), + new ConstantDenominatorTestCase("portion-per-1e10", 10000000000L), + new ConstantDenominatorTestCase("portion-per-1E10", 10000000000L), + new ConstantDenominatorTestCase("portion-per-1e3-kilometer", 1000), + new ConstantDenominatorTestCase("liter-per-12345-kilometer", 12345), + new ConstantDenominatorTestCase("per-1000-kilometer", 1000), + new ConstantDenominatorTestCase("liter-per-1000-kiloliter", 1000), + // NOTE: The following constant denominator should be 0. However, since + // `100-kilometer` is treated as a unit in CLDR, + // the unit does not have a constant denominator. + // This issue should be addressed in CLDR. + new ConstantDenominatorTestCase("meter-per-100-kilometer", 0), + // NOTE: the following CLDR identifier should be invalid, but because + // `100-kilometer` is considered a unit in CLDR, + // one `100` will be considered as a unit constant denominator and the other + // `100` will be considered part of the unit. + // This issue should be addressed in CLDR. + new ConstantDenominatorTestCase("meter-per-100-100-kilometer", 100)); for (ConstantDenominatorTestCase testCase : testCases) { MeasureUnit unit = MeasureUnit.forIdentifier(testCase.identifier);