You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.1 KiB
32 lines
1.1 KiB
package comm
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
// 扣费明细存进会议记录 computedevices 列(code:n,code:n),转写失败时按它原路退回。
|
|
// code 可能是带冒号的 MAC,必须按最后一个冒号切。
|
|
func TestDeviceChargesRoundTrip(t *testing.T) {
|
|
in := []DeviceCharge{
|
|
{Code: "F0:A9:12:34:56:78", N: 30},
|
|
{Code: "B0220000000000AB", N: 5},
|
|
}
|
|
s := EncodeDeviceCharges(in)
|
|
if s != "F0:A9:12:34:56:78:30,B0220000000000AB:5" {
|
|
t.Fatalf("编码结果 = %q", s)
|
|
}
|
|
if got := DecodeDeviceCharges(s); !reflect.DeepEqual(got, in) {
|
|
t.Fatalf("解码结果 = %+v, want %+v", got, in)
|
|
}
|
|
// 空码、非正数不进明细;脏数据解析时跳过,不能退出负数
|
|
if got := EncodeDeviceCharges([]DeviceCharge{{Code: "", N: 3}, {Code: "X", N: 0}}); got != "" {
|
|
t.Fatalf("空明细应编码为空串,实际 %q", got)
|
|
}
|
|
if got := DecodeDeviceCharges("abc,:5,X:-3,Y:notnum,Z:7"); !reflect.DeepEqual(got, []DeviceCharge{{Code: "Z", N: 7}}) {
|
|
t.Fatalf("脏数据解析 = %+v", got)
|
|
}
|
|
if got := DecodeDeviceCharges(""); len(got) != 0 {
|
|
t.Fatalf("空串应解析为空,实际 %+v", got)
|
|
}
|
|
}
|
|
|