初始化
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// 积分账务单元测试,验证积分精度解析和非法输入处理。
|
||||
package billing
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestParsePointCents 验证积分字符串能够稳定转换为整数分值。
|
||||
func TestParsePointCents(t *testing.T) {
|
||||
tests := map[string]int64{
|
||||
"0": 0,
|
||||
"1": 100,
|
||||
"1.2": 120,
|
||||
"1.23": 123,
|
||||
"1.2300": 123,
|
||||
"999.99": 99999,
|
||||
}
|
||||
for input, expected := range tests {
|
||||
actual, err := parsePointCents(input)
|
||||
if err != nil {
|
||||
t.Fatalf("parse %q: %v", input, err)
|
||||
}
|
||||
if actual != expected {
|
||||
t.Fatalf("parse %q: expected %d, got %d", input, expected, actual)
|
||||
}
|
||||
}
|
||||
for _, input := range []string{"", "-1", "1.234", "abc"} {
|
||||
if _, err := parsePointCents(input); err == nil {
|
||||
t.Fatalf("expected %q to be rejected", input)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user