示例#1
0
func TestMoneyAbs(t *testing.T) {
	v1 := int64(7839)
	v2 := float64(38261748.09)
	m1 := money.Money{M: -v1}
	m2 := money.Money{}
	m2.Updatef(-v2)

	m1abs := m1.Abs()
	m2abs := m2.Abs()

	m1pos := money.Money{M: v1}
	m2pos := money.Money{}
	m2pos.Updatef(v2)

	if m1abs.Valuei() != m1pos.Valuei() {
		t.Error("expected '7839' got: ", m1abs.Valuei())
	}

	if m2abs.Valuei() != m2pos.Valuei() {
		t.Error("expected '3826174809' got: ", m2abs.Valuei())
	}

	if m1.Abs().Valuei() != m1pos.Valuei() {
		t.Error("expected '7839' got: ", m1.Abs().Valuei())
	}

	if m2.Abs().Valuei() != m2pos.Valuei() {
		t.Error("expected '3826174809' got:", m2.Abs().Valuei())
	}

	//verify original values are still negative
	if m1.Valuei() != -m1pos.Valuei() {
		t.Error("expected '-7839' got: ", m1.Valuei())
	}

	if m2.Valuei() != -m2pos.Valuei() {
		t.Error("expected '-3826174809' got: ", m2.Valuei())
	}
}