// Load factor for a single source
void loadSingleFactor(Factor &factor, StringPiece source, UErrorCode &status) {
factor.source = source;
- bool reciprocal = false;
- // TODO(younies): illustrate this step.
- if (source.substr(0, 7) == "one-per") {
- reciprocal = true;
- source = source.substr(8); // e.g. one-per-second --> second
- }
for (const auto &entry : temporarily::dataEntries) {
if (entry.source == factor.source) {
factor.target = entry.target;
factor.offset.setTo(entry.offset, status);
factor.reciprocal = factor.reciprocal;
- if (reciprocal) {
- factor.flip(status);
- }
-
return;
}
}
auto singleUnit = TempSingleUnit::forMeasureUnit(singleUnits[i], status);
loadSingleFactor(singleFactor, singleUnit.identifier, status);
- singleFactor.power(singleUnit.dimensionality, status);
+
+ // You must apply SiPrefix before the power, because the power may be will flip the factor.
singleFactor.applySiPrefix(singleUnit.siPrefix, status);
- // TODO(younies): handle `one-per-second` case
+ singleFactor.power(singleUnit.dimensionality, status);
+
factor.multiplyBy(singleFactor, status);
}
}
void testMass();
void testTemperature();
void testArea();
+ void testComplicatedUnits();
// TODO(younies): fix this.
void verifyTestCase(const UnitConversionTestCase &testCase);
TESTCASE_AUTO(testMass);
TESTCASE_AUTO(testTemperature);
TESTCASE_AUTO(testArea);
+ TESTCASE_AUTO(testComplicatedUnits);
TESTCASE_AUTO_END;
}
}
}
+void UnitsTest::testComplicatedUnits() {
+ IcuTestErrorCode status(*this, "Units Area");
+
+ UnitConversionTestCase testCases[]{
+ {"meter-per-second", "meter-per-millisecond", 1000.0, 1.0} //
+ };
+
+ for (const auto &testCase : testCases) {
+ verifyTestCase(testCase);
+ }
+}
+
#endif /* #if !UCONFIG_NO_FORMATTING */