-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
68 lines (65 loc) · 1.38 KB
/
main_test.go
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
package main
import (
"reflect"
"testing"
)
func Test_rotate(t *testing.T) {
type args struct {
nums []int
k int
}
tests := []struct {
name string
args args
wantNums []int
}{
{
name: "example 1",
args: args{nums: []int{1, 2, 3, 4, 5, 6, 7}, k: 3},
wantNums: []int{5, 6, 7, 1, 2, 3, 4},
},
{
name: "example 2",
args: args{nums: []int{-1, -100, 3, 99}, k: 2},
wantNums: []int{3, 99, -1, -100},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rotate(tt.args.nums, tt.args.k)
if !reflect.DeepEqual(tt.wantNums, tt.args.nums) {
t.Fatalf("Expected nums after rotate %v, but got %v\n", tt.wantNums, tt.args.nums)
}
})
}
}
func Test_rotateV2(t *testing.T) {
type args struct {
nums []int
k int
}
tests := []struct {
name string
args args
wantNums []int
}{
{
name: "example 1",
args: args{nums: []int{1, 2, 3, 4, 5, 6, 7}, k: 3},
wantNums: []int{5, 6, 7, 1, 2, 3, 4},
},
{
name: "example 2",
args: args{nums: []int{-1, -100, 3, 99}, k: 2},
wantNums: []int{3, 99, -1, -100},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rotateV2(tt.args.nums, tt.args.k)
if !reflect.DeepEqual(tt.wantNums, tt.args.nums) {
t.Fatalf("Expected nums after rotateV2 %v, but got %v\n", tt.wantNums, tt.args.nums)
}
})
}
}