diff --git a/gomore/04_fan_in/fan_in_out_test.go b/gomore/04_fan_in/fan_in_out_test.go new file mode 100644 index 0000000..c687d06 --- /dev/null +++ b/gomore/04_fan_in/fan_in_out_test.go @@ -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) +}