package Hypotheek; import static Hypotheek.Util.* ; import org.junit.* ; import static org.junit.Assert.* ; public class Hypotheek_test { static final float ACCURACY = 0.001f ; @Test public void test1() { int loan = 100 * 100 ; // 100 euro int interestRate = 12 * 100 ; // 12% per annum, so 1% per month int duration = 2 * 12 ; // just 2 years int monthPayment = 2 * 100 ; // 2 euro int age = 1 ; Hypotheek H = new Hypotheek() ; H.setLoan(loan); H.setIterest(interestRate); H.setMonthlyPayment(monthPayment) ; H.setDuration(duration); H.setIncome(age) ; // Calculating expectations: int remaining = loan ; int totalPaidInterest = 0 ; for (int t=0; t0; t++) { int interest = toInt(calcPercentage(toFloat(interestRate)/1200f,remaining)) ; int toPay = monthPayment - interest ; assertTrue(toPay>=0) ; toPay = Math.min(toPay,remaining) ; remaining = remaining - toPay ; totalPaidInterest += interest ; //System.out.println("t = " + t) ; //System.out.println("To pay = " + toPay) ; //System.out.println("Interest = " + interest) ; //System.out.println("Remaining = " + remaining) ; } int expected_remaining = remaining ; int expected_totalPaidInterest = totalPaidInterest ; Hypotheek.Result R = H.calculate() ; System.out.println(">>> remaining = " + R.remaining + ", expected = " + expected_remaining) ; assertTrue(approxEq(R.remaining,expected_remaining,ACCURACY)) ; System.out.println(">>> tot paid interest = " + R.totInterest + ", expected = " + expected_totalPaidInterest) ; assertTrue(approxEq(R.totInterest,expected_totalPaidInterest,ACCURACY)) ; } @Test public void test2() { int loan = 100 * 100 ; // 100 euro int interestRate = 12 * 100 ; // 12% per annum, so 1% per month int duration = 2 * 12 ; // just 2 years int monthPayment = 2 * 100 ; // 2 euro int age = 1 ; int income = 10000 * 100 ; // 10 Keuro Hypotheek H = new Hypotheek() ; H.setLoan(loan); H.setIterest(interestRate); H.setMonthlyPayment(monthPayment) ; H.setDuration(duration); H.setIncome(age) ; H.setIncome(income) ; InkomenBelasting taxsys = new InkomenBelasting2009() ; // Calculating expectations: int remaining = loan ; int totalTaxReduction = 0 ; int yearlyInterest = 0 ; EigenWoningForfait EWforfait = new EigenWoningForfait2007() ; for (int t=0; t0; t++) { int interest = toInt(calcPercentage(toFloat(interestRate)/1200f,remaining)) ; int toPay = monthPayment - interest ; assertTrue(toPay>=0) ; toPay = Math.min(toPay,remaining) ; remaining = remaining - toPay ; yearlyInterest += interest ; if (t % 12 == 11) { totalTaxReduction += taxsys.calcHypBelastingAftrek(income + EWforfait.calc(loan), age, yearlyInterest) ; yearlyInterest = 0 ; } } int expected_remaining = remaining ; int expected_totalTaxReduction = totalTaxReduction ; Hypotheek.Result R = H.calculate() ; System.out.println(">>> remaining = " + R.remaining + ", expected = " + expected_remaining) ; assertTrue(approxEq(R.remaining,expected_remaining,ACCURACY)) ; System.out.println(">>> tot tax reduction = " + R.totTaxReduction + ", expected = " + expected_totalTaxReduction) ; assertTrue(approxEq(R.totTaxReduction,expected_totalTaxReduction,ACCURACY)) ; } }