mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 22:34:41 +01:00
code kata 230809
This commit is contained in:
32
reverse_string_230809/main_test.go
Normal file
32
reverse_string_230809/main_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func ReverseString(s string) string {
|
||||
ret := []rune(s)
|
||||
for l, r := 0, len(ret)-1; l < r; l, r = l+1, r-1 {
|
||||
ret[l], ret[r] = ret[r], ret[l]
|
||||
}
|
||||
return string(ret)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user