mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 21:24:46 +01:00
20201209
This commit is contained in:
25
20201209/main.go
Normal file
25
20201209/main.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func transform(src [][]int) [][]int {
|
||||||
|
for i := 0; i < len(src); i++ {
|
||||||
|
for j := i; j < len(src); j++ {
|
||||||
|
src[i][j], src[j][i] = src[j][i], src[i][j]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i, l := range src {
|
||||||
|
src[i] = reverse(l)
|
||||||
|
}
|
||||||
|
return src
|
||||||
|
}
|
||||||
|
|
||||||
|
func reverse(src []int) []int {
|
||||||
|
l := len(src)
|
||||||
|
for i := 0; i < l/2; i++ {
|
||||||
|
src[i], src[l-i-1] = src[l-i-1], src[i]
|
||||||
|
}
|
||||||
|
return src
|
||||||
|
}
|
||||||
86
20201209/main_test.go
Normal file
86
20201209/main_test.go
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user