diff options
author | Johannes Schickel | 2009-12-27 11:06:05 +0000 |
---|---|---|
committer | Johannes Schickel | 2009-12-27 11:06:05 +0000 |
commit | cbeb0011897c85d19d76602cfa8f9cc49ee7315a (patch) | |
tree | eae40e5499ec10506e2d55ee73824f4b280e44f9 | |
parent | 1cd917f67446be1438fabfdec43b87e6f6f797a7 (diff) | |
download | scummvm-rg350-cbeb0011897c85d19d76602cfa8f9cc49ee7315a.tar.gz scummvm-rg350-cbeb0011897c85d19d76602cfa8f9cc49ee7315a.tar.bz2 scummvm-rg350-cbeb0011897c85d19d76602cfa8f9cc49ee7315a.zip |
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
-rw-r--r-- | test/common/algorithm.h | 24 |
1 files 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<typename T, class StrictWeakOrdering> - 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<int>()); + TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Less<int>()), true); // already sorted Common::sort(array, array + ARRAYSIZE(array)); - checkSort(array, array + ARRAYSIZE(array), Common::Less<int>()); + TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Less<int>()), 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<int>()); + TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Less<int>()), true); Common::sort(array, array + ARRAYSIZE(array), Common::Greater<int>()); - checkSort(array, array + ARRAYSIZE(array), Common::Greater<int>()); + TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Greater<int>()), true); } } @@ -56,11 +62,11 @@ public: list.push_back(Item(i * 0xDEADBEEF % 1337)); Common::sort(list.begin(), list.end(), Common::Less<Item>()); - checkSort(list.begin(), list.end(), Common::Less<Item>()); + TS_ASSERT_EQUALS(checkSort(list.begin(), list.end(), Common::Less<Item>()), true); // already sorted Common::sort(list.begin(), list.end(), Common::Less<Item>()); - checkSort(list.begin(), list.end(), Common::Less<Item>()); + TS_ASSERT_EQUALS(checkSort(list.begin(), list.end(), Common::Less<Item>()), true); } }; |