code kata 230811

This commit is contained in:
VicRen
2023-08-10 11:46:24 +08:00
parent 800a0380b0
commit 51ac462117
8 changed files with 393 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
package main
import "testing"
func ReverseString(s string) string {
r := []rune(s)
for l, e := 0, len(r)-1; l < e; l, e = l+1, e-1 {
r[l], r[e] = r[e], r[l]
}
return string(r)
}
func TestReverseString(t *testing.T) {
tt := []struct {
name string
input string
want string
}{
{"test", "test", "tset"},
{"testing", "testing", "gnitset"},
{"i am testing", "i am testing", "gnitset ma i"},
}
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\n", tc.input, got, tc.want)
}
})
}
}