Skip to content

Commit

Permalink
CLDR-15954 Add test cases without preference data, and without quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
macchiati committed Mar 17, 2024
1 parent d81d7bb commit a9cd36f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ public static TypeAndCore splitUnit(String longOrShortUnit, TypeAndCore typeAndC
}

public static String getShort(String longUnit) {
return LONG_TO_SHORT.get(longUnit);
String result = LONG_TO_SHORT.get(longUnit);
return result == null ? longUnit : result;
}

public static String getLong(String shortId) {
return LONG_TO_SHORT.inverse().get(shortId);
String result = LONG_TO_SHORT.inverse().get(shortId);
return result == null ? shortId : result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4382,7 +4382,31 @@ public void testPreferencesWithLocales() {
"default",
"en-u-mu-stone",
Rational.TWO,
"stone"));
"stone"),
List.of(
1,
MeasureUnit.forIdentifier(
"candela"), // a unit whose quantity has no preference data
"default",
"en",
Rational.ONE,
"candela"),
List.of(
1,
MeasureUnit.forIdentifier(
"candela-per-byte"), // a unit that has no quantity
"default",
"en",
Rational.of(1, 8),
"candela-per-bit"),
List.of(
1,
MeasureUnit.forIdentifier(
"candela-per-cubic-foot"), // a unit that has no quantity
"default",
"en",
Rational.of(1953125000, 55306341),
"candela-per-cubic-meter"));
for (boolean isICU : List.of(false, true)) {
for (List<Object> test : tests) {
String actualUnit;
Expand All @@ -4400,16 +4424,15 @@ public void testPreferencesWithLocales() {
Rational rationalAmount = Rational.of(sourceAmount.toString());
UnitPreferences prefs = SDI.getUnitPreferences();
final ULocale uLocale = ULocale.forLanguageTag(languageTag);
UnitPreference unitPreference1 =
UnitPreference unitPreference =
prefs.getUnitPreference(
rationalAmount, sourceUnitString, usage, uLocale);
if (unitPreference1 == null) { // if the quantity isn't found
if (unitPreference == null) { // if the quantity isn't found
throw new IllegalArgumentException(
String.format(
"No unit preferences found for unit: %s, usage: %s, locale:%s",
sourceUnitString, usage, languageTag));
}
UnitPreference unitPreference = unitPreference1;
actualUnit = unitPreference.unit;
actualValue =
converter.convert(
Expand Down

0 comments on commit a9cd36f

Please sign in to comment.