mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-30 02:18:42 +01:00
Code kata restarting
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func ReverseString(s string) string {
|
||||
tmp := []byte(s)
|
||||
l := len(tmp)
|
||||
for i := 0; i < l/2; i++ {
|
||||
tmp[i], tmp[l-i-1] = tmp[l-i-1], tmp[i]
|
||||
}
|
||||
return string(tmp)
|
||||
}
|
||||
|
||||
func TestReverseString(t *testing.T) {
|
||||
tt := []struct {
|
||||
name string
|
||||
input string
|
||||
want string
|
||||
}{
|
||||
{"test", "test", "tset"},
|
||||
{"testing", "testing", "gnitset"},
|
||||
}
|
||||
|
||||
for _, tc := range tt {
|
||||
got := ReverseString(tc.input)
|
||||
if got != tc.want {
|
||||
t.Errorf("ReverseString(%s) = %s, want %s", tc.input, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user