22
33import static org .junit .Assert .*;
44
5+ import org .junit .Ignore ;
56import org .junit .Test ;
67
78public class _SavingsAccountYearTest {
@@ -10,68 +11,92 @@ public class _SavingsAccountYearTest {
1011 public void startingBalanceMatchesConstructor () {
1112 assertEquals (10000 , newAccount ().startingBalance ());
1213 }
14+
15+ @ Test
16+ public void startingPrincipalMatchesConstructor () {
17+ SavingsAccountYear year = new SavingsAccountYear (10000 , 3000 , 10 );
18+ assertEquals ("Starting principal" , 3000 , year .startingPrincipal ());
19+ }
1320
1421 @ Test
1522 public void interestRateMatchesConstructor () {
1623 assertEquals (10 , newAccount ().interestRate ());
1724 }
18-
25+
1926 @ Test
20- public void endingBalanceAppliesInterestRate () {
21- assertEquals (11000 , newAccount ().endingBalance (25 ));
27+ public void startingCapitalGainsIsStartingBalanceMinusStartingPrincipal () {
28+ SavingsAccountYear year = new SavingsAccountYear (10000 , 3000 , 10 );
29+ assertEquals (7000 , year .startingCapitalGains ());
2230 }
2331
2432 @ Test
25- public void nextYearsStartingBalanceEqualsThisYearsEndingBalance () {
26- SavingsAccountYear thisYear = newAccount ( );
27- assertEquals ( thisYear . endingBalance ( 25 ), thisYear . nextYear ( 25 )
28- . startingBalance ());
33+ public void endingPrincipalConsidersWithdrawals () {
34+ SavingsAccountYear year = new SavingsAccountYear ( 10000 , 3000 , 10 );
35+ year . withdraw ( 2000 );
36+ assertEquals ( "Ending principal" , 1000 , year . endingPrincipal ());
2937 }
3038
3139 @ Test
32- public void nextYearsInterestRateEqualsThisYearsInterestRate () {
33- SavingsAccountYear thisYear = newAccount ( );
34- assertEquals ( thisYear . interestRate (), thisYear . nextYear ( 25 )
35- . interestRate ());
40+ public void endingPrincipalNeverGoesBelowZero () {
41+ SavingsAccountYear year = new SavingsAccountYear ( 10000 , 3000 , 10 );
42+ year . withdraw ( 4000 );
43+ assertEquals ( "ending principal" , 0 , year . endingPrincipal ());
3644 }
37-
45+
46+ @ Test
47+ public void interestEarnedIsStartingBalanceCombinedWithInterestRate () {
48+ SavingsAccountYear year = new SavingsAccountYear (10000 , 3000 , 10 );
49+ assertEquals (1000 ,year .interestEarned (25 ));
50+ }
51+
3852 @ Test
39- public void withdrawingFundsOccursAtTheBeginningOfTheYear () {
40- SavingsAccountYear year = new SavingsAccountYear ( 10000 , 10 );
53+ public void withdrawingFundsDoNotEarnInterest () {
54+ SavingsAccountYear year = newAccount ( );
4155 year .withdraw (1000 );
42- assertEquals (9900 , year .endingBalance (25 ));
56+ assertEquals (900 , year .interestEarned (25 ));
4357 }
44-
58+
4559 @ Test
46- public void multipleWithdrawalsInAYear () {
47- SavingsAccountYear year = new SavingsAccountYear (10000 , 10 );
60+ public void totalWithdrawnIncludingCapitalGains () {
61+ SavingsAccountYear year = new SavingsAccountYear (10000 , 0 , 10 );
4862 year .withdraw (1000 );
49- year .withdraw (2000 );
50- assertEquals (3000 , year .totalWithdrawn ());
63+ assertEquals ("capital gains tax" , 333 , year .capitalGainsTaxIncurred (25 ));
64+ assertEquals ("total withdrawn" , 1333 , year .totalWithdrawn (25 ));
65+ }
66+
67+ @ Test
68+ public void capitalGainsTaxesDoNotEarnInterest () {
69+ SavingsAccountYear year = new SavingsAccountYear (10000 , 0 , 10 );
70+ year .withdraw (1000 );
71+ assertEquals ("capital gains withdrawn" , 1000 , year .capitalGainsWithdrawn ());
72+ assertEquals ("capital gains tax" , 333 , year .capitalGainsTaxIncurred (25 ));
73+ // assertEquals("total withdrawn", 1333, year.totalWithdrawnIncludingCapitalGains());
74+ assertEquals ("interest earned" , 866 , year .interestEarned (25 ));
5175 }
5276
5377 @ Test
54- public void principal () {
78+ @ Ignore
79+ public void endingCapitalGainsIncludesInterestEarned () {
5580 SavingsAccountYear year = new SavingsAccountYear (10000 , 3000 , 10 );
56- assertEquals ("Starting principal" , 3000 , year .startingPrincipal ());
81+ assertEquals (7000 , year .startingCapitalGains ());
82+ assertEquals (3000 +1000 , year .endingCapitalGains ());
5783 }
5884
5985 @ Test
60- public void endingPrincipal () {
61- SavingsAccountYear year = new SavingsAccountYear (10000 , 3000 , 10 );
62- year .withdraw (2000 );
63- assertEquals ("Ending principal" , 1000 , year .endingPrincipal ());
86+ public void endingBalanceAppliesInterestRate () {
87+ assertEquals (11000 , newAccount ().endingBalance (25 ));
6488 }
6589
6690 @ Test
67- public void endingPrincipalNeverGoesBelowZero () {
68- SavingsAccountYear year = new SavingsAccountYear (10000 , 3000 , 10 );
69- year .withdraw (4000 );
70- assertEquals ("ending principal" , 0 , year .endingPrincipal ());
91+ public void multipleWithdrawalsInAYearAreTotaled () {
92+ SavingsAccountYear year = newAccount ();
93+ year .withdraw (1000 );
94+ year .withdraw (2000 );
95+ assertEquals (3000 , year .totalWithdrawnExceptCapitalGainsTax ());
7196 }
7297
7398 @ Test
74- public void capitalGainsWithdrawn () {
99+ public void withdrawingMoreThanPrincipalTakesFromCapitalGains () {
75100 SavingsAccountYear year = new SavingsAccountYear (10000 , 3000 , 10 );
76101 year .withdraw (1000 );
77102 assertEquals (0 , year .capitalGainsWithdrawn ());
@@ -95,8 +120,22 @@ public void capitalGainsTaxIsIncludedInEndingBalance() {
95120 assertEquals (10000 - 5000 - 666 + 433 , year .endingBalance (25 ));
96121 }
97122
123+ @ Test
124+ public void nextYearsStartingBalanceEqualsThisYearsEndingBalance () {
125+ SavingsAccountYear thisYear = newAccount ();
126+ assertEquals (thisYear .endingBalance (25 ), thisYear .nextYear (25 )
127+ .startingBalance ());
128+ }
129+
130+ @ Test
131+ public void nextYearsInterestRateEqualsThisYearsInterestRate () {
132+ SavingsAccountYear thisYear = newAccount ();
133+ assertEquals (thisYear .interestRate (), thisYear .nextYear (25 )
134+ .interestRate ());
135+ }
136+
98137 private SavingsAccountYear newAccount () {
99- SavingsAccountYear account = new SavingsAccountYear (10000 , 10 );
138+ SavingsAccountYear account = new SavingsAccountYear (10000 , 10000 , 10 );
100139 return account ;
101140 }
102141
0 commit comments