-
Notifications
You must be signed in to change notification settings - Fork 92
/
rotate_k_steps_test.go
34 lines (29 loc) · 777 Bytes
/
rotate_k_steps_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
package array
import (
"slices"
"testing"
)
/*
TestRotateKSteps tests solution(s) with the following signature and problem description:
RotateKSteps(list []int, k int)
Given an list of integers and a number k, rotate the array k times.
*/
func TestRotateKSteps(t *testing.T) {
tests := []struct {
list []int
steps int
rotatedList []int
}{
{[]int{}, 0, []int{}},
{[]int{1, 2, 3}, 1, []int{3, 1, 2}},
{[]int{1, 2, 3}, 2, []int{2, 3, 1}},
{[]int{1, 2, 3}, 3, []int{1, 2, 3}},
{[]int{1, 2, 3, 4, 5}, 2, []int{4, 5, 1, 2, 3}},
}
for i, test := range tests {
RotateKSteps(test.list, test.steps)
if !slices.Equal(test.list, test.rotatedList) {
t.Fatalf("Failed test case #%d. Want %#v got %#v", i, test.rotatedList, test.list)
}
}
}