diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2022-04-07 21:36:40 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2022-04-07 21:36:40 +0300 |
commit | 9cd6b0fca87679e570fbdd4942e3068feb3439fa (patch) | |
tree | 557bf877d71854480f4171e9dd324cebb5606056 /filter_test.go |
initial
Diffstat (limited to 'filter_test.go')
-rw-r--r-- | filter_test.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/filter_test.go b/filter_test.go new file mode 100644 index 0000000..a19d361 --- /dev/null +++ b/filter_test.go @@ -0,0 +1,66 @@ +package collection + +import ( + "reflect" + "testing" +) + +func TestFilterSync(t *testing.T) { + type args struct { + collection []int + filter func(item int, idx int) bool + } + tests := []struct { + name string + args args + want []int + }{ + { + name: "odds", + args: args{ + collection: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + filter: func(item int, idx int) bool { + return item%2 == 0 + }, + }, + want: []int{2, 4, 6, 8, 10}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := FilterSync(tt.args.collection, tt.args.filter); !reflect.DeepEqual(got, tt.want) { + t.Errorf("Filter() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFilter(t *testing.T) { + type args struct { + collection []int + filter func(item int, idx int) bool + } + tests := []struct { + name string + args args + want int + }{ + { + name: "odds count", + args: args{ + collection: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + filter: func(item int, idx int) bool { + return item%2 == 0 + }, + }, + want: 5, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := Filter(tt.args.collection, tt.args.filter); len(got) != tt.want { + t.Errorf("FilterParallel() returned %v elements, want %v", len(got), tt.want) + } + }) + } +} |