return TRUE;
}
-// http://junit.sourceforge.net/javadoc/org/junit/Assert.html#assertEquals(java.lang.String,%20double,%20double,%20double)
-UBool IntlTest::assertEqualsNear(const char *message, double expected, double actual, double precision) {
- double diff = std::abs(expected - actual);
- double diffPercent =
- expected != 0 ? diff / expected
- : diff; // If the expected is equals zero, we assume that
- // the `diffPercent` is equal to the difference
- // between the actual and the expected
-
- if (diffPercent > precision) {
- errln((UnicodeString) "FAIL: " + message + "; got " + actual + "; expected " + expected);
- return FALSE;
- }
-#ifdef VERBOSE_ASSERTIONS
- else {
- logln((UnicodeString) "Ok: " + message + "; got " + expected);
- }
-#endif
- return TRUE;
-}
+// // TODO: the following link is misleading, since JUnit does absolute numbers and
+// // this code does relative, and this code doesn't support NaN whereas JUnit
+// // does. JUnit's function is also simply overloading "assertEquals".
+// // http://junit.sourceforge.net/javadoc/org/junit/Assert.html#assertEquals(java.lang.String,%20double,%20double,%20double)
+// UBool IntlTest::assertEqualsNear(const char *message, double expected, double actual, double precision) {
+// double diff = std::abs(expected - actual);
+// double diffPercent =
+// expected != 0 ? diff / expected
+// : diff; // If the expected is equals zero, we assume that
+// // the `diffPercent` is equal to the difference
+// // between the actual and the expected
+
+// if (diffPercent > precision) {
+// errln((UnicodeString) "FAIL: " + message + "; got " + actual + "; expected " + expected);
+// return FALSE;
+// }
+// #ifdef VERBOSE_ASSERTIONS
+// else {
+// logln((UnicodeString) "Ok: " + message + "; got " + expected);
+// }
+// #endif
+// return TRUE;
+// }
static char ASSERT_BUF[256];
void UnitsTest::testConversionCapability() {
struct TestCase {
- const StringPiece source;
- const StringPiece target;
+ const char *source;
+ const char *target;
const UnitsConvertibilityState expectedState;
} testCases[]{
{"meter", "foot", CONVERTIBLE}, //
ConversionRates conversionRates(status);
auto convertibility = checkConvertibility(source, target, conversionRates, status);
- assertEquals("Conversion Capability", testCase.expectedState, convertibility);
+ assertEquals(UnicodeString("Conversion Capability: ") + testCase.source + " to " +
+ testCase.target,
+ testCase.expectedState, convertibility);
}
}
IcuTestErrorCode status(*this, "Units testSiPrefixes");
// Test Cases
struct TestCase {
- StringPiece source;
- StringPiece target;
+ const char *source;
+ const char *target;
const double inputValue;
const double expectedValue;
} testCases[]{
ConversionRates conversionRates(status);
UnitConverter converter(source, target, conversionRates, status);
- assertEqualsNear("test conversion", testCase.expectedValue,
- converter.convert(testCase.inputValue), 0.001);
+ assertEquals(UnicodeString("testSiPrefixes: ") + testCase.source + " to " + testCase.target,
+ testCase.expectedValue, converter.convert(testCase.inputValue),
+ 0.0001 * testCase.expectedValue);
}
}
// Test Cases
struct TestCase {
- StringPiece source;
- StringPiece target;
+ const char *source;
+ const char *target;
const double inputValue;
const double expectedValue;
} testCases[]{
ConversionRates conversionRates(status);
UnitConverter converter(source, target, conversionRates, status);
- assertEqualsNear("test conversion", testCase.expectedValue,
- converter.convert(testCase.inputValue), 0.001);
+ assertEquals(UnicodeString("testMass: ") + testCase.source + " to " + testCase.target,
+ testCase.expectedValue, converter.convert(testCase.inputValue),
+ 0.0001 * testCase.expectedValue);
}
}
IcuTestErrorCode status(*this, "Units testTemperature");
// Test Cases
struct TestCase {
- StringPiece source;
- StringPiece target;
+ const char *source;
+ const char *target;
const double inputValue;
const double expectedValue;
} testCases[]{
ConversionRates conversionRates(status);
UnitConverter converter(source, target, conversionRates, status);
- assertEqualsNear("test conversion", testCase.expectedValue,
- converter.convert(testCase.inputValue), 0.001);
+ assertEquals(UnicodeString("testTemperature: ") + testCase.source + " to " + testCase.target,
+ testCase.expectedValue, converter.convert(testCase.inputValue),
+ 0.0001 * abs(testCase.expectedValue));
}
}
// Test Cases
struct TestCase {
- StringPiece source;
- StringPiece target;
+ const char *source;
+ const char *target;
const double inputValue;
const double expectedValue;
} testCases[]{
ConversionRates conversionRates(status);
UnitConverter converter(source, target, conversionRates, status);
- assertEqualsNear("test conversion", testCase.expectedValue,
- converter.convert(testCase.inputValue), 0.001);
+ assertEquals(UnicodeString("testArea: ") + testCase.source + " to " + testCase.target,
+ testCase.expectedValue, converter.convert(testCase.inputValue),
+ 0.0001 * testCase.expectedValue);
}
}
double got = converter.convert(1000);
msg.clear();
msg.append("Converting 1000 ", status).append(x, status).append(" to ", status).append(y, status);
- unitsTest->assertEqualsNear(msg.data(), expected, got, 0.0001);
+ unitsTest->assertEquals(msg.data(), expected, got, 0.0001 * expected);
}
/**