Ejemplo n.º 1
0
func verifyTerms(t *testing.T, terms []*Term, balance currency.Amount) {
	prevBalance := balance.Int64()
	for _, term := range terms {
		verifyTerm(t, term)
		balance := term.Balance().Int64()
		if prevBalance-term.Principal().Int64() != balance {
			t.Error("Balance wrong")
		}
		prevBalance = balance
	}
	if prevBalance != 0 {
		t.Error("Final balance not zero.")
	}
}
Ejemplo n.º 2
0
func solveForPayment(
	amount currency.Amount, rate float64, length int) currency.Amount {
	amountF := amount.Float64()
	if rate == 0.0 {
		return amount.FromFloat64(amountF / float64(length))
	}
	result := amount.FromFloat64(amountF * rate * (1.0 + 1.0/(math.Pow((1.0+rate), float64(length))-1.0)))

	resultI := result.Int64()
	if resultI <= 0 {
		resultI = 1
	}
	interestOnly := amount.FromFloat64(amountF * rate).Int64()
	if resultI <= interestOnly {
		resultI = interestOnly + 1
	}
	return result.FromInt64(resultI)
}