-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixedprocess_test.go
88 lines (74 loc) · 1.57 KB
/
fixedprocess_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
package parallel
import (
"math"
"testing"
)
// MARK: Tests
func TestFixedProcessCompleteness_01(t *testing.T) {
v := make([]float64, 1000000)
p := NewFixedProcess(1)
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 TestFixedProcessCompleteness_02(t *testing.T) {
v := make([]float64, 1000000)
p := NewFixedProcess(2)
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 TestStopFixedProcess(t *testing.T) {
v := make([]float64, 1000000)
p := NewFixedProcess(2)
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
}
} else {
if value != 0.0 {
t.Errorf("Value, %f, should be equal to 0.0.", value)
break
}
}
}
}
// MARK: Benchmarks
func BenchmarkFixedProcess_01(b *testing.B) {
v := make([]float64, 1000000)
p := NewFixedProcess(1)
for n := 0; n < b.N; n++ {
p.Execute(len(v), func(i int) {
v[i] = math.Sqrt(float64(i))
})
}
}
func BenchmarkFixedProcess_02(b *testing.B) {
v := make([]float64, 1000000)
p := NewFixedProcess(2)
for n := 0; n < b.N; n++ {
p.Execute(len(v), func(i int) {
v[i] = math.Sqrt(float64(i))
})
}
}