mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-25 00:44:42 +01:00
Code kata restarting
This commit is contained in:
32
reverseString/main_test.go
Normal file
32
reverseString/main_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user