-
Notifications
You must be signed in to change notification settings - Fork 1
/
edges_test.go
36 lines (29 loc) · 1001 Bytes
/
edges_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
package trie
import "testing"
func TestEdgeAdd(t *testing.T) {
var (
n *Node
o = &Node{key: Key("foods"), value: 1}
p = &Node{key: Key("foodz"), value: 2}
)
n = &Node{key: Key("foodie"), value: 3}
if res, modified := (edges{o, p}).add(new(Txn), 4, n, false); !modified {
t.Errorf("expected [%q, %q] to be modified when adding %q", o.key, p.key, n.key)
} else {
assertExactNode(t, n, res[0])
assertExactNode(t, o, res[1])
assertExactNode(t, p, res[2])
}
if _, modified := (edges{o, p}).add(new(Txn), 4, p, false); modified {
t.Errorf("expected [%q, %q] to NOT be modified when adding %q", o.key, p.key, p.key)
}
n = &Node{key: Key("foodz"), value: 4}
if res, modified := (edges{o, p}).add(new(Txn), 4, n, false); !modified {
t.Errorf("expected [%q, %q] to be modified when adding %q with new value", o.key, p.key, n.key)
} else if len(res) != 2 {
t.Errorf("expected length to stay 2")
} else {
assertExactNode(t, o, res[0])
assertExactNode(t, n, res[1])
}
}