]> granicus.if.org Git - icu/commitdiff
ICU-21480 brs 69rc, add tests to verify that rbnf spellout is the same for no,nb
authorPeter Edberg <pedberg@unicode.org>
Wed, 10 Mar 2021 00:36:07 +0000 (16:36 -0800)
committerPeter Edberg <42151464+pedberg-icu@users.noreply.github.com>
Wed, 10 Mar 2021 21:51:32 +0000 (13:51 -0800)
icu4c/source/test/intltest/itrbnf.cpp
icu4c/source/test/intltest/itrbnf.h
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/RbnfTest.java

index d5487cc6ae576f16cad5dcb20fdcc77ed6c36cd4..73f553256347c31e69d665e54894060a7f55e612 100644 (file)
@@ -77,6 +77,7 @@ void IntlTestRBNF::runIndexedTest(int32_t index, UBool exec, const char* &name,
         TESTCASE(25, TestCompactDecimalFormatStyle);
         TESTCASE(26, TestParseFailure);
         TESTCASE(27, TestMinMaxIntegerDigitsIgnored);
+        TESTCASE(28, TestNorwegianSpellout);
 #else
         TESTCASE(0, TestRBNFDisabled);
 #endif
@@ -1604,6 +1605,38 @@ IntlTestRBNF::TestThaiSpellout()
     delete formatter;
 }
 
+void
+IntlTestRBNF::TestNorwegianSpellout()
+{
+    UErrorCode status = U_ZERO_ERROR;
+    RuleBasedNumberFormat* noFormatter
+        = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale("no"), status);
+    RuleBasedNumberFormat* nbFormatter
+        = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale("nb"), status);
+
+    if (U_FAILURE(status)) {
+        errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status));
+    } else {
+        static const char* testDataDefault[][2] = {
+            { "1", "\\u00E9n" },
+            { "2", "to" },
+            { "3", "tre" },
+            { "4", "fire" },
+            { "101", "hundre og \\u00E9n" },
+            { "123", "hundre og tjue\\u00ADtre" },
+            { "1,001", "tusen og \\u00E9n" },
+            { "1,100", "tusen hundre" },
+            { "6.789", "seks komma sju \\u00E5tte ni" },
+            { "-5.678", "minus fem komma seks sju \\u00E5tte" },
+            { NULL, NULL }
+        };
+        doTest(noFormatter, testDataDefault, TRUE);
+        doTest(nbFormatter, testDataDefault, TRUE);
+    }
+    delete nbFormatter;
+    delete noFormatter;
+}
+
 void
 IntlTestRBNF::TestSwedishSpellout()
 {
index c82b50d86fe0a7d67bdad85d200b70f98e2e8fff..5cb97ea2b5fb7c22acfa7958ecd6bf9ed98d6cd8 100644 (file)
@@ -101,6 +101,11 @@ class IntlTestRBNF : public IntlTest {
    */
   void TestThaiSpellout();
 
+  /**
+   * Perform a simple spot check on the Norwegian (no,nb) spellout rules
+   */
+  void TestNorwegianSpellout();
+
   /**
    * Perform a simple spot check on the Swedish spellout rules
    */
index c062f5e52d84b243a8441365770d094d4abb7045..e7973255982a479fda897922179577e2ab248972 100644 (file)
@@ -820,6 +820,35 @@ public class RbnfTest extends TestFmwk {
         doTest(formatter, testData, false); // exact values aren't parsable from fractions
     }
 
+    @Test
+    public void TestNorwegianSpellout()
+    {
+        Locale noLocale = new Locale("no", "", "");
+        Locale nbLocale = new Locale("nb", "", "");
+        RuleBasedNumberFormat noFormatter = new RuleBasedNumberFormat(noLocale,
+                RuleBasedNumberFormat.SPELLOUT);
+        RuleBasedNumberFormat nbFormatter = new RuleBasedNumberFormat(nbLocale,
+                RuleBasedNumberFormat.SPELLOUT);
+
+        String[][] testDataDefault = {
+                { "1", "\u00E9n" },
+                { "2", "to" },
+                { "3", "tre" },
+                { "4", "fire" },
+                { "101", "hundre og \u00E9n" },
+                { "123", "hundre og tjue\u00ADtre" },
+                { "1,001", "tusen og \u00E9n" },
+                { "1,100", "tusen hundre" },
+                { "6.789", "seks komma sju \u00E5tte ni" },
+                { "-5.678", "minus fem komma seks sju \u00E5tte" },
+        };
+
+        logln("testing default rules");
+        doTest(noFormatter, testDataDefault, true);
+        doTest(nbFormatter, testDataDefault, true);
+
+    }
+
     @Test
     public void TestSwedishSpellout()
     {