mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 19:54:43 +01:00
36 lines
621 B
Go
36 lines
621 B
Go
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"},
|
|
{"12", 12, "12"},
|
|
{"123", 123, "123"},
|
|
{"32123", 32123, "32123"},
|
|
{"1232123", 1232123, "1232123"},
|
|
}
|
|
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|