-
Notifications
You must be signed in to change notification settings - Fork 1
/
graph_node_test.go
80 lines (59 loc) · 1.91 KB
/
graph_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
package gstream
import (
"context"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
type mockSupplier[V, VR any] struct{}
var _ ProcessorSupplier[any, any] = &mockSupplier[any, any]{}
func (*mockSupplier[V, VR]) Processor(_ ...Processor[VR]) Processor[V] {
return func(ctx context.Context, v V) {}
}
func newMockNode[V, VR any]() *graphNode[V, VR] {
return newProcessorNode[V, VR](&mockSupplier[V, VR]{})
}
func assertEqualPointer(t *testing.T, expected, actual any) {
assert.Equal(t, reflect.ValueOf(expected).Pointer(), reflect.ValueOf(actual).Pointer())
}
func TestAddChildStraight(t *testing.T) {
first := newMockNode[int, string]()
second := newMockNode[string, int]()
third := newMockNode[int, float64]()
addChild(first, second)
addChild(second, third)
ffs := first.forwards()
assert.Equal(t, 1, len(ffs))
assertEqualPointer(t, second.processor, ffs[0])
sfs := second.forwards()
assert.Equal(t, 1, len(sfs))
assertEqualPointer(t, third.processor, sfs[0])
assert.Equal(t, 0, len(third.forwards()))
}
func TestAddChildSplit(t *testing.T) {
first := newMockNode[int, string]()
second := newMockNode[string, int]()
third := newMockNode[string, float64]()
addChild(first, second)
addChild(first, third)
ffs := first.forwards()
assert.Equal(t, 2, len(ffs))
assertEqualPointer(t, second.processor, ffs[0])
assertEqualPointer(t, third.processor, ffs[1])
assert.Equal(t, 0, len(second.forwards()))
assert.Equal(t, 0, len(third.forwards()))
}
func TestAddChildMerge(t *testing.T) {
first := newMockNode[int, string]()
second := newMockNode[int, string]()
third := newMockNode[string, float64]()
addChild(first, third)
addChild(second, third)
ffs := first.forwards()
assert.Equal(t, 1, len(ffs))
assertEqualPointer(t, third.processor, ffs[0])
sfs := second.forwards()
assert.Equal(t, 1, len(sfs))
assertEqualPointer(t, third.processor, sfs[0])
assert.Equal(t, 0, len(third.forwards()))
}