Files
Veyra/internal/model/money_test.go
T
Blizzard 92329ddce2
Checks / verify (push) Failing after 9m52s
feat: 完成模拟交易闭环、App 与 A 股行情接入
统一单入口 Go 工程与前端依赖目录,增加后台供应商配置、候选审核、计划预算、成交冲正、持仓复盘和站内通知。接入策略版本、Python 回测、可配置 A 股公开行情及 zap 文件轮转日志,补充迁移、契约与验证。
2026-10-08 22:58:52 +08:00

33 lines
1.0 KiB
Go

package model
import "testing"
func TestExactMoney(t *testing.T) {
for _, tc := range []struct {
input string
minor int64
formatted string
}{{"0", 0, "0.00"}, {"0.01", 1, "0.01"}, {"100000.10", 10000010, "100000.10"}, {"3.1", 310, "3.10"}, {"1000000000.00", 100000000000, "1000000000.00"}} {
amount, err := ParseMoney(tc.input)
if err != nil || amount != tc.minor || FormatMoney(amount) != tc.formatted {
t.Fatalf("%s: amount=%d err=%v", tc.input, amount, err)
}
}
for _, input := range []string{"-1", "1.001", "1e3", "NaN", " 1", "01", "1.", "1000000000.01", "999999999999999999999", ""} {
if _, err := ParseMoney(input); err == nil {
t.Fatalf("accepted invalid amount %q", input)
}
}
}
func TestSignedLedgerMoney(t *testing.T) {
for _, tc := range []struct {
minor int64
want string
}{{-1, "-0.01"}, {-100, "-1.00"}, {-1005, "-10.05"}, {0, "0.00"}, {-9223372036854775808, "-92233720368547758.08"}} {
if got := FormatMoney(tc.minor); got != tc.want {
t.Fatalf("got %s want %s", got, tc.want)
}
}
}