Fix edge-case in identify 'end' upper-bound
All checks were successful
ci/woodpecker/push/check Pipeline was successful

Just my luck, this was found immediately in the CI, right when I
uploaded the project thinking I was done.

Thankfully the fix is easy and (in hindsight) quite obvious.
This commit is contained in:
Bruno BELANYI 2024-08-24 20:59:14 +01:00
parent 3305b13936
commit 2004cd06cf
2 changed files with 7 additions and 1 deletions

View file

@ -35,7 +35,7 @@ public:
if (insert_begin) if (insert_begin)
it = underlying_.insert(it, {begin, val}); it = underlying_.insert(it, {begin, val});
// Get the proper upper-bound for `end` // Get the proper upper-bound for `end`
it = (it == underlying_.end()) ? it : std::next(it); it = (it == underlying_.end() || end < it->first) ? it : std::next(it);
if (!(at_upper_bound(it) == end_val)) if (!(at_upper_bound(it) == end_val))
underlying_.insert(it, {end, end_val}); underlying_.insert(it, {end, end_val});
} }

View file

@ -242,6 +242,12 @@ TEST_F(IntervalMapTest, fuzzing_003) {
assign(-110, -10, 4); assign(-110, -10, 4);
} }
TEST_F(IntervalMapTest, fuzzing_004) {
assign(-20, 120, 1);
assign(50, 110, 0);
assign(-120, 100, 0);
}
TEST_F(IntervalMapTest, randomized_test) { TEST_F(IntervalMapTest, randomized_test) {
auto const seed = []() { auto const seed = []() {
std::random_device r; std::random_device r;