mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 19:54:43 +01:00
33 lines
628 B
Go
33 lines
628 B
Go
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)
|
|
}
|
|
})
|
|
}
|
|
}
|