-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsystem_group_test.go
147 lines (126 loc) · 3.7 KB
/
system_group_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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package ecs
import (
"testing"
)
type __systemGroup_Test_C_1 struct {
Component[__systemGroup_Test_C_1]
}
type __systemGroup_Test_C_2 struct {
Component[__systemGroup_Test_C_2]
}
type __systemGroup_Test_C_3 struct {
Component[__systemGroup_Test_C_3]
}
type __systemGroup_Test_C_4 struct {
Component[__systemGroup_Test_C_4]
}
type __systemGroup_Test_C_5 struct {
Component[__systemGroup_Test_C_5]
}
type __systemGroup_Test_C_6 struct {
Component[__systemGroup_Test_C_6]
}
type __systemGroup_Test_C_7 struct {
Component[__systemGroup_Test_C_7]
}
type __systemGroup_Test_C_8 struct {
Component[__systemGroup_Test_C_8]
}
type __systemGroup_Test_C_9 struct {
Component[__systemGroup_Test_C_9]
}
type __systemGroup_Test_C_10 struct {
Component[__systemGroup_Test_C_10]
}
type __systemGroup_Test_S_1 struct {
System[__systemGroup_Test_S_1]
Name int
}
func NewTestSystem(ID int, rqs ...IRequirement) *__systemGroup_Test_S_1 {
s := &__systemGroup_Test_S_1{Name: ID}
s.setRequirementsInternal(rqs...)
return s
}
func (p *__systemGroup_Test_S_1) Call(label int) interface{} {
switch label {
case 1:
println(p.Name)
}
return nil
}
func newSystemGroupTestSystem() []ISystem {
return []ISystem{
NewTestSystem(1, &__systemGroup_Test_C_1{}, &__systemGroup_Test_C_2{}),
NewTestSystem(2, &ReadOnly[__systemGroup_Test_C_1]{}, &__systemGroup_Test_C_3{}),
NewTestSystem(3, &__systemGroup_Test_C_2{}, &__systemGroup_Test_C_5{}),
NewTestSystem(4, &__systemGroup_Test_C_2{}, &__systemGroup_Test_C_3{}, &__systemGroup_Test_C_6{}),
NewTestSystem(5, &__systemGroup_Test_C_7{}),
NewTestSystem(6, &__systemGroup_Test_C_9{}, &__systemGroup_Test_C_10{}),
NewTestSystem(7, &__systemGroup_Test_C_6{}),
NewTestSystem(8, &__systemGroup_Test_C_1{}, &__systemGroup_Test_C_5{}),
NewTestSystem(9, &__systemGroup_Test_C_4{}, &__systemGroup_Test_C_6{}),
NewTestSystem(10, &__systemGroup_Test_C_7{}, &__systemGroup_Test_C_5{}),
NewTestSystem(11, &ReadOnly[__systemGroup_Test_C_1]{}),
}
}
func TestNewSystemGroupIterEmpty(t *testing.T) {
sg := NewSystemGroup()
sg.resort()
Log.Infof("========== system count %d, Batch count: %d, Max peer Batch: %d:", sg.systemCount(), sg.batchCount(), sg.maxSystemCountPeerBatch())
for ss := sg.Begin(); !sg.End(); ss = sg.Next() {
Log.Info("========== batch:")
for _, s := range ss {
Log.Infof("%s\n", ObjectToString(s))
}
}
}
func TestNewSystemGroupIter(t *testing.T) {
tests := newSystemGroupTestSystem()
sg := NewSystemGroup()
for _, test := range tests {
sg.insert(test)
}
sg.resort()
Log.Infof("========== system count %d, Batch count: %d, Max peer Batch: %d:", sg.systemCount(), sg.batchCount(), sg.maxSystemCountPeerBatch())
for ss := sg.Begin(); !sg.End(); ss = sg.Next() {
Log.Info("========== batch:")
for _, s := range ss {
Log.Infof("%s\n", ObjectToString(s))
}
}
}
func TestNewSystemGroupIterTemp(t *testing.T) {
tests := newSystemGroupTestSystem()
sg := NewSystemGroup()
for _, test := range tests {
sg.insert(test)
}
sg.resort()
Log.Infof("========== system count %d, Batch count: %d, Max peer Batch: %d:", sg.systemCount(), sg.batchCount(), sg.maxSystemCountPeerBatch())
for ss := sg.Begin(); !sg.End(); ss = sg.Next() {
Log.Info("========== batch:")
for _, s := range ss {
Log.Infof("%s\n", ObjectToString(s))
}
}
for ss := sg.Begin(); !sg.End(); ss = sg.Next() {
Log.Info("========== batch:")
for _, s := range ss {
Log.Infof("%s\n", ObjectToString(s))
}
}
}
func BenchmarkSystemGroupIter(b *testing.B) {
tests := newSystemGroupTestSystem()
sg := NewSystemGroup()
for _, test := range tests {
sg.insert(test)
}
sg.resort()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for ss := sg.Begin(); !sg.End(); ss = sg.Next() {
_ = ss
}
}
}