Skip to content

Commit

Permalink
ICU-22781 Add test for portion format with parts per billion (C++)
Browse files Browse the repository at this point in the history
See #3389
  • Loading branch information
younies authored and Squash Bot committed Feb 11, 2025
1 parent 84599e1 commit 4ea4a56
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions icu4c/source/test/intltest/numbertest.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class NumberFormatterApiTest : public IntlTestWithFieldPosition {
void toDecimalNumber();
void microPropsInternals();
void formatUnitsAliases();
void TestPortionFormat();
void testIssue22378();

void runIndexedTest(int32_t index, UBool exec, const char*& name, char* par = nullptr) override;
Expand Down
39 changes: 39 additions & 0 deletions icu4c/source/test/intltest/numbertest_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ void NumberFormatterApiTest::runIndexedTest(int32_t index, UBool exec, const cha
TESTCASE_AUTO(toDecimalNumber);
TESTCASE_AUTO(microPropsInternals);
TESTCASE_AUTO(formatUnitsAliases);
TESTCASE_AUTO(TestPortionFormat);
TESTCASE_AUTO(testIssue22378);
TESTCASE_AUTO_END;
}
Expand Down Expand Up @@ -6085,6 +6086,44 @@ void NumberFormatterApiTest::formatUnitsAliases() {
}
}

void NumberFormatterApiTest::TestPortionFormat() {
IcuTestErrorCode status(*this, "TestPortionFormat");

struct TestCase {
const char *unitIdentifier;
const char *locale;
double inputValue;
UnicodeString expectedOutput;
} testCases[]{
{"portion-per-1e9", "en-US", 1, "1 part per billion"},
{"portion-per-1e9", "en-US", 2, "2 parts per billion"},
{"portion-per-1e9", "en-US", 1000000, "1,000,000 parts per billion"},
{"portion-per-1e9", "de-DE", 1000000, "1.000.000 Milliardstel"},
{"portion-per-1e1", "en-US", 1, "UNKNOWN"},
{"portion-per-1e2", "en-US", 1, "UNKNOWN"},
{"portion-per-1e3", "en-US", 1, "UNKNOWN"},
{"portion-per-1e4", "en-US", 1, "UNKNOWN"},
{"portion-per-1e5", "en-US", 1, "UNKNOWN"},
{"portion-per-1e6", "en-US", 1, "UNKNOWN"},
{"portion-per-1e7", "en-US", 1, "UNKNOWN"},
{"portion-per-1e8", "en-US", 1, "UNKNOWN"},
};

for (auto testCase : testCases) {
if (uprv_strcmp(testCase.unitIdentifier, "portion-per-1e9") != 0) {
logKnownIssue("CLDR-18274", "The data for portion-per-XYZ is not determined yet.");
continue;
}
MeasureUnit unit = MeasureUnit::forIdentifier(testCase.unitIdentifier, status);
LocalizedNumberFormatter lnf =
NumberFormatter::withLocale(Locale::forLanguageTag(testCase.locale, status))
.unit(unit)
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME);
UnicodeString actualOutput = lnf.formatDouble(testCase.inputValue, status).toString(status);
assertEquals("test portion format", testCase.expectedOutput, actualOutput);
}
}

void NumberFormatterApiTest::testIssue22378() {
IcuTestErrorCode status(*this, "testIssue22378");

Expand Down

0 comments on commit 4ea4a56

Please sign in to comment.