Example #1
0
// check multiplication is good but also that original values are not modified
func TestMoneyMul(t *testing.T) {
	m1 := money.Money{M: 67}   //67 cents!!
	m2 := money.Money{M: 6700} // 67 dollars
	res := m2.Mul(&m1)
	finResi := int64(4489)    // 44 dollars and 89 cents
	finResf := float64(44.89) // 44 dollars and 89 cents

	if res.Valuei() != finResi {
		t.Error("expected '4489' got: ", res.Valuei())
	}

	if res.Valuef() != finResf {
		t.Error("expected '44.89' 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() != "44.89" {
		t.Error("expected '44.89' got: ", res.StringD())
	}
}