Esempio n. 1
0
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)
	}
}
Esempio n. 2
0
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())
	}
}
Esempio n. 3
0
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())
	}
}
Esempio n. 4
0
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())
	}
}
Esempio n. 5
0
// 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())
	}
}