-
Notifications
You must be signed in to change notification settings - Fork 1
/
expert_node_test.go
119 lines (87 loc) · 2.51 KB
/
expert_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package incr
import (
"testing"
"github.com/wcharczuk/go-incr/testutil"
)
func Test_ExpertNode_setters(t *testing.T) {
g := New()
n := newMockBareNode(g)
en := ExpertNode(n)
id := NewIdentifier()
en.SetID(id)
testutil.Equal(t, id, n.Node().ID())
en.SetHeight(7)
testutil.Equal(t, 7, en.Height())
en.SetChangedAt(8)
testutil.Equal(t, 8, en.ChangedAt())
en.SetSetAt(9)
testutil.Equal(t, 9, en.SetAt())
en.SetRecomputedAt(10)
testutil.Equal(t, 10, en.RecomputedAt())
en.SetAlways(true)
testutil.Equal(t, true, en.Always())
}
func Test_ExpertNode_AddChildren(t *testing.T) {
g := New()
n := newMockBareNode(g)
en := ExpertNode(n)
en.AddChildren(newMockBareNode(g), newMockBareNode(g))
testutil.Equal(t, 2, len(en.Children()))
}
func Test_ExpertNode_AddParents(t *testing.T) {
g := New()
n := newMockBareNode(g)
en := ExpertNode(n)
en.AddParents(newMockBareNode(g), newMockBareNode(g))
testutil.Equal(t, 2, len(en.Parents()))
}
func Test_ExpertNode_RemoveChild(t *testing.T) {
g := New()
n := newMockBareNode(g)
en := ExpertNode(n)
mbn0 := newMockBareNode(g)
mbn1 := newMockBareNode(g)
en.AddChildren(mbn0, mbn1)
testutil.Equal(t, 2, len(en.Children()))
en.RemoveChild(mbn0.Node().ID())
testutil.Equal(t, 1, len(en.Children()))
}
func Test_ExpertNode_RemoveParent(t *testing.T) {
g := New()
n := newMockBareNode(g)
en := ExpertNode(n)
mbn0 := newMockBareNode(g)
mbn1 := newMockBareNode(g)
en.AddParents(mbn0, mbn1)
testutil.Equal(t, 2, len(en.Parents()))
en.RemoveParent(mbn0.Node().ID())
testutil.Equal(t, 1, len(en.Parents()))
}
func Test_ExpertNode_Value(t *testing.T) {
g := New()
n := Return(g, "hello")
en := ExpertNode(n)
value := en.Value()
testutil.Equal(t, "hello", value)
}
func Test_ExpertNode_ComputePseudoheight(t *testing.T) {
g := New()
r00 := Return(g, "r")
m10 := Map(g, r00, ident)
m20 := Map(g, m10, ident)
m30 := Map(g, m20, ident)
_ = MustObserve(g, m30)
testutil.Equal(t, m10.Node().height, ExpertNode(m10).ComputePseudoHeight())
testutil.Equal(t, m20.Node().height, ExpertNode(m20).ComputePseudoHeight())
testutil.Equal(t, m30.Node().height, ExpertNode(m30).ComputePseudoHeight())
}
func Test_ExpertNode_ComputePseudoheight_usesParentsFn(t *testing.T) {
g := New()
r00 := Return(g, "r")
m10 := Map(g, r00, ident)
m20 := Map(g, m10, ident)
m30 := Map(g, m20, ident)
testutil.Equal(t, 1, ExpertNode(m10).ComputePseudoHeight())
testutil.Equal(t, 2, ExpertNode(m20).ComputePseudoHeight())
testutil.Equal(t, 3, ExpertNode(m30).ComputePseudoHeight())
}