[tor-commits] [tor/master] Fix an overzealous compiler warning in the tests
nickm at torproject.org
nickm at torproject.org
Fri Aug 14 12:48:33 UTC 2015
commit 05d52899cbdc7a16d4e9b93555a081d16b06d96b
Author: Nick Mathewson <nickm at torproject.org>
Date: Fri Aug 14 08:48:26 2015 -0400
Fix an overzealous compiler warning in the tests
---
src/test/test.h | 9 +++++++++
src/test/test_containers.c | 12 ++++++------
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/test/test.h b/src/test/test.h
index b0c0946..86699c3 100644
--- a/src/test/test.h
+++ b/src/test/test.h
@@ -40,6 +40,15 @@
tt_assert_test_type(a,b,#a" "#op" "#b,double,(val1_ op val2_),"%g", \
TT_EXIT_TEST_FUNCTION)
+/* Declare "double equal" in a sneaky way, so compiler won't complain about
+ * comparing floats with == or !=. Of course, only do this if you know what
+ * you're doing. */
+#define tt_double_eq(a,b) \
+ STMT_BEGIN \
+ tt_double_op((a), >=, (b)); \
+ tt_double_op((a), <=, (b)); \
+ STMT_END
+
#ifdef _MSC_VER
#define U64_PRINTF_TYPE uint64_t
#define I64_PRINTF_TYPE int64_t
diff --git a/src/test/test_containers.c b/src/test/test_containers.c
index eb98cc8..1ee240f 100644
--- a/src/test/test_containers.c
+++ b/src/test/test_containers.c
@@ -934,12 +934,12 @@ test_container_order_functions(void *arg)
#undef third_quartile
double dbls[] = { 1.0, 10.0, 100.0, 1e4, 1e5, 1e6 };
- tt_assert(1.0 == median_double(dbls, 1));
- tt_assert(1.0 == median_double(dbls, 2));
- tt_assert(10.0 == median_double(dbls, 3));
- tt_assert(10.0 == median_double(dbls, 4));
- tt_assert(100.0 == median_double(dbls, 5));
- tt_assert(100.0 == median_double(dbls, 6));
+ tt_double_eq(1.0, median_double(dbls, 1));
+ tt_double_eq(1.0, median_double(dbls, 2));
+ tt_double_eq(10.0, median_double(dbls, 3));
+ tt_double_eq(10.0, median_double(dbls, 4));
+ tt_double_eq(100.0, median_double(dbls, 5));
+ tt_double_eq(100.0, median_double(dbls, 6));
time_t times[] = { 5, 10, 20, 25, 15 };
More information about the tor-commits
mailing list