mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 18:34:42 +01:00
20201210
This commit is contained in:
29
20201210/main.go
Normal file
29
20201210/main.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
|
||||
func replace(src string) string {
|
||||
var ret []rune
|
||||
l := len(src)
|
||||
cursor := 0
|
||||
for {
|
||||
if cursor == l {
|
||||
break
|
||||
}
|
||||
if cursor < l-1 && src[cursor] == '(' && src[cursor+1] == ')' {
|
||||
ret = append(ret, 'o')
|
||||
cursor += 2
|
||||
continue
|
||||
}
|
||||
if cursor < l-3 && src[cursor] == '(' && src[cursor+3] == ')' {
|
||||
ret = append(ret, []rune{'a', 'l'}...)
|
||||
cursor += 4
|
||||
continue
|
||||
}
|
||||
ret = append(ret, rune(src[cursor]))
|
||||
cursor++
|
||||
}
|
||||
return string(ret)
|
||||
}
|
||||
43
20201210/main_test.go
Normal file
43
20201210/main_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func Test_replace(t *testing.T) {
|
||||
type args struct {
|
||||
src string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
}{
|
||||
{
|
||||
"test1",
|
||||
args{
|
||||
"G()(al)",
|
||||
},
|
||||
"Goal",
|
||||
},
|
||||
{
|
||||
"test2",
|
||||
args{
|
||||
"G()()()()(al)",
|
||||
},
|
||||
"Gooooal",
|
||||
},
|
||||
{
|
||||
"test3",
|
||||
args{
|
||||
"(al)G(al)()()G",
|
||||
},
|
||||
"alGalooG",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := replace(tt.args.src); got != tt.want {
|
||||
t.Errorf("replace() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user