Explicitly test for canonicity

This will come in handy later, with more complex test cases.
This commit is contained in:
Bruno BELANYI 2024-08-23 23:16:39 +01:00
parent 6bc72fdc25
commit 73c2b21b94
2 changed files with 27 additions and 0 deletions

View file

@ -2,6 +2,9 @@
#include <map>
// Testing class forward declaration
class IntervalMapTest;
namespace amby {
template <typename K, typename V> class interval_map {
@ -21,6 +24,9 @@ public:
return std::prev(it)->second;
}
// Used in testing
friend class ::IntervalMapTest;
private:
V init_;
std::map<K, V> underlying_{};

View file

@ -69,6 +69,27 @@ protected:
void SetUp() override {
map = map_type{0};
}
void TearDown() override {
check_canonicity();
}
void check_canonicity() const {
// Consecutive map entries must not contain the same value
for (auto it = map.underlying_.begin(); it != map.underlying_.end();
++it) {
const auto next = std::next(it, 1);
if (next == map.underlying_.end())
break;
EXPECT_NE(it->second, next->second);
}
// The first entry must not contain the initial value
if (const auto it = map.underlying_.begin();
it != map.underlying_.end()) {
EXPECT_NE(it->second, map.init_);
}
}
};
TEST_F(IntervalMapTest, minimal_interface) {