code kata 230813

This commit is contained in:
VicRen
2023-08-13 20:15:04 +08:00
parent 7c93bc4847
commit a515a19ad7
2 changed files with 79 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
package main
import "testing"
func IntToString(n int) string {
ret := make([]byte, 0)
for n > 0 {
ret = append([]byte{byte('0' + n%10)}, ret...)
n /= 10
}
return string(ret)
}
func TestIntToString(t *testing.T) {
tt := []struct {
name string
input int
want string
}{
{"1", 1, "1"},
{"12345678", 12345678, "12345678"},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
got := IntToString(tc.input)
if got != tc.want {
t.Errorf("IntToString(%d) = %s, want %s\n", tc.input, got, tc.want)
}
})
}
}