From cbeb0011897c85d19d76602cfa8f9cc49ee7315a Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 27 Dec 2009 11:06:05 +0000 Subject: Do not use TS_ASSERT_EQUALS in checkSort, but rather let return checkSort an boolean, which indicates whether the sequence is sorted by the given predicate. This allows for easier checking which order related tests failed. svn-id: r46620 --- test/common/algorithm.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/test/common/algorithm.h b/test/common/algorithm.h index 8ce0290c7e..79845b835f 100644 --- a/test/common/algorithm.h +++ b/test/common/algorithm.h @@ -7,7 +7,10 @@ class AlgorithmTestSuite : public CxxTest::TestSuite { template - void checkSort(T first, T last, StrictWeakOrdering comp = StrictWeakOrdering()) { + bool checkSort(T first, T last, StrictWeakOrdering comp = StrictWeakOrdering()) { + if (first == last) + return true; + // Check whether the container is sorted by the given binary predicate, which // decides whether the first value passed preceeds the second value passed. // @@ -15,8 +18,11 @@ class AlgorithmTestSuite : public CxxTest::TestSuite { // given predicate in reverse order, when it returns false everything is // fine, when it returns false, the follower preceeds the item and thus // the order is violated. - for (T prev = first++; first != last; ++prev, ++first) - TS_ASSERT_EQUALS(comp(*first, *prev), false); + for (T prev = first++; first != last; ++prev, ++first) { + if (comp(*first, *prev)) + return false; + } + return true; } struct Item { @@ -32,19 +38,19 @@ public: { int array[] = { 63, 11, 31, 72, 1, 48, 32, 69, 38, 31 }; Common::sort(array, array + ARRAYSIZE(array)); - checkSort(array, array + ARRAYSIZE(array), Common::Less()); + TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Less()), true); // already sorted Common::sort(array, array + ARRAYSIZE(array)); - checkSort(array, array + ARRAYSIZE(array), Common::Less()); + TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Less()), true); } { int array[] = { 90, 80, 70, 60, 50, 40, 30, 20, 10 }; Common::sort(array, array + ARRAYSIZE(array)); - checkSort(array, array + ARRAYSIZE(array), Common::Less()); + TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Less()), true); Common::sort(array, array + ARRAYSIZE(array), Common::Greater()); - checkSort(array, array + ARRAYSIZE(array), Common::Greater()); + TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Greater()), true); } } @@ -56,11 +62,11 @@ public: list.push_back(Item(i * 0xDEADBEEF % 1337)); Common::sort(list.begin(), list.end(), Common::Less()); - checkSort(list.begin(), list.end(), Common::Less()); + TS_ASSERT_EQUALS(checkSort(list.begin(), list.end(), Common::Less()), true); // already sorted Common::sort(list.begin(), list.end(), Common::Less()); - checkSort(list.begin(), list.end(), Common::Less()); + TS_ASSERT_EQUALS(checkSort(list.begin(), list.end(), Common::Less()), true); } }; -- cgit v1.2.3