From cc54e8d9ad3eff05d2dddee3ac5098dadba16006 Mon Sep 17 00:00:00 2001 From: Edward Date: Thu, 7 May 2020 12:25:01 +0800 Subject: [PATCH] add a fan_in_out test in fan-in dir --- gomore/04_fan_in/fan_in_out_test.go | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 gomore/04_fan_in/fan_in_out_test.go 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) +}