diff --git a/tests/unit/unit_test.cc b/tests/unit/unit_test.cc index e488c79..288c811 100644 --- a/tests/unit/unit_test.cc +++ b/tests/unit/unit_test.cc @@ -2,6 +2,67 @@ #include -TEST(misc, passing) { - ASSERT_EQ(1, 1); +#include + +template class KeyInterface { +public: + explicit KeyInterface(T val) : underlying_(val) {} + + KeyInterface(KeyInterface const&) = default; + KeyInterface& operator=(KeyInterface const&) = default; + + bool operator<(KeyInterface const& other) const { + return underlying_ < other.underlying_; + } + +private: + T underlying_; +}; + +template struct std::numeric_limits> { + static KeyInterface lowest() { + return KeyInterface(std::numeric_limits::lowest()); + } +}; + +static_assert(std::is_copy_constructible_v>); +static_assert(std::is_copy_assignable_v>); +static_assert( + std::is_same_v, + decltype(std::numeric_limits>::lowest())>); + +template class ValueInterface { +public: + explicit ValueInterface(T val) : underlying_(val) {} + + ValueInterface(ValueInterface const&) = default; + ValueInterface& operator=(ValueInterface const&) = default; + + bool operator==(ValueInterface const& other) const { + return underlying_ == other.underlying_; + } + +private: + T underlying_; +}; + +template struct std::numeric_limits> { + static ValueInterface lowest() { + return ValueInterface(std::numeric_limits::lowest()); + } +}; + +static_assert(std::is_copy_constructible_v>); +static_assert(std::is_copy_assignable_v>); +static_assert(std::is_same_v< + ValueInterface, + decltype(std::numeric_limits>::lowest())>); + +TEST(interval_map, minimal_interface) { + using Key = KeyInterface; + using Value = ValueInterface; + + auto map = amby::interval_map{Value(0)}; + ASSERT_EQ(map[Key(0)], Value(0)); + map.assign(Key(0), Key(1), Value(1)); }