]> granicus.if.org Git - icu/commitdiff
Move testGetConversionRateInfo to UnitsDataTest
authorHugo van der Merwe <17109322+hugovdm@users.noreply.github.com>
Sat, 28 Mar 2020 18:29:37 +0000 (19:29 +0100)
committerHugo van der Merwe <17109322+hugovdm@users.noreply.github.com>
Sat, 28 Mar 2020 18:29:37 +0000 (19:29 +0100)
icu4c/source/test/intltest/Makefile.in
icu4c/source/test/intltest/intltest.vcxproj
icu4c/source/test/intltest/intltest.vcxproj.filters
icu4c/source/test/intltest/itformat.cpp
icu4c/source/test/intltest/unitsdatatest.cpp [new file with mode: 0644]
icu4c/source/test/intltest/unitstest.cpp

index 5878d6b19ca43b596e5bd34927917dbc8436c919..cb356c44db9fda5ec25689387d19c0a252a57a78 100644 (file)
@@ -69,7 +69,7 @@ string_segment_test.o \
 numbertest_parse.o numbertest_doubleconversion.o numbertest_skeletons.o \
 static_unisets_test.o numfmtdatadriventest.o numbertest_range.o erarulestest.o \
 formattedvaluetest.o formatted_string_builder_test.o numbertest_permutation.o \
-unitstest.o unitsroutertest.o
+unitsdatatest.o unitstest.o unitsroutertest.o
 
 DEPS = $(OBJECTS:.o=.d)
 
index 78084b976c87028e25583039dc5bd2cf569e5cc8..f659cda193c3fce24502db6f9cf0258006321d15 100644 (file)
     <ClCompile Include="formattedvaluetest.cpp" />
     <ClCompile Include="localebuildertest.cpp" />
     <ClCompile Include="localematchertest.cpp" />
+    <ClCompile Include="unitsdatatest.cpp" />
     <ClCompile Include="unitstest.cpp" />
     <ClCompile Include="unitsroutertest.cpp" />
   </ItemGroup>
index adf9068a83805be625d63f57afb9e3a91ba2040a..bba4e921982d5f2265c41301243891950492f8e4 100644 (file)
     <ClCompile Include="localematchertest.cpp">
       <Filter>locales &amp; resources</Filter>
     </ClCompile>
+    <ClCompile Include="unitsdatatest.cpp">
+      <Filter>formatting</Filter>
+    </ClCompile>
     <ClCompile Include="unitstest.cpp">
       <Filter>formatting</Filter>
     </ClCompile>
index 7ee86dbd9ab9b5fb0b2d87467f079ca700e01f84..a2b5ffec67a95702b2cb1de4c7c9a0f6327acf4d 100644 (file)
@@ -74,6 +74,7 @@ extern IntlTest *createScientificNumberFormatterTest();
 extern IntlTest *createFormattedValueTest();
 extern IntlTest *createFormattedStringBuilderTest();
 extern IntlTest *createStringSegmentTest();
+extern IntlTest *createUnitsDataTest();
 extern IntlTest *createUnitsTest();
 extern IntlTest *createUnitsRouterTest();
 
@@ -259,6 +260,15 @@ void IntlTestFormat::runIndexedTest( int32_t index, UBool exec, const char* &nam
           }
           break;
         case 57:
