forked from buptmiao/parallel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipeline_test.go
More file actions
36 lines (31 loc) · 800 Bytes
/
pipeline_test.go
File metadata and controls
36 lines (31 loc) · 800 Bytes
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
package parallel_test
import (
"fmt"
"github.com/buptmiao/parallel"
"testing"
)
// a function with a single return value
func testFunc2(x, y, z int) string {
return fmt.Sprintf("%d:%d:%d", x, y, z)
}
// a function with no return value, but receiver the result by res argument
func testFunc3(x, y int, res *int) {
*res = x + y
}
// a function with multiple return values
func testFunc4(x, y int) (int, int) {
return y, x
}
func TestNewPipeline(t *testing.T) {
pipe := parallel.NewPipeline()
var res string
pipe.Register(testFunc2, 1, 2, 3).SetReceivers(&res)
var expect2 int
pipe.Register(testFunc3, 1, 1, &expect2)
var x, y int
pipe.Register(testFunc4, 1, 2).SetReceivers(&x, &y)
pipe.Do()
if res != "1:2:3" || expect2 != 2 || x != 2 || y != 1 {
panic("unexpected result")
}
}