Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import static org.junit.Assert.*;
import org.junit.Test;
import junit.framework.Assert;
public class BankAccountCompTest {
@Test
public void depositTest() {
BankAccountComp bank = new BankAccountComp();
// Insert 500
bank.deposit(500);
double newBal = bank.getBalance();
Assert.assertEquals(500, newBal, 0.01);
// Insert 312.8 more
bank.deposit(312.8);
newBal = bank.getBalance();
Assert.assertEquals(812.8, newBal, 0.01);
}
@Test
public void withdrawTest() {
// Start the bank with 500
BankAccountComp bank = new BankAccountComp(500);
// Withdraw 200
bank.withdraw(200);
double newBal = bank.getBalance();
Assert.assertEquals(300, newBal, 0.01);
// Withdraw 52.6 more
bank.withdraw(52.6);
newBal = bank.getBalance();
Assert.assertEquals(247.4, newBal, 0.01);
}
@Test
public void accrueTest () {
// Start the bank with 500
BankAccountComp bank = new BankAccountComp(500);
// Accrue for 1 year at 6%: 500 * 1.06 = 530
bank.accrue();
double newBal = bank.getBalance();
Assert.assertEquals(530, newBal, 0.01);
// Accrue for another year at 6%: 530 * 1.06 = 561.8
bank.accrue();
newBal = bank.getBalance();
Assert.assertEquals(561.8, newBal, 0.01);
}
@Test
public void accrueYearsTest () {
// Start the bank with 500
BankAccountComp bank = new BankAccountComp(500);
// Accrue for 2 years at 6%: 500 -> 561.8
bank.accrueYears(2);
double newBal = bank.getBalance();
Assert.assertEquals(561.8, newBal, 0.01);
// Accrue for 10 years at 6%: 561.8 -> 1006.1
bank.accrueYears(10);
newBal = bank.getBalance();
Assert.assertEquals(1006.1, newBal, 0.01);
}
@Test
public void ageTest () {
BankAccountComp bank = new BankAccountComp();
// Should start at 0 years
int age = bank.getAccountAge();
Assert.assertEquals(0, age);
// Fast forward 10 years
bank.accrueYears(10);
age = bank.getAccountAge();
Assert.assertEquals(10, age);
// Fast forward another 60 years: 10 + 60 = 70
bank.accrueYears(60);
age = bank.getAccountAge();
Assert.assertEquals(70, age);
}
}