Files
bj_power/bj_power_mes/common/dockcode/dockcode_test.go
T

84 lines
2.1 KiB
Go
Raw Normal View History

package dockcode
import "testing"
// 编码规则:GW{工位号}{Z|Y},Z=左、Y=右,工位 1~10 统一,不做左右互换。
func TestStation(t *testing.T) {
cases := []struct {
no int
left bool
want string
}{
{1, true, "GW1Z"}, {1, false, "GW1Y"},
{2, true, "GW2Z"}, {2, false, "GW2Y"},
{10, true, "GW10Z"}, {10, false, "GW10Y"},
{0, true, ""}, {11, false, ""},
}
for _, c := range cases {
if got := Station(c.no, c.left); got != c.want {
t.Fatalf("Station(%d,%v)=%q, want %q", c.no, c.left, got, c.want)
}
}
}
func TestParse(t *testing.T) {
for _, code := range []string{"GW1Z", "GW1Y", "GW2Z", "GW10Y", "gw3z"} {
if _, _, ok := Parse(code); !ok {
t.Fatalf("Parse(%q) 应解析成功", code)
}
}
for _, code := range []string{"", "JBT21", "GW0Z", "GW11Z", "GW1X", "GWX", "G1Z", "GW1"} {
if _, _, ok := Parse(code); ok {
t.Fatalf("Parse(%q) 不应解析成功", code)
}
}
n, left, _ := Parse("GW2Z")
if n != 2 || !left {
t.Fatalf("Parse(GW2Z)=%d,%v,want 2,true", n, left)
}
}
// 接驳台序号(PLC 位序):奇数工位 1=左(Z)/2=右(Y),偶数工位 1=右(Y)/2=左(Z)。
func TestSeq(t *testing.T) {
cases := map[string]int{
"GW1Z": 1, "GW1Y": 2,
"GW2Y": 3, "GW2Z": 4,
"GW3Z": 5, "GW3Y": 6,
"GW10Y": 19, "GW10Z": 20,
"JBT21": 0, "A1": 0,
}
for code, want := range cases {
if got := Seq(code); got != want {
t.Fatalf("Seq(%q)=%d, want %d", code, got, want)
}
}
}
func TestCodeOfSeq(t *testing.T) {
for seq := 1; seq <= 20; seq++ {
code := CodeOfSeq(seq)
if code == "" {
t.Fatalf("CodeOfSeq(%d) 为空", seq)
}
if got := Seq(code); got != seq {
t.Fatalf("CodeOfSeq(%d)=%q 反解序号=%d,不自洽", seq, code, got)
}
}
if CodeOfSeq(0) != "" || CodeOfSeq(21) != "" {
t.Fatalf("越界序号应返回空串")
}
}
func TestLabel(t *testing.T) {
cases := map[string]string{
"GW1Z": "工位1左", "GW1Y": "工位1右",
"GW2Z": "工位2左", "GW10Y": "工位10右",
"JBT21": "库房接驳台", "A1": "A1",
}
for code, want := range cases {
if got := Label(code); got != want {
t.Fatalf("Label(%q)=%q, want %q", code, got, want)
}
}
}