diff --git a/20201228/main.go b/20201228/main.go new file mode 100644 index 0000000..d5014da --- /dev/null +++ b/20201228/main.go @@ -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 +} diff --git a/20201228/main_test.go b/20201228/main_test.go new file mode 100644 index 0000000..388fe4b --- /dev/null +++ b/20201228/main_test.go @@ -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) + } + }) + } +}