Your Task
Your bank is tired of its mainframe COBOL accounting software and they hired both of you for a greenfield project in - what a happy coincidence
your favorite programming language!
Your task is to show them that your TDD-fu and your new-age programming language can cope with good ole’ COBOL!
Requirements
Write a class Account that offers the following methods void deposit(int) void withdraw(int) String printStatement()
An example statement would be:
Date Amount Balance
24.12.2015 +500 500
23.8.2016 -100 400
class Account { private int balance = 0; void deposit(int amount){ balance += amount; } void withdraw(int amount){ balance = 400; } String getStatement() { return "" + balance; //Integer.toString(balance); // } }
- class Account {
- private int balance = 0;
- void deposit(int amount){
- balance += amount;
- }
- void withdraw(int amount){
- balance = 400;
- }
- String getStatement() {
- return "" + balance; //Integer.toString(balance); //
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; // TODO: Replace examples and use TDD by writing your own tests class AccountTest { @Test void deposit_adds_money_to_initial_balance() { Account account = new Account(); account.deposit(100); String statement = account.getStatement(); assertTrue(statement.contains("100")); } @Test void deposit_adds_different_amount_of_money_to_initial_balance(){ Account account = new Account(); account.deposit(200); String statement = account.getStatement(); assertTrue(statement.contains("200")); } @Test void withdraw_of_zero_balance_remains_same(){ Account account = new Account(); account.withdraw(0); String statement = account.getStatement(); assertTrue(statement.contains("0")); } @Test void withdraw_reduces_balance_by_amount_withdrawn(){ Account account = new Account(); account.deposit(500); account.withdraw(100); String statement = account.getStatement(); assertTrue(statement.contains("400")); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import static org.junit.jupiter.api.Assertions.assertTrue;
- // TODO: Replace examples and use TDD by writing your own tests
- class AccountTest {
- @Test
- void deposit_adds_money_to_initial_balance() {
- Account account = new Account();
- account.deposit(100);
- String statement = account.getStatement();
- assertTrue(statement.contains("100"));
- }
- @Test
- void deposit_adds_different_amount_of_money_to_initial_balance(){
- Account account = new Account();
- account.deposit(200);
- String statement = account.getStatement();
- assertTrue(statement.contains("200"));
- }
- @Test
- void withdraw_of_zero_balance_remains_same(){
- Account account = new Account();
- account.withdraw(0);
- String statement = account.getStatement();
- assertTrue(statement.contains("0"));
- }
- @Test
- void withdraw_reduces_balance_by_amount_withdrawn(){
- Account account = new Account();
- account.deposit(500);
- account.withdraw(100);
- String statement = account.getStatement();
- assertTrue(statement.contains("400"));
- }
- }