+          name = "UnitsDataTest";
+          if (exec) {
+            logln("UnitsDataTest test---");
+            logln((UnicodeString)"");
+            LocalPointer<IntlTest> test(createUnitsDataTest());
+            callTest(*test, par);
+          }
+          break;
+        case 58:
           name = "UnitsRouterTest";
           if (exec) {
             logln("UnitsRouterTest test---");
diff --git a/icu4c/source/test/intltest/unitsdatatest.cpp b/icu4c/source/test/intltest/unitsdatatest.cpp
new file mode 100644 (file)
index 0000000..225482d
--- /dev/null
@@ -0,0 +1,123 @@
+// © 2020 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html#License
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "intltest.h"
+#include "unitsdata.h"
+
+class UnitsDataTest : public IntlTest {
+    public:
+    UnitsDataTest() {}
+
+    void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = NULL);
+
+    void testGetConversionRateInfo();
+};
+
+extern IntlTest *createUnitsDataTest() { return new UnitsDataTest(); }
+
+void UnitsDataTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char * /*par*/) {
+    if (exec) { logln("TestSuite UnitsDataTest: "); }
+    TESTCASE_AUTO_BEGIN;
+    TESTCASE_AUTO(testGetConversionRateInfo);
+    TESTCASE_AUTO_END;
+}
+
+void UnitsDataTest::testGetConversionRateInfo() {
+    const int MAX_NUM_RATES = 5;
+    struct {
+        // The source unit passed to getConversionRateInfo.
+        const char *sourceUnit;
+        // The target unit passed to getConversionRateInfo.
+        const char *targetUnit;
+        // Expected: units whose conversion rates are expected in the results.
+        const char *expectedOutputs[MAX_NUM_RATES];
+        // Expected "base unit", to serve as pivot between source and target.
+        const char *expectedBaseUnit;
+    } testCases[]{
+        {"centimeter-per-square-milligram",
+         "inch-per-square-ounce",
+         {"meter", "gram", "inch", "ounce", NULL},
+         "meter-per-square-kilogram"},
+
+        {"liter", "gallon", {"liter", "gallon", NULL, NULL, NULL}, "cubic-meter"},
+
+        // Sequence
+        {"stone-and-pound", "ton", {"pound", "stone", "ton", NULL, NULL}, "kilogram"},
+
+        {"mile-per-hour",
+         "dekameter-per-hour",
+         {"mile", "hour", "meter", NULL, NULL},
+         "meter-per-second"},
+
+        // Power: watt
+        {"watt",
+         "horsepower",
+         {"watt", "horsepower", NULL, NULL, NULL},
+         "kilogram-square-meter-per-cubic-second"},
+
+        // Energy: joule
+        {"therm-us",
+         "kilogram-square-meter-per-square-second",
+         {"therm-us", "kilogram", "meter", "second", NULL},
+         "kilogram-square-meter-per-square-second"},
+
+        // WIP/FIXME(hugovdm): I think I found a bug in targetBaseUnit.product():
+        // Target Base: <kilogram-square-meter-per-square-second> x <one-per-meter> => <meter>
+        //
+        // // Joule-per-meter
+        // {"therm-us-per-meter",
+        //  "joule-per-meter",
+        //  {"therm-us", "joule", "meter", NULL, NULL},
+        //  "kilogram-meter-per-square-second"},
+
+        // TODO: include capacitance test case with base unit:
+        // pow4-second-square-ampere-per-kilogram-square-meter;
+    };
+    for (const auto &t : testCases) {
+        logln("---testing: source=\"%s\", target=\"%s\", expectedBaseUnit=\"%s\"", t.sourceUnit,
+              t.targetUnit, t.expectedBaseUnit);
+        IcuTestErrorCode status(*this, "testGetConversionRateInfo");
+
+        MeasureUnit baseCompoundUnit;
+        MeasureUnit sourceUnit = MeasureUnit::forIdentifier(t.sourceUnit, status);
+        MeasureUnit targetUnit = MeasureUnit::forIdentifier(t.targetUnit, status);
+        MaybeStackVector<ConversionRateInfo> conversionInfo =
+            getConversionRatesInfo(sourceUnit, targetUnit, &baseCompoundUnit, status);
+        if (status.errIfFailureAndReset("getConversionRatesInfo(<%s>, <%s>, ...)",
+                                        sourceUnit.getIdentifier(), targetUnit.getIdentifier())) {
+            continue;
+        }
+
+        assertEquals("baseCompoundUnit returned by getConversionRatesInfo", t.expectedBaseUnit,
+                     baseCompoundUnit.getIdentifier());
+        int countExpected;
+        for (countExpected = 0; countExpected < MAX_NUM_RATES; countExpected++) {
+            auto expected = t.expectedOutputs[countExpected];
+            if (expected == NULL) break;
+            // Check if this conversion rate was expected
+            bool found = false;
+            for (int i = 0; i < conversionInfo.length(); i++) {
+                auto cri = conversionInfo[i];
+                if (strcmp(expected, cri->sourceUnit.data()) == 0) {
+                    found = true;
+                    break;
+                }
+            }
+            assertTrue(UnicodeString("<") + expected + "> expected", found);
+        }
+        assertEquals("number of conversion rates", countExpected, conversionInfo.length());
+
+        // Convenience output for debugging
+        for (int i = 0; i < conversionInfo.length(); i++) {
+            ConversionRateInfo *cri = conversionInfo[i];
+            logln("* conversionInfo %d: source=\"%s\", baseUnit=\"%s\", factor=\"%s\", "
+                  "offset=\"%s\"",
+                  i, cri->sourceUnit.data(), cri->baseUnit.data(), cri->factor.data(),
+                  cri->offset.data());
+        }
+    }
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
index a130e38dc0cc49095e4f2904d051b57df676c7dd..9675cbbfc42573fa8eb17462e669c7a448d6163e 100644 (file)
@@ -59,7 +59,6 @@ void UnitsTest::runIndexedTest(int32_t index, UBool exec, const char *&name, cha
     TESTCASE_AUTO_BEGIN;
     TESTCASE_AUTO(testConversions);
     TESTCASE_AUTO(testPreferences);
-    TESTCASE_AUTO(testGetConversionRateInfo);
     TESTCASE_AUTO(testGetUnitsData);
 
     TESTCASE_AUTO(testBasic);
@@ -580,102 +579,6 @@ void UnitsTest::testPreferences() {
     }
 }
 
-void UnitsTest::testGetConversionRateInfo() {
-    const int MAX_NUM_RATES = 5;
-    struct {
-        // The source unit passed to getConversionRateInfo.
-        const char *sourceUnit;
-        // The target unit passed to getConversionRateInfo.
-        const char *targetUnit;
-        // Expected: units whose conversion rates are expected in the results.
-        const char *expectedOutputs[MAX_NUM_RATES];
-        // Expected "base unit", to serve as pivot between source and target.
-        const char *expectedBaseUnit;
-    } testCases[]{
-        {"centimeter-per-square-milligram",
-         "inch-per-square-ounce",
-         {"meter", "gram", "inch", "ounce", NULL},
-         "meter-per-square-kilogram"},
-
-        {"liter", "gallon", {"liter", "gallon", NULL, NULL, NULL}, "cubic-meter"},
-
-        // Sequence
-        {"stone-and-pound", "ton", {"pound", "stone", "ton", NULL, NULL}, "kilogram"},
-
-        {"mile-per-hour",
-         "dekameter-per-hour",
-         {"mile", "hour", "meter", NULL, NULL},
-         "meter-per-second"},
-
-        // Power: watt
-        {"watt",
-         "horsepower",
-         {"watt", "horsepower", NULL, NULL, NULL},
-         "kilogram-square-meter-per-cubic-second"},
-
-        // Energy: joule
-        {"therm-us",
-         "kilogram-square-meter-per-square-second",
-         {"therm-us", "kilogram", "meter", "second", NULL},
-         "kilogram-square-meter-per-square-second"},
-
-        // WIP/FIXME(hugovdm): I think I found a bug in targetBaseUnit.product():
-        // Target Base: <kilogram-square-meter-per-square-second> x <one-per-meter> => <meter>
-        //
-        // // Joule-per-meter
-        // {"therm-us-per-meter",
-        //  "joule-per-meter",
-        //  {"therm-us", "joule", "meter", NULL, NULL},
-        //  "kilogram-meter-per-square-second"},
-
-        // TODO: include capacitance test case with base unit:
-        // pow4-second-square-ampere-per-kilogram-square-meter;
-    };
-    for (const auto &t : testCases) {
-        logln("---testing: source=\"%s\", target=\"%s\", expectedBaseUnit=\"%s\"", t.sourceUnit,
-              t.targetUnit, t.expectedBaseUnit);
-        IcuTestErrorCode status(*this, "testGetConversionRateInfo");
-
-        MeasureUnit baseCompoundUnit;
-        MeasureUnit sourceUnit = MeasureUnit::forIdentifier(t.sourceUnit, status);
-        MeasureUnit targetUnit = MeasureUnit::forIdentifier(t.targetUnit, status);
-        MaybeStackVector<ConversionRateInfo> conversionInfo =
-            getConversionRatesInfo(sourceUnit, targetUnit, &baseCompoundUnit, status);
-        if (status.errIfFailureAndReset("getConversionRatesInfo(<%s>, <%s>, ...)",
-                                        sourceUnit.getIdentifier(), targetUnit.getIdentifier())) {
-            continue;
-        }
-
-        assertEquals("baseCompoundUnit returned by getConversionRatesInfo", t.expectedBaseUnit,
-                     baseCompoundUnit.getIdentifier());
-        int countExpected;
-        for (countExpected = 0; countExpected < MAX_NUM_RATES; countExpected++) {
-            auto expected = t.expectedOutputs[countExpected];
-            if (expected == NULL) break;
-            // Check if this conversion rate was expected
-            bool found = false;
-            for (int i = 0; i < conversionInfo.length(); i++) {
-                auto cri = conversionInfo[i];
-                if (strcmp(expected, cri->sourceUnit.data()) == 0) {
-                    found = true;
-                    break;
-                }
-            }
-            assertTrue(UnicodeString("<") + expected + "> expected", found);
-        }
-        assertEquals("number of conversion rates", countExpected, conversionInfo.length());
-
-        // Convenience output for debugging
-        for (int i = 0; i < conversionInfo.length(); i++) {
-            ConversionRateInfo *cri = conversionInfo[i];
-            logln("* conversionInfo %d: source=\"%s\", baseUnit=\"%s\", factor=\"%s\", "
-                  "offset=\"%s\"",
-                  i, cri->sourceUnit.data(), cri->baseUnit.data(), cri->factor.data(),
-                  cri->offset.data());
-        }
-    }
-}
-
 // We test "successfully loading some data", not specific output values, since
 // this would duplicate some of the input data. We leave end-to-end testing to
 // take care of that. Running `intltest` with `-v` will print out the loaded