diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2022-05-01 21:50:12 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2022-05-01 21:50:12 +0300 |
commit | 9fcf8e29214210612d545bed50d7f889800ac639 (patch) | |
tree | 3a99d2cd37fb8158d49abc1de6298758d205c9dd /channels/fanout_test.go |
Initial
Diffstat (limited to 'channels/fanout_test.go')
-rw-r--r-- | channels/fanout_test.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/channels/fanout_test.go b/channels/fanout_test.go new file mode 100644 index 0000000..f8b0380 --- /dev/null +++ b/channels/fanout_test.go @@ -0,0 +1,48 @@ +package channels + +import ( + "reflect" + "sort" + "testing" +) + +func TestFanOut(t *testing.T) { + type args struct { + in []int + workers int + } + tests := []struct { + name string + args args + }{ + { + name: "test fanout - fanin", + args: args{ + in: []int{1, 2, 3, 4, 5, 6, 7, 8, 9}, + workers: 2, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + in := make(chan int) + go func() { + for _, v := range tt.args.in { + in <- v + } + close(in) + }() + + ch := FanOut(in, tt.args.workers) + gotCh := FanIn(ch...) + got := []int{} + for v := range gotCh { + got = append(got, v) + } + sort.Ints(got) + if !reflect.DeepEqual(got, tt.args.in) { + t.Errorf("FanIn() = %v, want %v", got, tt.args.in) + } + }) + } +} |