本文整理汇总了Golang中github.com/jbowles/money.Money.Sub方法的典型用法代码示例。如果您正苦于以下问题:Golang Money.Sub方法的具体用法?Golang Money.Sub怎么用?Golang Money.Sub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jbowles/money.Money
的用法示例。
在下文中一共展示了Money.Sub方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestMoneyOverflow
func TestMoneyOverflow(t *testing.T) {
flag.Parse()
if ovf == 0 {
t.Skip("Skip overflow no 'overflow' cli flag set: 'ovf=1 will run it'")
}
r := random(1, 25)
m1 := money.Money{M: money.MaxInt}
m2 := money.Money{M: money.MinInt}
if (r % 2) == 1 {
_ = m1.Add(&m1)
} else {
_ = m2.Sub(&m1)
}
/*
** this was testing using fields on the struct to check for overlfow errors
// overflow error should return value of struct attempting op
if res.Valuei() != int64(0) {
t.Error("expected overflow value to be zero", res.Valuei())
}
if res.OvfErr != true {
t.Error("expected ok to be false", res.OvfErr)
}
if len(res.Ovf) < 1 {
t.Error("need overflow message", res.Ovf)
}
*/
}
示例2: TestMoneySub
// check subtraction is good but also that original values are not modified
func TestMoneySub(t *testing.T) {
m1 := money.Money{M: 67}
m2 := money.Money{M: 6700}
res := m2.Sub(&m1)
finResi := int64(6633)
finResf := float64(66.33)
if res.Valuei() != finResi {
t.Error("expected '6633' got: ", res.Valuei())
}
if res.Valuef() != finResf {
t.Error("expected '66.33' got: ", res.Valuef())
}
if m1.Valuei() != int64(67) {
t.Error("expected '67' got: ", m1.Valuei())
}
if m2.Valuei() != int64(6700) {
t.Error("expected '6700' got: ", m2.Valuei())
}
if m1.Valuef() != float64(0.67) {
t.Error("expected '0.67' got: ", m1.Valuef())
}
if m2.Valuef() != float64(67.00) {
t.Error("expected '67.00' got: ", m2.Valuef())
}
if res.StringD() != "66.33" {
t.Error("expected '66.33' got: ", res.StringD())
}
}