Make test failure more verbose

Outputting the state of the map and this history of operations makes
debugging easier.
This commit is contained in:
Bruno BELANYI 2024-08-24 19:19:27 +01:00
parent 4d59126f10
commit 749cb335e3

View file

@ -2,6 +2,7 @@
#include <interval-map/interval-map.hh>
#include <sstream>
#include <type_traits>
#include "model.hh"
@ -86,10 +87,28 @@ protected:
}
void check() const {
SCOPED_TRACE(stringify_map());
SCOPED_TRACE(stringify_operations());
check_ranges();
check_canonicity();
}
std::string stringify_map() const {
std::ostringstream out;
out << "map: ";
for (const auto& [key, val] : map.underlying_)
out << "[" << +key << ": " << +val << "]";
return out.str();
}
std::string stringify_operations() const {
std::ostringstream out;
out << "ops: ";
for (const auto& [start, end, val] : model.ranges_)
out << "[" << +start << ":" << +end << " => " << +val << "]";
return out.str();
}
// Compare against the fake 'Model' implementation
void check_ranges() const {
auto i = std::numeric_limits<key_type>::min();