Tech test provided on Week 10 of the Makers Course. Instructions for the projects can be found here. The aim of the project is to produce the best code that I can without a strict time limit.
git clone [email protected]:FayeCarter/bank_tech_test.git
cd bank_tech_test
bundle install
rspec
rubocop
Run IRB
irb
Once in IRB
require './lib/account'
account = Account.new
- You should be able to interact with your code via a REPL like IRB or the JavaScript console. (You don't need to implement a command line interface that takes input from STDIN.)
- Deposits, withdrawal.
- Account statement (date, amount, balance) printing.
- Data can be kept in memory (it doesn't need to be stored to a database or anything).
Given a client makes a deposit of 1000 on 10-01-2012
And a deposit of 2000 on 13-01-2012
And a withdrawal of 500 on 14-01-2012
When she prints her bank statement
Then she would see
date || credit || debit || balance
14/01/2012 || || 500.00 || 2500.00
13/01/2012 || 2000.00 || || 3000.00
10/01/2012 || 1000.00 || || 1000.00
To get a clearer understanding of the task I created user stories using the requirements and acceptance criteria.
As a customer,
So I can save my money,
I want to be able to deposit money into my account.
As a customer,
So that I can access my money,
I want to be able to withdraw money from my account
As a customer,
So that I can manage my account,
I want to be able to print a statement.
I then created a class diagram to get a clearer understanding the classes that could be used and their interactions
- Complete
As a customer,
So I can save my money,
I want to be able to deposit money into my account.
Steps taken:
- Account has initial balance
- Deposit adds to balance
- Deposit increases transaction history
- Deposit is a transaction
- transactions have date
- transactions can have credit
- transactions can have debit
- transactions can have balance
Approach
I created a repository and installed bundler and RSpec. I updated the Gemfile and the spec_helper to include SimpleCov to help me check my tests coverage. I also added Ruboocop so that I could ensure that my code was properly linted.
My first step was to create and Account class with an initial balance of 0. I initially accessed this by creating a method to display the balance. This was later removed as it became unnecessary.
I created a deposit method that would take a value and increase the account balance. When a deposit is made it is stored in the account transaction history.
I chose to refactor this logic into a transaction method that could handle deposits and withdrawals.
- Complete
As a customer,
So that I can access my money,
I want to be able to withdraw money from my account
Steps taken:
- Withdraw method created that reduces balance
- Withdraw creates a transaction
Approach
As I already had created a transaction class, I updated it to include an option for credit. If a deposit transaction was made, credit would be nil by default. If a withdrawal transaction was made, debit would be nil by default.
- Complete
As a customer,
So that I can manage my account,
I want to be able to print a statement.
Steps taken:
- Create Statement class with a header
- Transactions should be added to account in reverse chronological order
- Statement should take transaction history
Approach
I chose to update deposit and withdraw methods to add transaction to the beginning of the transaction array so the the statement would receive transactions in reverse chronological order.
I initially began to implement the statement to return a string of the statement. when I tested this in irb I noticed that didn't output correctly. I refactored this logic to allow the statement to print the string onto separate lines.