Exemplo n.º 1
0
// Neg value make sure 'val' is not updated
func TestMoneyNegNotMutable(t *testing.T) {
	val := money.Money{M: 123456}
	neg := val.Neg()

	if val.Valuei() != int64(123456) {
		t.Error("val should be int64 '123456'", val.Valuei())
	}

	if val.Valuef() != float64(1234.56) {
		t.Error("val should be int64 '1234.56'", val.Valuef())
	}

	if neg.Valuei() != int64(-123456) {
		t.Error("neg.Valuei should be int64 '-123456'", neg.Valuei())
	}

	if neg.Valuef() != float64(-1234.56) {
		t.Error("neg.Valuef should be float64 '-1234.56'", neg.Valuef())
	}

	if val.StringD() != "1234.56" {
		t.Error("val.StringD() should be '1234.56'", val.StringD())
	}
	// TODO oddity for negative money values!!!!
	if neg.StringD() != "-1234.56" {
		t.Error("neg.StringD() should be '-1234.56'", neg.StringD())
	}
}
Exemplo n.º 2
0
func BenchmarkNegValueForMoney(b *testing.B) {
	for i := 0; i < b.N; i++ {
		val := money.Money{M: 123456}
		val.Neg()
	}
}