mirror of
https://github.com/crazybber/go-pattern-examples.git
synced 2024-11-28 14:46:01 +03:00
35 lines
633 B
Go
35 lines
633 B
Go
package fanin
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestFanInNumbersSeq(t *testing.T) {
|
|
|
|
//第一路输入源
|
|
dataStreams1 := []int{13, 44, 56, 99, 9, 45, 67, 90, 78, 23}
|
|
// generate the common channel with inputs
|
|
inputChan1 := generateNumbersPipeline(dataStreams1)
|
|
|
|
//第二路输入源
|
|
dataStreams2 := []int{2, 4, 6, 9, 1, 1, 2, 3, 7, 8}
|
|
|
|
inputChan2 := generateNumbersPipeline(dataStreams2)
|
|
|
|
c1 := squareNumber(inputChan1)
|
|
|
|
c2 := squareNumber(inputChan2)
|
|
|
|
//fanIn data for the squared numbers
|
|
out := Merge(c1, c2)
|
|
|
|
sum := 0
|
|
|
|
for c := range out {
|
|
sum += c
|
|
}
|
|
|
|
fmt.Printf("Total Sum of Squares by FanIn : %d\n", sum)
|
|
}
|