mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 21:24:46 +01:00
code kata 230806
This commit is contained in:
32
reverse_string_230806/main_test.go
Normal file
32
reverse_string_230806/main_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func ReverseString(s string) string {
|
||||
tmp := []rune(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"},
|
||||
{"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", tc.input, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user