-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLessTree_test.go
More file actions
75 lines (68 loc) · 1.59 KB
/
LessTree_test.go
File metadata and controls
75 lines (68 loc) · 1.59 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package omap
import (
"cmp"
"testing"
)
/*
func TestLessIndex(t *testing.T) {
Slice := []KvSet[int, int]{{1, 1}}
Expected := func(k, cidx, coffset int) {
idx, offset := LessIndex(k, cmp.Less, Slice)
t.Logf("Testing Lookup of: %d, idx: %d, offset: %d", k, cidx, coffset)
if idx != cidx || offset != coffset {
t.Fatalf("Expected index: %d, got: %d, expected offset: %d, got: %d", cidx, idx, coffset, offset)
}
}
Expected(0, 0, -1)
Expected(1, 0, 0)
Expected(2, 0, 1)
Slice = []KvSet[int, int]{{0, 0}, {1, 1}, {2, 2}}
Expected(1, 1, 0)
Expected(2, 2, 0)
Expected(0, 0, 0)
Expected(-1, 0, -1)
Expected(3, 2, 1)
Slice = []KvSet[int, int]{{0, 0}, {3, 3}, {5, 5}}
Expected(2, 0, 1)
Expected(4, 2, -1)
Slice = []KvSet[int, int]{{0, 0}, {3, 3}, {5, 5}, {7, 7}}
Expected(4, 2, -1)
Expected(6, 3, -1)
Expected(7, 3, 0)
}
*/
func TestUpgradedGetIndex(t *testing.T) {
Slice := []KvSet[int, int]{{0, 0}, {1, 1}, {2, 2}}
Expected := func(k, cidx, coffset int) {
idx, offset := GetIndex(k, cmp.Compare, Slice)
t.Logf("Checking key: %d", k)
if idx != cidx || offset != coffset {
t.Fatalf("Expected index: %d, got: %d, expected offset: %d, got: %d", cidx, idx, coffset, offset)
}
}
Expected(0, 0, 0)
Expected(1, 1, 0)
Expected(2, 2, 0)
Slice = []KvSet[int, int]{{0, 0}, {3, 3}, {5, 5}, {7, 7}}
Expected(2, 0, 1)
Expected(6, 3, -1)
Expected(7, 3, 0)
Slice = []KvSet[int, int]{
{0, 0},
{3, 3},
{5, 5},
{8, 7},
{9, 7},
{10, 7},
{11, 7},
{12, 7},
{13, 7},
{14, 7},
{15, 7},
{16, 7},
{17, 7},
{18, 7},
{19, 7},
}
Expected(20, 14, 1)
}