summaryrefslogtreecommitdiff
path: root/src/Q5/EmployeeSavingsTest.java
blob: a85ab326a86de2f8b2759a1876656ec5fb53c8f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package ca.mokhan.test;

import Q5.*;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class EmployeeSavingsTest extends TestCase {
  private EmployeeSavings subject;

  public EmployeeSavingsTest(String testName) {
    super(testName);
    double monthlyContribution = 100.00;
    this.subject = new EmployeeSavings("Tsuyoshi", "Garrett", monthlyContribution);
  }

  public static Test suite() {
    return new TestSuite(EmployeeSavingsTest.class);
  }

  public void testPredictSavingsAfter1Month() {
    // Bankers rounding rules would round this amount down to $100.41
    // the $0.007 would go to the bank.
    assertEquals(100.417, subject.predictBalanceAfterMonths(1));
    assertEquals(201.252, subject.predictBalanceAfterMonths(2));
    assertEquals(302.507, subject.predictBalanceAfterMonths(3));
  }

  public void testPredictInterestAfter1Month() {
    // Bankers rounding rules would round this amount down to $100.41
    // the $0.007 would go to the bank.
    assertEquals(0.417, subject.predictInterestAfterMonths(1));
    assertEquals(1.252, subject.predictInterestAfterMonths(2));
    assertEquals(2.507, subject.predictInterestAfterMonths(3));
  }

  public void testGetAccountValue() {
    assertEquals(subject.predictBalanceAfterMonths(12), subject.getAccountValue());
  }

  public void testCalculateInterests() {
    assertEquals(0.417, subject.calculateInterests()[0]);
    assertEquals(1.252, subject.calculateInterests()[1]);
    assertEquals(2.507, subject.calculateInterests()[2]);
    assertEquals(4.184, subject.calculateInterests()[3]);
    assertEquals(6.285, subject.calculateInterests()[4]);
    assertEquals(8.811, subject.calculateInterests()[5]);
    assertEquals(11.764, subject.calculateInterests()[6]);
    assertEquals(15.147, subject.calculateInterests()[7]);
    assertEquals(18.96, subject.calculateInterests()[8]);
    assertEquals(23.206, subject.calculateInterests()[9]);
    assertEquals(27.886, subject.calculateInterests()[10]);
    assertEquals(33.002, subject.calculateInterests()[11]);
  }

  public void testGenerateMonthlySavings() {
    assertEquals(100.417, subject.generateMonthlySavings()[0]);
    assertEquals(201.252, subject.generateMonthlySavings()[1]);
    assertEquals(302.507, subject.generateMonthlySavings()[2]);
  }

  public void testGetReport() {
    EmployeeSavings[] accounts =
        new EmployeeSavings[] {
          new EmployeeSavings("Elena", "Brandon"),
          new EmployeeSavings("Thomas", "Molson"),
          new EmployeeSavings("Hamilton", "Winn"),
          new EmployeeSavings("Suzie", "Sarandin"),
          new EmployeeSavings("Philip", "Winne"),
          new EmployeeSavings("Alex", "Trebok"),
          new EmployeeSavings("Emma", "Pivoto"),
          new EmployeeSavings("John", "Lenthen"),
          new EmployeeSavings("James", "Lean"),
          new EmployeeSavings("Jane", "Ostin"),
          new EmployeeSavings("Emily", "Car"),
          new EmployeeSavings("Daniel", "Hamshire"),
          new EmployeeSavings("Neda", "Bazdar"),
          new EmployeeSavings("Aaron", "Smith"),
          new EmployeeSavings("Kate", "Hen")
        };
    String report = EmployeeSavings.getReport(accounts);
    for (EmployeeSavings account : accounts) assertTrue(report.contains(account.getFirstName()));
  }
}