Code kata restarting

This commit is contained in:
VicRen
2023-08-04 10:18:54 +08:00
parent 268e4686dc
commit 4b33737441
7 changed files with 282 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package main
import "testing"
func ReverseString(s string) string {
tm := []byte(s)
l := len(s)
for i := 0; i < l/2; i++ {
tm[i], tm[l-1-i] = tm[l-1-i], tm[i]
}
return string(tm)
}
func TestReverseString(t *testing.T) {
tt := []struct {
name string
input string
want string
}{
{"1", "test", "tset"},
{"2", "testing", "gnitset"},
{"3", "this is a testing string", "gnirts gnitset a si siht"},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
got := ReverseString(tc.input)
if got != tc.want {
t.Errorf("ReverseString(%s) = %s, want %s", tc.input, got, tc.want)
}
})
}
}