diff options
Diffstat (limited to 'pkg/libs/rangemap/rangemap_test.go')
| -rw-r--r-- | pkg/libs/rangemap/rangemap_test.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/pkg/libs/rangemap/rangemap_test.go b/pkg/libs/rangemap/rangemap_test.go index deb6dc7..7ea7f52 100644 --- a/pkg/libs/rangemap/rangemap_test.go +++ b/pkg/libs/rangemap/rangemap_test.go @@ -112,3 +112,79 @@ func TestSpaceBetween(t *testing.T) { // Since our search can never fail, we pad the space with a sentinel value. assert.Equal(t, "[{0..2: a}, {3..3}, {4..6: x}, {7..8}, {9..9: b}, {10..-1}]", rm.String()) } + +func TestAppendRanges(t *testing.T) { + rm1 := rangemap.New[string]() + + rm1.Set(0, 2, "a") + rm1.Set(3, 5, "b") + + rm2 := rangemap.New[string]() + rm2.Set(0, 2, "c") + rm2.Set(3, 3, "d") + + assert.Equal(t, "[{0..2: a}, {3..5: b}, {6..-1}]", rm1.String()) + assert.Equal(t, "[{0..2: c}, {3..3: d}, {4..-1}]", rm2.String()) + + rm1.AppendRanges(rm2) + + assert.Equal(t, "[{0..2: a}, {3..5: b}, {6..8: c}, {9..9: d}, {10..-1}]", rm1.String()) +} + +func TestAppendRangesSpaceBetween(t *testing.T) { + rm1 := rangemap.New[string]() + + rm1.Set(1, 2, "a") + rm1.Set(4, 4, "b") + + rm2 := rangemap.New[string]() + + rm2.Set(2, 4, "c") + rm2.Set(6, 6, "d") + + rm1.AppendRanges(rm2) + + assert.Equal(t, "[{0..0}, {1..2: a}, {3..3}, {4..4: b}, {5..6}, {7..9: c}, {10..10}, {11..11: d}, {12..-1}]", rm1.String()) +} + +func TestFill(t *testing.T) { + rm := rangemap.New[string]() + + rm.Set(0, 1, "a") + rm.Set(3, 5, "b") + rm.Set(9, 10, "c") + + rm.Fill(2, 10, "x") + + assert.Equal(t, "[{0..1: a}, {2..2: x}, {3..5: b}, {6..8: x}, {9..10: c}, {11..-1}]", rm.String()) +} + +func TestFillFromMiddle(t *testing.T) { + rm := rangemap.New[string]() + + rm.Set(0, 2, "a") + rm.Set(9, 10, "c") + + rm.Fill(5, 6, "x") + + assert.Equal(t, "[{0..2: a}, {3..4}, {5..6: x}, {7..8}, {9..10: c}, {11..-1}]", rm.String()) +} + +func TestFillEdge(t *testing.T) { + rm := rangemap.New[string]() + + rm.Set(0, 2, "a") + rm.Set(9, 10, "c") + + rm.Fill(2, 6, "x") + + assert.Equal(t, "[{0..2: a}, {3..6: x}, {7..8}, {9..10: c}, {11..-1}]", rm.String()) +} + +func TestFillFromEmpty(t *testing.T) { + rm := rangemap.New[string]() + rm.Fill(2, 4, "x") + rm.Fill(8, 10, "x") + + assert.Equal(t, "[{0..1}, {2..4: x}, {5..7}, {8..10: x}, {11..-1}]", rm.String()) +} |
