本文整理汇总了Golang中github.com/jbowles/money.Money.Updatei方法的典型用法代码示例。如果您正苦于以下问题:Golang Money.Updatei方法的具体用法?Golang Money.Updatei怎么用?Golang Money.Updatei使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jbowles/money.Money
的用法示例。
在下文中一共展示了Money.Updatei方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestMoneyUpdateIsMoneyType
func TestMoneyUpdateIsMoneyType(t *testing.T) {
m := money.Money{}
var val1 int64 = 7868
res := m.Updatei(val1)
if res.Valuei() != val1 {
t.Error("should be '7868'", res.Valuei())
}
typ := fmt.Sprintf("%T", m)
typPointer := fmt.Sprintf("%T", res)
printValue := fmt.Sprintf("%v", m.M)
if typ != "money.Money" {
t.Error("should be money type, instead it is: ", typ)
}
if typPointer != "*money.Money" {
t.Error("should be money type, instead it is: ", typPointer)
}
if printValue != "7868" {
t.Error("default print value for money Updatei() int64 '7868' should be '7868', but got", printValue)
}
printValued := fmt.Sprintf("%d", m)
//if printValued != "{7868 0}" {
if printValued != "{7868}" {
//t.Error("base 10 print format of money struct should be base value '{7868 0}'", printValued)
t.Error("base 10 print format of money struct should be base value '{7868}'", printValued)
}
}
示例2: TestMoneyUpdateChangesOriginalValue
func TestMoneyUpdateChangesOriginalValue(t *testing.T) {
m := money.Money{M: 67}
m.Updatei(int64(6700))
if m.Valuei() != int64(6700) {
t.Error("original vlaue should be updated to '67.00' but got: ", m.Valuei())
}
}
示例3: TestMoneyStringWithUpdate
func TestMoneyStringWithUpdate(t *testing.T) {
m := money.Money{M: 67}
if m.StringD() != "0.67" {
t.Error("wanted to see '0.67' cents but got: ", m.StringD())
}
var val2 int64 = 6700
m.Updatei(val2)
if m.StringD() != "67.00" {
t.Error("wanted to see '67.00' dollars but got: ", m.StringD())
}
}
示例4: TestMoneySmallNumberSubtractLarger
func TestMoneySmallNumberSubtractLarger(t *testing.T) {
var val1 int64 = 67 //0.67
var val2 int64 = 6700 //67.00
m1 := money.Money{}
m2 := money.Money{}
m1Set := m1.Updatei(val1)
m2Set := m2.Updatei(val2)
res := m1Set.Sub(m2Set)
if res.Valuei() != int64(-6633) {
t.Error("expected negative '-6633' got: ", res.Valuei())
}
if res.Valuef() != float64(-66.33) {
t.Error("expected negative '-66.33' got: ", res.Valuef())
}
}
示例5: TestMoneyNegativeSubUpdate
// verify subtracting negatives with updates does UPDATE and change original values
// and returns correct results
func TestMoneyNegativeSubUpdate(t *testing.T) {
var val1Neg int64 = -1 //-0.01 cents
var val2Pos int64 = 6700 //-67.00 dollars
m1Neg := money.Money{}
m2Pos := money.Money{}
m1SetNeg := m1Neg.Updatei(val1Neg)
m2SetPos := m2Pos.Updatei(val2Pos)
resNeg := m1SetNeg.Sub(m2SetPos)
vali := resNeg.Valuei()
valf := resNeg.Valuef()
if vali != int64(-6701) {
t.Error("expected negative '-6701' got: ", vali)
}
if valf != float64(-67.01) {
t.Error("expected negative '-67.01' got: ", valf)
}
// verify return values from update were set correctly
if m1SetNeg.Valuei() != val1Neg {
t.Error("expected negative '-1' got: ", m1SetNeg.Valuei())
}
if m2SetPos.Valuei() != val2Pos {
t.Error("expected negative '6700' got: ", m2SetPos.Valuei())
}
// verify original values for an update were updated
if m1Neg.Valuei() != val1Neg {
t.Error("expected negative '-1' got: ", m1Neg.Valuei())
}
if m2Pos.Valuei() != val2Pos {
t.Error("expected negative '6700' got: ", m2Pos.Valuei())
}
}