36 lines
891 B
Go
36 lines
891 B
Go
package usecase
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// 單元測試
|
|
func TestEncodeToBase(t *testing.T) {
|
|
tests := []struct {
|
|
num int64
|
|
base int
|
|
length int
|
|
want string
|
|
}{
|
|
// 測試基礎情況
|
|
{num: 0, base: 10, length: 6, want: "OOOOOO"},
|
|
{num: 1, base: 10, length: 6, want: "OOOOOD"},
|
|
|
|
{num: 24, base: 10, length: 6, want: "OOOOWY"},
|
|
{num: 25, base: 10, length: 6, want: "OOOOWG"},
|
|
{num: 1, base: 10, length: 4, want: "OOOD"},
|
|
{num: 24, base: 10, length: 4, want: "OOWY"},
|
|
{num: 25, base: 10, length: 5, want: "OOOWG"},
|
|
{num: 1234567890, base: 10, length: 10, want: "DWXYGBCHEO"}, // 測試大數情況
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run("encodeToBase", func(t *testing.T) {
|
|
got := encodeToBase(tt.num, tt.base, tt.length)
|
|
if got != tt.want {
|
|
t.Errorf("encodeToBase(%d, %d, %d) = %s; want %s", tt.num, tt.base, tt.length, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|