diff --git a/src/include/interval-map/interval-map.hh b/src/include/interval-map/interval-map.hh index 8f806c3..4dc2335 100644 --- a/src/include/interval-map/interval-map.hh +++ b/src/include/interval-map/interval-map.hh @@ -2,6 +2,9 @@ #include +// Testing class forward declaration +class IntervalMapTest; + namespace amby { template class interval_map { @@ -21,6 +24,9 @@ public: return std::prev(it)->second; } + // Used in testing + friend class ::IntervalMapTest; + private: V init_; std::map underlying_{}; diff --git a/tests/unit/unit_test.cc b/tests/unit/unit_test.cc index 3cdf79e..d51db5a 100644 --- a/tests/unit/unit_test.cc +++ b/tests/unit/unit_test.cc @@ -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) {