mirror of
https://github.com/crazybber/go-pattern-examples.git
synced 2024-11-25 13:16:02 +03:00
add a fan_in_out test in fan-in dir
This commit is contained in:
parent
4d6d56c338
commit
cc54e8d9ad
31
gomore/04_fan_in/fan_in_out_test.go
Normal file
31
gomore/04_fan_in/fan_in_out_test.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package fanin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFanInOutNumbersSeq(T *testing.T) {
|
||||||
|
|
||||||
|
//一路输入源
|
||||||
|
dataStreams := []int{13, 44, 56, 99, 9, 45, 67, 90, 78, 23}
|
||||||
|
// generate the common channel with inputs
|
||||||
|
inputChan1 := generateNumbersPipeline(dataStreams)
|
||||||
|
inputChan2 := generateNumbersPipeline(dataStreams)
|
||||||
|
|
||||||
|
//this is a fanout operation
|
||||||
|
// Fan-out to 2 Go-routine
|
||||||
|
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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user