68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package tiles
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestHuaPaiShortSplit(t *testing.T) {
|
|
testCases := []struct {
|
|
input int
|
|
output string
|
|
err error
|
|
}{
|
|
{0, "", fmt.Errorf("invalid hua pai index 0")},
|
|
{1, "ME", nil},
|
|
{2, "LA", nil},
|
|
{3, "ZU", nil},
|
|
{4, "JU", nil},
|
|
{5, "CH", nil},
|
|
{6, "XA", nil},
|
|
{7, "QI", nil},
|
|
{8, "DN", nil},
|
|
{9, "", fmt.Errorf("invalid hua pai index 9")},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(fmt.Sprintf("Test case %d", tc.input), func(t *testing.T) {
|
|
result, err := huaPaiShortSplit(tc.input)
|
|
if err != nil {
|
|
if tc.err != nil {
|
|
if err.Error() != tc.err.Error() {
|
|
t.Errorf("Expected error: %v, got: %v", tc.err, err)
|
|
}
|
|
return
|
|
}
|
|
t.Errorf("not expect error, but got %v", err)
|
|
} else if result != tc.output {
|
|
t.Errorf("Expected result: %v, got: %v", tc.output, result)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
func TestShortToArray(t *testing.T) {
|
|
type testcase struct {
|
|
Name string
|
|
Arg string
|
|
Want []string
|
|
}
|
|
testcases := []testcase{
|
|
{Name: "自创格式", Arg: "12W56T456B1234567Z", Want: []string{"1W", "2W", "5T", "6T", "4B", "5B", "6B", "DO", "XI", "NA", "BE", "ZH", "FA", "BA"}},
|
|
{Name: "日麻格式", Arg: "1134m4p24s123677z6m", Want: []string{"1W", "1W", "3W", "4W", "4B", "2T", "4T", "DO", "NA", "XI", "FA", "ZH", "ZH", "6W"}},
|
|
}
|
|
for _, tc := range testcases {
|
|
t.Run(tc.Name, func(t *testing.T) {
|
|
result, err := shortToArray(tc.Arg)
|
|
if err != nil {
|
|
log.Fatalf("Failed in translating tiles %s , error: %s", tc.Arg, err)
|
|
}
|
|
fmt.Println(result)
|
|
if !reflect.DeepEqual(result, tc.Want) {
|
|
log.Fatalf("Failed in translating tiles %s , expectd: %v, got %v", tc.Arg, tc.Want, result)
|
|
}
|
|
})
|
|
}
|
|
}
|