diff options
author | Daniel Burrows <dburrows@debian.org> | 2010-05-09 20:25:48 -0700 |
---|---|---|
committer | Daniel Burrows <dburrows@debian.org> | 2010-05-09 20:25:48 -0700 |
commit | c94f4f0d6d526766a1f918c81b3eb10787d764fb (patch) | |
tree | 3c68c4c585ef24a4787c5b8b0bd4f6b430bfa492 | |
parent | 0beff671170b203879331c0f0fca97b8f21a1dbc (diff) | |
download | aptitude-c94f4f0d6d526766a1f918c81b3eb10787d764fb.tar.gz |
Overhaul the shared test code to support comparisons between signal values and to support checking arbitrary collections as sets.
-rw-r--r-- | tests/test_dynamic_set.cc | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/tests/test_dynamic_set.cc b/tests/test_dynamic_set.cc index 6ad3c9b5..72ac4272 100644 --- a/tests/test_dynamic_set.cc +++ b/tests/test_dynamic_set.cc @@ -65,6 +65,11 @@ namespace { return !(*this == other); } + + bool operator<(const inserted_call &other) const + { + return value < other.value; + } }; template<typename T> @@ -96,6 +101,11 @@ namespace { return !(*this == other); } + + bool operator<(const removed_call &other) const + { + return value < other.value; + } }; template<typename T> @@ -145,6 +155,11 @@ namespace { return !(*this == other); } + + bool operator<(const set_signal &other) const + { + return value < other.value; + } }; template<typename T> @@ -271,19 +286,22 @@ namespace // // For a general library this wouldn't be enough, but I only need to // cover a few cases. -std::vector<int> to_vector(const std::vector<int> &v) +template<typename T> +std::vector<T> to_vector(const std::vector<T> &v) { return v; } -std::vector<int> to_vector(const unordered_set<int> &s) +template<typename T> +std::vector<T> to_vector(const unordered_set<T> &s) { - return std::vector<int>(s.begin(), s.end()); + return std::vector<T>(s.begin(), s.end()); } -std::vector<int> to_vector(dynamic_set<int> &s) +template<typename T> +std::vector<T> to_vector(dynamic_set<T> &s) { - std::vector<int> rval; + std::vector<T> rval; rval.reserve(s.size()); for(shared_ptr<enumerator<int> > e = s.enumerate(); @@ -295,18 +313,25 @@ std::vector<int> to_vector(dynamic_set<int> &s) return rval; } -std::vector<int> to_vector(const shared_ptr<dynamic_set<int> > &s) +template<typename T> +std::vector<T> to_vector(const shared_ptr<dynamic_set<T> > &s) { return to_vector(*s); } +template<typename T> +std::vector<set_signal<T> > to_vector(const dynamic_set_signals<T> &s) +{ + return std::vector<set_signal<T> >(s.begin(), s.end()); +} + -#define CHECK_EQUAL_SETS(c1, c2) \ +#define CHECK_EQUAL_SETS(c1, c2, T) \ do \ { \ - std::vector<int> __c1 = to_vector(c1); \ - std::vector<int> __c2 = to_vector(c2); \ + std::vector<T> __c1 = to_vector(c1); \ + std::vector<T> __c2 = to_vector(c2); \ \ std::sort(__c1.begin(), __c1.end()); \ std::sort(__c2.begin(), __c2.end()); \ @@ -321,7 +346,7 @@ std::vector<int> to_vector(const shared_ptr<dynamic_set<int> > &s) do \ { \ BOOST_CHECK_EQUAL(expected.size(), values.size()); \ - CHECK_EQUAL_SETS(expected, values); \ + CHECK_EQUAL_SETS(expected, values, int); \ BOOST_CHECK_EQUAL_COLLECTIONS(expected_signals.begin(), \ expected_signals.end(), \ signals.begin(), \ |