]> granicus.if.org Git - icu/commitdiff
ICU-11689 add assertEquals(double..)
authorSteven R. Loomis <srl@icu-project.org>
Thu, 30 Jul 2015 22:45:39 +0000 (22:45 +0000)
committerSteven R. Loomis <srl@icu-project.org>
Thu, 30 Jul 2015 22:45:39 +0000 (22:45 +0000)
X-SVN-Rev: 37705

icu4c/source/test/intltest/intltest.cpp
icu4c/source/test/intltest/intltest.h
icu4c/source/test/intltest/numrgts.cpp

index b40d37feed2dd078de904241ed0119db4e767502..f23f827ea6e60d0a55686460327d364ab01c7c69 100644 (file)
@@ -1931,6 +1931,24 @@ UBool IntlTest::assertEquals(const char* message,
     return TRUE;
 }
 
+UBool IntlTest::assertEquals(const char* message,
+                             double expected,
+                             double actual) {
+    if (expected != actual) {
+        errln((UnicodeString)"FAIL: " + message + "; got " +
+              actual + 
+              "; expected " + expected);
+        return FALSE;
+    }
+#ifdef VERBOSE_ASSERTIONS
+    else {
+        logln((UnicodeString)"Ok: " + message + "; got " + actual);
+    }
+#endif
+    return TRUE;
+}
+
+
 UBool IntlTest::assertEquals(const char* message,
                              UBool expected,
                              UBool actual) {
index 667685ec3096fff00875985f6921aaa663b14d02..58877cf94d15c923e54049224423c18cd766ea05 100644 (file)
@@ -275,6 +275,7 @@ protected:
                        UBool actual);
     UBool assertEquals(const char* message, int32_t expected, int32_t actual);
     UBool assertEquals(const char* message, int64_t expected, int64_t actual);
+    UBool assertEquals(const char* message, double expected, double actual);
 #if !UCONFIG_NO_FORMATTING
     UBool assertEquals(const char* message, const Formattable& expected,
                        const Formattable& actual, UBool possibleDataError=FALSE);
index 772bbe8bbf3b8f2032f48efa7afbf52494aa5ff5..821a94f341842b56fa4c56004e9a28d420099792 100644 (file)
@@ -1,5 +1,5 @@
 /***********************************************************************
- * Copyright (c) 1997-2014, International Business Machines Corporation
+ * Copyright (c) 1997-2015, International Business Machines Corporation
  * and others. All Rights Reserved.
  ***********************************************************************/
  
@@ -2710,6 +2710,12 @@ void NumberFormatRegressionTest::TestJ691(void) {
     if ((expr)==FALSE) {\
         errln("File %s, line %d: Assertion Failed: " #expr "\n", __FILE__, __LINE__);\
     }
+#define TEST_ASSERT_EQUALS(x,y)                  \
+    {                                                                     \
+      char _msg[100]; \
+      sprintf (_msg,"File %s, line %d: Assertion Failed: " #x "==" #y "\n", __FILE__, __LINE__); \
+      assertEquals((const char*)_msg, x,y);                             \
+    }
 
 
 // Ticket 8199:  Parse failure for numbers in the range of 1E10 - 1E18
@@ -2827,8 +2833,8 @@ void NumberFormatRegressionTest::Test8199(void) {
     nf->parse(numStr, val, status); //    the ones digit, putting it up to ...994
     TEST_CHECK_STATUS(status);
     TEST_ASSERT(Formattable::kDouble == val.getType());
-    TEST_ASSERT(9007199254740993LL == val.getInt64(status));
-    TEST_ASSERT(9007199254740994.0 == val.getDouble(status));
+    TEST_ASSERT_EQUALS((int64_t)9007199254740993LL,val.getInt64(status));
+    TEST_ASSERT_EQUALS((double)9007199254740994.0,(double)val.getDouble(status));
     TEST_CHECK_STATUS(status);
 
     delete nf;