1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
}
|