From 9cd6b0fca87679e570fbdd4942e3068feb3439fa Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Thu, 7 Apr 2022 21:36:40 +0300 Subject: initial --- filter_test.go | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 filter_test.go (limited to 'filter_test.go') 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) + } + }) + } +} -- cgit v1.2.3