-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_test.go
66 lines (63 loc) · 1.4 KB
/
node_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package bstree
import (
"testing"
)
func TestNode_Size(t *testing.T) {
tests := []struct {
name string
fields Node[string, int]
want int
}{
{
name: "returns the size of the node with zero children",
fields: Node[string, int]{size: 0},
want: 0,
},
{
name: "returns the size of the node with one children",
fields: Node[string, int]{size: 1, left: &Node[string, int]{size: 0}},
want: 1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
node := &Node[string, int]{
size: tt.fields.size,
key: tt.fields.key,
value: tt.fields.value,
left: tt.fields.left,
right: tt.fields.right,
}
if got := node.Size(); got != tt.want {
t.Errorf("Node.Size() = %v, want %v", got, tt.want)
}
})
}
}
func TestNode_String(t *testing.T) {
tests := []struct {
name string
fields Node[string, int]
want string
}{
{
name: "returns the string representation of the node",
fields: Node[string, int]{size: 0},
want: "Key: Value: 0 (Left: <nil> Right: <nil>)",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
node := &Node[string, int]{
size: tt.fields.size,
key: tt.fields.key,
value: tt.fields.value,
left: tt.fields.left,
right: tt.fields.right,
}
if got := node.String(); got != tt.want {
t.Errorf("Node.String() = %v, want %v", got, tt.want)
}
})
}
}