forked from glycerine/offheap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
del_test.go
51 lines (42 loc) · 1.09 KB
/
del_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package offheap
import (
"testing"
cv "github.com/glycerine/goconvey/convey"
)
func TestDelete(t *testing.T) {
h := NewHashTable(2)
h.Clear()
cv.Convey("delete should eliminate an element, leaving the rest", t, func() {
N := 5
// fill up a table
cv.So(h.Population, cv.ShouldEqual, 0)
for i := 0; i < N; i++ {
a, ok := h.Insert(uint64(i))
cv.So(ok, cv.ShouldEqual, true)
cell := h.Lookup(uint64(i))
cv.So(cell, cv.ShouldNotEqual, nil)
cv.So(cell, cv.ShouldEqual, a)
for j := i + 1; j < N+10; j++ {
cell = h.Lookup(uint64(j))
cv.So(cell, cv.ShouldEqual, nil)
}
}
// now delete from it, checking all the way down for correctness
for i := -10; i < N; i++ {
h.DeleteKey(uint64(i))
if i >= 0 {
cell := h.Lookup(uint64(i))
cv.So(cell, cv.ShouldEqual, nil)
for j := i + 1; j < N; j++ {
cell = h.Lookup(uint64(j))
cv.So(cell, cv.ShouldNotEqual, nil)
cv.So(cell.UnHashedKey, cv.ShouldEqual, j)
}
} else {
cv.So(h.Population, cv.ShouldEqual, N)
}
}
cell := h.Lookup(uint64(N + 1))
cv.So(cell, cv.ShouldEqual, nil)
})
}