Files
codekata-golang/20201209/main_test.go
2020-12-09 10:39:13 +08:00

87 lines
1.3 KiB
Go

package main
import (
"reflect"
"testing"
)
func Test_transform(t *testing.T) {
type args struct {
src [][]int
}
tests := []struct {
name string
args args
want [][]int
}{
{
"test1",
args{[][]int{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}},
[][]int{
{7, 4, 1},
{8, 5, 2},
{9, 6, 3},
},
},
{
"test2",
args{[][]int{
{5, 1, 9, 11},
{2, 4, 8, 10},
{13, 3, 6, 7},
{15, 14, 12, 16},
}},
[][]int{
{15, 13, 2, 5},
{14, 3, 4, 1},
{12, 6, 8, 9},
{16, 7, 10, 11},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := transform(tt.args.src); !reflect.DeepEqual(got, tt.want) {
t.Errorf("transform() = %v, want %v", got, tt.want)
}
})
}
}
func Test_reverse(t *testing.T) {
type args struct {
src []int
}
tests := []struct {
name string
args args
want []int
}{
{
"test1",
args{
[]int{1, 2, 3},
},
[]int{3, 2, 1},
},
{
"test2",
args{
[]int{1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3},
},
[]int{3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := reverse(tt.args.src); !reflect.DeepEqual(got, tt.want) {
t.Errorf("reverse() = %v, want %v", got, tt.want)
}
})
}
}