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 /collections/merge_test.go |
Initial
Diffstat (limited to 'collections/merge_test.go')
-rw-r--r-- | collections/merge_test.go | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/collections/merge_test.go b/collections/merge_test.go new file mode 100644 index 0000000..27f5ba0 --- /dev/null +++ b/collections/merge_test.go @@ -0,0 +1,92 @@ +package collections + +import ( + "reflect" + "testing" +) + +func TestMergeScalar(t *testing.T) { + type args struct { + s1 []int + s2 []int + } + tests := []struct { + name string + args args + want []int + }{ + { + name: "test 1", + args: args{ + s1: []int{1, 2, 4, 5, 6}, + s2: []int{3, 3}, + }, + want: []int{1, 2, 3, 3, 4, 5, 6}, + }, + { + name: "test 2", + args: args{ + s1: []int{1, 3, 5, 7}, + s2: []int{0, 2, 4, 6, 8}, + }, + want: []int{0, 1, 2, 3, 4, 5, 6, 7, 8}, + }, + { + name: "test 3", + args: args{ + s1: []int{8, 6, 4, 2, 0}, + s2: []int{1, 3, 5, 7}, + }, + want: []int{1, 3, 5, 7, 8, 6, 4, 2, 0}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := MergeScalar(tt.args.s1, tt.args.s2); !reflect.DeepEqual(got, tt.want) { + t.Errorf("MergeScalar() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMerge(t *testing.T) { + type args struct { + s1 []*myType + s2 []*myType + } + tests := []struct { + name string + args args + want []*myType + }{ + { + name: "test1", + args: args{ + s1: []*myType{ + {400}, {200}, {100}, + }, + s2: []*myType{ + {300}, + }, + }, + want: []*myType{ + {400}, {300}, {200}, {100}, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := Merge(tt.args.s1, tt.args.s2); !reflect.DeepEqual(got, tt.want) { + t.Errorf("Merge() = %v, want %v", got, tt.want) + } + }) + } +} + +type myType struct { + Weight int +} + +func (t *myType) Less(t2 *myType) bool { + return t2.Weight < t.Weight +} |