mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 21:24:46 +01:00
20201228
This commit is contained in:
37
20201228/main.go
Normal file
37
20201228/main.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func transform(s string) []string {
|
||||||
|
return process(strings.Split(s, " "))
|
||||||
|
}
|
||||||
|
|
||||||
|
func process(src []string) []string {
|
||||||
|
maxL := 0
|
||||||
|
for _, s := range src {
|
||||||
|
if len(s) > maxL {
|
||||||
|
maxL = len(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mid := make([]string, maxL)
|
||||||
|
for i := 0; i < len(mid); i++ {
|
||||||
|
for _, s := range src {
|
||||||
|
if i < len(s) {
|
||||||
|
mid[i] += string(s[i])
|
||||||
|
} else {
|
||||||
|
mid[i] += " "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var ret []string
|
||||||
|
for _, s := range mid {
|
||||||
|
ret = append(ret, strings.TrimRight(s, " "))
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
74
20201228/main_test.go
Normal file
74
20201228/main_test.go
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_process(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
src []string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"test1",
|
||||||
|
args{[]string{"HOW", "ARE", "YOU"}},
|
||||||
|
[]string{"HAY", "ORO", "WEU"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test2",
|
||||||
|
args{[]string{"TO", "BE", "OR", "NOT", "TO", "BE"}},
|
||||||
|
[]string{"TBONTB", "OEROOE", " T"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test3",
|
||||||
|
args{[]string{"CONTEST", "IS", "COMING"}},
|
||||||
|
[]string{"CIC", "OSO", "N M", "T I", "E N", "S G", "T"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := process(tt.args.src); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("process() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_transform(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
s string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"test1",
|
||||||
|
args{"HOW ARE YOU"},
|
||||||
|
[]string{"HAY", "ORO", "WEU"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test2",
|
||||||
|
args{"TO BE OR NOT TO BE"},
|
||||||
|
[]string{"TBONTB", "OEROOE", " T"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test3",
|
||||||
|
args{"CONTEST IS COMING"},
|
||||||
|
[]string{"CIC", "OSO", "N M", "T I", "E N", "S G", "T"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := transform(tt.args.s); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("transform() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user