Initial commit
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package pkg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPrint(t *testing.T) {
|
||||
var env environment
|
||||
env.Print()
|
||||
}
|
||||
|
||||
func TestPatternNormalization(t *testing.T) {
|
||||
var env environment
|
||||
handTiles := env.PatternNormalization()
|
||||
fmt.Println(handTiles)
|
||||
}
|
||||
|
||||
func TestTileComparator(t *testing.T) {
|
||||
type testcase struct {
|
||||
Args [2]string
|
||||
Expected bool
|
||||
}
|
||||
testcases := []testcase{
|
||||
{Args: [2]string{"1W", "6W"}, Expected: true},
|
||||
{Args: [2]string{"9W", "1B"}, Expected: true},
|
||||
{Args: [2]string{"4W", "BA"}, Expected: true},
|
||||
{Args: [2]string{"BE", "NA"}, Expected: false},
|
||||
}
|
||||
for _, v := range testcases {
|
||||
result, err := TileComparator(v.Args[0], v.Args[1])
|
||||
if err != nil {
|
||||
log.Fatalf("Failed in comparing tiles: %v", err)
|
||||
}
|
||||
if result != v.Expected {
|
||||
log.Fatalf("Failed in comparing tiles %s vs %s, expectd: %t, got %t", v.Args[0], v.Args[1], v.Expected, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSort(t *testing.T) {
|
||||
type testcase struct {
|
||||
Args []string
|
||||
Expected []string
|
||||
}
|
||||
testcases := []testcase{
|
||||
{Args: []string{"7B", "4T", "2T", "3W", "5W", "4W", "BA", "DO"}, Expected: []string{"3W", "4W", "5W", "2T", "4T", "7B", "DO", "BA"}},
|
||||
{Args: []string{"8B", "8B", "7B", "6B", "5W", "4W", "4W", "4W"}, Expected: []string{"4W", "4W", "4W", "5W", "6B", "7B", "8B", "8B"}},
|
||||
{Args: []string{"BA", "BA", "BA", "BA", "XI", "XI", "XI", "NA"}, Expected: []string{"XI", "XI", "XI", "NA", "BA", "BA", "BA", "BA"}},
|
||||
}
|
||||
for _, v := range testcases {
|
||||
err := Sort(v.Args)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed in sorting tiles: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(v.Args, v.Expected) {
|
||||
log.Fatalf("Failed in sorting tiles expectd: %v, got %v", v.Expected, v.Args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckXushuTile(t *testing.T) {
|
||||
type testcase struct {
|
||||
Args []string
|
||||
Expected [][][]string
|
||||
}
|
||||
testcases := []testcase{
|
||||
{Args: []string{}, Expected: [][][]string{}},
|
||||
{Args: []string{"4W", "4W"}, Expected: [][][]string{{{"4W", "4W"}}}},
|
||||
{Args: []string{"4W", "4W", "4W", "4W"}, Expected: [][][]string{{{"4W", "4W", "4W", "4W"}}, {{"4W", "4W"}, {"4W", "4W"}}}},
|
||||
{Args: []string{"2W", "3W", "3W", "4W", "4W", "4W", "5W", "5W", "6W"}, Expected: [][][]string{{{"2W", "3W", "4W"}, {"3W", "4W", "5W"}, {"4W", "5W", "6W"}}}},
|
||||
{Args: []string{"2W", "3W", "3W", "4W", "4W", "4W", "5W", "5W", "5W", "5W", "6W"}, Expected: [][][]string{{{"2W", "3W", "4W"}, {"3W", "4W", "5W"}, {"4W", "5W", "6W"}, {"5W", "5W"}}}},
|
||||
{Args: []string{"3W", "3W", "3W", "4W", "4W", "4W", "5W", "5W", "5W"}, Expected: [][][]string{{{"3W", "3W", "3W"}, {"4W", "4W", "4W"}, {"5W", "5W", "5W"}}, {{"3W", "4W", "5W"}, {"3W", "4W", "5W"}, {"3W", "4W", "5W"}}}},
|
||||
{Args: []string{"3W", "3W", "3W", "3W", "4W", "4W", "4W", "4W", "5W", "5W", "5W", "5W"}, Expected: [][][]string{{{"3W", "3W", "3W", "3W"}, {"4W", "4W", "4W", "4W"}, {"5W", "5W", "5W", "5W"}}, {{"3W", "4W", "5W"}, {"3W", "3W", "3W"}, {"4W", "4W", "4W"}, {"5W", "5W", "5W"}}, {{"3W", "4W", "5W"}, {"3W", "4W", "5W"}, {"3W", "4W", "5W"}, {"3W", "4W", "5W"}}, {{"3W", "3W"}, {"3W", "3W"}, {"4W", "4W"}, {"4W", "4W"}, {"5W", "5W"}, {"5W", "5W"}}}},
|
||||
{Args: []string{"1W", "4W", "7W"}, Expected: [][][]string{{{"1W"}, {"4W"}, {"7W"}}}},
|
||||
{Args: []string{"4W", "7W"}, Expected: [][][]string{{{"4W"}, {"7W"}}}},
|
||||
{Args: []string{"1W", "4W"}, Expected: [][][]string{{{"1W"}, {"4W"}}}},
|
||||
{Args: []string{"1W", "7W"}, Expected: [][][]string{{{"1W"}, {"7W"}}}},
|
||||
{Args: []string{"1W", "1W", "9W"}, Expected: [][][]string{{{"1W"}, {"1W"}, {"9W"}}}},
|
||||
{Args: []string{"1W", "9W", "9W"}, Expected: [][][]string{{{"1W"}, {"9W"}, {"9W"}}}},
|
||||
{Args: []string{"1W", "9W"}, Expected: [][][]string{{{"1W"}, {"9W"}}}},
|
||||
{Args: []string{"1W", "3W", "5W"}, Expected: [][][]string{}},
|
||||
}
|
||||
for _, v := range testcases {
|
||||
result, err := CheckXushuTile(v.Args)
|
||||
if err != nil {
|
||||
log.Printf("Failed in dividing tiles: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(result, v.Expected) {
|
||||
log.Fatalf("Failed in dividing tiles expectd: %v, got %v", v.Expected, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user