Commit 2badfdea authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f1473c1c
...@@ -32,13 +32,13 @@ func TestRangedMap(t *testing.T) { ...@@ -32,13 +32,13 @@ func TestRangedMap(t *testing.T) {
type testEntry struct { type testEntry struct {
A *RangedMap A *RangedMap
B KeyRange B RangedMapEntry
Set *RangedMap // A.SetRange(B, x) Set *RangedMap // A.SetRange(B.keycov, B.value)
Del *RangedMap // A.DelRange(B) Del *RangedMap // A.DelRange(B)
Has bool // A.HasRange(B) Has bool // A.HasRange(B)
// XXX Get? // XXX Get?
} }
E := func(A *RangedMap, B KeyRange, S, D *RangedMap, H bool) testEntry { E := func(A *RangedMap, B RangedMapEntry, S, D *RangedMap, H bool) testEntry {
return testEntry{A, B, S, D, H} return testEntry{A, B, S, D, H}
} }
...@@ -72,13 +72,13 @@ func TestRangedMap(t *testing.T) { ...@@ -72,13 +72,13 @@ func TestRangedMap(t *testing.T) {
return M return M
} }
// K creates [lo,hi) KeyRange // K creates RangedMapEntry{v, [lo,hi)}
K := func(lo,hi Key) KeyRange { K := func(lo,hi Key, v string) RangedMapEntry {
hi_ := hi hi_ := hi
if hi_ != noo { if hi_ != noo {
hi_-- hi_--
} }
return KeyRange{lo, hi_} return RangedMapEntry{v, KeyRange{lo, hi_}}
} }
// y, n alias true/false // y, n alias true/false
...@@ -88,41 +88,65 @@ func TestRangedMap(t *testing.T) { ...@@ -88,41 +88,65 @@ func TestRangedMap(t *testing.T) {
const a, b, c, d, x = "a", "b", "c", "d", "x" const a, b, c, d, x = "a", "b", "c", "d", "x"
// XXX SetRange:
// - coalesce (value same)
// - shrink left/right (value !same) + new entry
testv := []testEntry{ testv := []testEntry{
E( E(
M(1,2,a, 2,3,b), // A M(1,2,a, 2,3,b), // A
K(1,3), // B K(1,3,x), // B
M(1,3,x), // Set M(1,3,x), // Set
M(), // Del M(), // Del
y), // Has y), // Has
// coalesce (same value, no overlap)
E(
M(1,2,a, 4,5,a), // A
K(2,4,a), // B
M(1,5,a), // Set
M(1,2,a, 4,5,a), // Del
n), // Has
// coalesce (same value, overlap)
E(
M(1,4,a, 5,8,a), // A
K(2,6,a), // B
M(1,8,a), // Set
M(1,2,a, 6,8,a), // Del
n), // Has
// - shrink left/right (value !same) + new entry
E(
M(1,4,a, 5,8,b), // A
K(2,6,x), // B
M(1,2,a, 2,6,x, 6,8,b), // Set
M(1,2,a, 6,8,b), // Del
n), // Has
} }
for _, tt := range testv { for _, tt := range testv {
A := tt.A A := tt.A
B := tt.B B := tt.B
r := B.KeyRange
v := B.Value
has := A.HasRange(B) has := A.HasRange(r)
Aset := A.Clone() Aset := A.Clone()
Adel := A.Clone() Adel := A.Clone()
Aset.SetRange(B, x) Aset.SetRange(r, v)
Adel.DelRange(B) Adel.DelRange(r)
if !(has == tt.Has) { if !(has == tt.Has) {
t.Errorf("HasRange:\n A: %s\n B: %s\n ->·: %t\n ok·: %t\n", A, B, has, tt.Has) t.Errorf("HasRange:\n A: %s\n r: %s\n ->·: %t\n ok·: %t\n", A, r, has, tt.Has)
} }
if !Aset.Equal(tt.Set) { if !Aset.Equal(tt.Set) {
t.Errorf("SetRange:\n A: %s\n B: %s\n ->·: %s\n ok·: %s\n", A, RangedMapEntry{x,B}, Aset, tt.Set) t.Errorf("SetRange:\n A: %s\n e: %s\n ->·: %s\n ok·: %s\n", A, B, Aset, tt.Set)
} }
if !Adel.Equal(tt.Del) { if !Adel.Equal(tt.Del) {
t.Errorf("DelRange:\n A: %s\n B: %s\n ->·: %s\n ok·: %s\n", A, B, Adel, tt.Del) t.Errorf("DelRange:\n A: %s\n r: %s\n ->·: %s\n ok·: %s\n", A, r, Adel, tt.Del)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment