Commit ed2de0de authored by Kirill Smelkov's avatar Kirill Smelkov

X Tests for Get

parent 7ae1abd4
...@@ -36,7 +36,6 @@ func TestRangedMap(t *testing.T) { ...@@ -36,7 +36,6 @@ func TestRangedMap(t *testing.T) {
Set *RangedMap // A.SetRange(B.keycov, B.value) Set *RangedMap // A.SetRange(B.keycov, B.value)
Del *RangedMap // A.DelRange(B.keycov) Del *RangedMap // A.DelRange(B.keycov)
Has bool // A.HasRange(B.keycov) Has bool // A.HasRange(B.keycov)
// XXX Get?
} }
E := func(A *RangedMap, B RangedMapEntry, 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}
...@@ -142,16 +141,12 @@ func TestRangedMap(t *testing.T) { ...@@ -142,16 +141,12 @@ func TestRangedMap(t *testing.T) {
r := B.KeyRange r := B.KeyRange
v := B.Value v := B.Value
has := A.HasRange(r) assertMHasRange(t, A, r, tt.Has)
Aset := A.Clone() Aset := A.Clone()
Adel := A.Clone() Adel := A.Clone()
Aset.SetRange(r, v) Aset.SetRange(r, v)
Adel.DelRange(r) Adel.DelRange(r)
if !(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 e: %s\n ->·: %s\n ok·: %s\n", A, B, Aset, tt.Set) t.Errorf("SetRange:\n A: %s\n e: %s\n ->·: %s\n ok·: %s\n", A, B, Aset, tt.Set)
...@@ -162,6 +157,59 @@ func TestRangedMap(t *testing.T) { ...@@ -162,6 +157,59 @@ func TestRangedMap(t *testing.T) {
} }
assertMHasRange(t, Aset, r, true)
assertMHasRange(t, Adel, r, false)
verifyGet(t, A)
verifyGet(t, Aset)
verifyGet(t, Adel)
}
}
// assertMHasRange asserts that RangeMap M.HasRange(r) == hasOK.
func assertMHasRange(t *testing.T, M *_RangedMap_str, r KeyRange, hasOK bool) {
t.Helper()
has := M.HasRange(r)
if !(has == hasOK) {
t.Errorf("HasRange:\n M: %s\n r: %s\n ->·: %t\n ok·: %t\n", M, r, has, hasOK)
} }
}
// verifyGet verifies RangedMap.Get .
func verifyGet(t *testing.T, M *_RangedMap_str) {
type RangedMap = _RangedMap_str
type RangedMapEntry = _RangedMap_strEntry
t.Helper()
var Mranges []RangedMapEntry
Mranges = append(Mranges, M.AllRanges()...) // copy just in case it changes on Get
for _, e := range Mranges {
for k := e.Lo; k <= e.Hi_; k++ {
v, ok := M.Get_(k)
if !(v == e.Value && ok) {
t.Errorf("%s\tGet(%s):\nhave: %q, %t\nwant: %q, true",
M, KStr(k), v, ok, e.Value)
}
}
}
// verify no-data
// NA = [-∞,∞) \ M
na := RangedKeySet{}
na.AddRange(KeyRange{-10,+10}) // models -∞,∞
for _, e := range Mranges {
na.DelRange(e.KeyRange)
}
for _, r := range na.AllRanges() {
for k := r.Lo; k <= r.Hi_; k++ {
v, ok := M.Get_(k)
if !(v == "" && !ok) {
t.Errorf("%s\tGet(%s):\nhave: %q, %t\nwant: %q, false",
M, KStr(k), v, ok, "")
}
}
}
} }
...@@ -158,22 +158,22 @@ func TestRangedKeySet(t *testing.T) { ...@@ -158,22 +158,22 @@ func TestRangedKeySet(t *testing.T) {
} }
// HasRange // HasRange
assertHasRange(t, A.AllRanges(), A, true) assertSHasRange(t, A.AllRanges(), A, true)
assertHasRange(t, B.AllRanges(), B, true) assertSHasRange(t, B.AllRanges(), B, true)
assertHasRange(t, A.AllRanges(), U, true) assertSHasRange(t, A.AllRanges(), U, true)
assertHasRange(t, B.AllRanges(), U, true) assertSHasRange(t, B.AllRanges(), U, true)
Dab := D Dab := D
Dba := B.Difference(A) Dba := B.Difference(A)
assertHasRange(t, Dab.AllRanges(), A, true) assertSHasRange(t, Dab.AllRanges(), A, true)
assertHasRange(t, Dab.AllRanges(), B, false) assertSHasRange(t, Dab.AllRanges(), B, false)
assertHasRange(t, Dba.AllRanges(), B, true) assertSHasRange(t, Dba.AllRanges(), B, true)
assertHasRange(t, Dba.AllRanges(), A, false) assertSHasRange(t, Dba.AllRanges(), A, false)
} }
} }
// assertHasRange asserts for all ranges from rangev that S.HasRange(r) == hasOK // assertSHasRange asserts for all ranges from rangev that RangedSet S.HasRange(r) == hasOK.
func assertHasRange(t *testing.T, rangev []KeyRange, S *RangedKeySet, hasOK bool) { func assertSHasRange(t *testing.T, rangev []KeyRange, S *RangedKeySet, hasOK bool) {
t.Helper() t.Helper()
for _, r := range rangev { for _, r := range rangev {
has := S.HasRange(r) has := S.HasRange(r)
......
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