Page 167 -
P. 167

public void testTypicalResults( ) {
                                Account accounts[] = new Account[3];
                                accounts[0] = new Account( );
                                accounts[0].principal = 35;
                                accounts[0].rate = (float) .04;
                                accounts[0].daysActive = 365;
                                accounts[0].accountType = Account.PREMIUM;

                                accounts[1] = new Account( );
                                accounts[1].principal = 100;
                                accounts[1].rate = (float) .035;
                                accounts[1].daysActive = 100;
                                accounts[1].accountType = Account.BUDGET;
                                accounts[2] = new Account( );
                                accounts[2].principal = 50;
                                accounts[2].rate = (float) .04;
                                accounts[2].daysActive = 600;
                                accounts[2].accountType = Account.PREMIUM_PLUS;

                                float result = feeCalculation.calculateFee(accounts);
                                assertEquals(result, (float) 0.060289, (float) 0.00001);
                            }

                          This test passes. The call to feeCalculation( ) with those three accounts returns a value of
                          0.060289383, which matches the value passed to assertEquals( ) within the specified toler-
                          ance of .000001. The assertion does not cause a failure, and the test case completes.
                          It’s important to test unexpected input. The programmer may not have expected
                          feeCalculation( ) to receive a set of accounts that contained no premium accounts. So the
                          second test checks for a set of non-premium accounts:

                            public void testNonPremiumAccounts( ) {
                                Account accounts[] = new Account[2];

                                accounts[0] = new Account( );
                                accounts[0].principal = 12;
                                accounts[0].rate = (float) .025;
                                accounts[0].daysActive = 100;
                                accounts[0].accountType = Account.BUDGET;

                                accounts[1] = new Account( );
                                accounts[1].principal = 50;
                                accounts[1].rate = (float) .0265;
                                accounts[1].daysActive = 150;
                                accounts[1].accountType = Account.STANDARD;

                                float result = feeCalculation.calculateFee(accounts);
                                assertEquals(result, 0, 0.0001);
                            }
                          The expected result for this test is 0, and it passes.






                                                                                  DESIGN AND PROGRAMMING  159
   162   163   164   165   166   167   168   169   170   171   172