forked from seiflotfy/sllb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reg_test.go
48 lines (43 loc) · 1.1 KB
/
reg_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
package sllb
import (
"testing"
)
type testStruct struct {
name string
tr tR
exptr []tR
}
var testData = []*testStruct{
&testStruct{name: "A", tr: tR{T: 0, R: 5}, exptr: []tR{tR{T: 0, R: 5}}},
&testStruct{name: "B", tr: tR{T: 1, R: 3}, exptr: []tR{tR{T: 0, R: 5}, tR{T: 1, R: 3}}},
&testStruct{name: "C", tr: tR{T: 2, R: 4}, exptr: []tR{tR{T: 0, R: 5}, tR{T: 2, R: 4}}},
&testStruct{name: "D", tr: tR{T: 3, R: 2}, exptr: []tR{tR{T: 0, R: 5}, tR{T: 2, R: 4}, tR{T: 3, R: 2}}},
&testStruct{name: "E", tr: tR{T: 4, R: 1}, exptr: []tR{tR{T: 0, R: 5}, tR{T: 2, R: 4}, tR{T: 3, R: 2}, tR{T: 4, R: 1}}},
&testStruct{name: "F", tr: tR{T: 5, R: 6}, exptr: []tR{tR{T: 5, R: 6}}},
}
func testEq(a, b []tR) bool {
if a == nil && b == nil {
return true
}
if a == nil || b == nil {
return false
}
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
func TestRegInsert(t *testing.T) {
r := newReg()
for _, td := range testData {
r.insert(td.tr)
if !testEq(r.lfpm, td.exptr) {
t.Errorf("expected %v, got %v", td.exptr, r.lfpm)
}
}
}