-
Notifications
You must be signed in to change notification settings - Fork 0
/
variableprocess_test.go
61 lines (51 loc) · 1.25 KB
/
variableprocess_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
package parallel
import (
"math"
"testing"
"time"
)
// MARK: Tests
func TestVariableProcessCompleteness(t *testing.T) {
v := make([]float64, 10000000)
c := NewControllerConfiguration(2.0, 0.0, 1.0, 0.1, 1.0)
p := NewVariableProcess(100*time.Millisecond, 1, 20, c, false)
p.Execute(len(v), func(i int) {
v[i] = float64(i + 1)
})
for i, value := range v {
if float64(i+1) != value {
t.Errorf("Value, %f, should be equal to %f.", value, float64(i+1))
break
}
}
}
func TestStopVariableProcess(t *testing.T) {
v := make([]float64, 1000000)
c := NewControllerConfiguration(2.0, 0.0, 1.0, 0.1, 1.0)
p := NewVariableProcess(100*time.Millisecond, 1, 20, c, false)
p.Execute(len(v), func(i int) {
if i == len(v)/2 {
p.Stop()
}
v[i] = float64(i + 1)
})
for i, value := range v {
if i <= len(v)/2 {
if float64(i+1) != value {
t.Errorf("Value, %f, should be equal to %f.", value, float64(i+1))
break
}
}
}
}
// MARK: Benchmarks
func BenchmarkVariableProcess(b *testing.B) {
v := make([]float64, 1000000)
c := NewControllerConfiguration(2.0, 0.0, 1.0, 1.0, 1.0)
p := NewVariableProcess(100*time.Millisecond, 1, 20, c, false)
for n := 0; n < b.N; n++ {
p.Execute(len(v), func(i int) {
v[i] = math.Sqrt(float64(i))
})
}
}