Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Janice's Bank Accounts. At long last. #48

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6c66f0f
Account#initialize test passed.
janicewilson Feb 21, 2017
d352739
Raises an ArgumentError when created with a negative balance test pas…
janicewilson Feb 21, 2017
5164162
Can be created with a balance of 0 test passed.
janicewilson Feb 21, 2017
aa0734e
Account#withdraw test passed.
janicewilson Feb 21, 2017
6c6aa1c
"Returns the modified balance" and "Outputs a warning if the account …
janicewilson Feb 21, 2017
8b63bb6
"Allows the balance to go to 0" and "Requires a positive withdrawal a…
janicewilson Feb 22, 2017
b80a9c3
"Requires a positive withdrawal amount" test passes.
janicewilson Feb 22, 2017
78f2f94
"Increases the balance", "Returns the modified balance" and "Requires…
janicewilson Feb 22, 2017
44535b0
Added the optional. Attempted to add a "before" statement, but too ti…
janicewilson Feb 22, 2017
75faf68
Reboot re Wave 1. Committing without regrets.
janicewilson Feb 23, 2017
e3ffbb8
YAR (Yet Another Reboot.)
janicewilson Feb 23, 2017
3cc028d
All tests but the last have passed.
janicewilson Feb 24, 2017
85e624e
All tests but the last have passed.
janicewilson Feb 24, 2017
f69fa40
A fully sanitized Wave 2.
janicewilson Feb 24, 2017
f530f7b
Minitests for Savings Account \'initialize\' and \'withdraw\' success…
janicewilson Feb 24, 2017
16d4639
Added RB files for savings and checking account..
janicewilson Feb 24, 2017
fe911d4
Minitest /'add_interest/' passed for Saving Account.
janicewilson Feb 24, 2017
396ed54
Minitests re \'initialize\' and \'withdraw'\ updated.
janicewilson Feb 25, 2017
502cc28
Minitests re \'initialize\' and \'withdraw'\ updated.
janicewilson Feb 25, 2017
c26a9ed
All systems go. All mini-tests passed.
janicewilson Feb 25, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minitest /'add_interest/' passed for Saving Account.
janicewilson committed Feb 24, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit fe911d4b8d47067959e27c3297b7387e14ab806f
18 changes: 14 additions & 4 deletions lib/savings_account.rb
Original file line number Diff line number Diff line change
@@ -30,20 +30,30 @@ def withdraw(withdrawal_amount)

end

def add_interest(rate)

raise ArgumentError.new "Please enter an interest rate greater than 0.00." unless rate > 0.00

start_balance = @balance
@balance *= 1 + (rate/100)
interest_earned = start_balance * (rate/100)

end


end

end


#Updated withdrawal functionality:
#Each withdrawal 'transaction' incurs a fee of $2 that is taken out of the balance.
#Does not allow the account to go below the $10 minimum balance - Will output a warning #message and return the original un-modified balance
#It should include the following new method:

#add_interest(rate): Calculate the interest on the balance and add the interest to the balance. Return the interest that was calculated and added to the balance (not the updated balance).
#Input rate is assumed to be a percentage (i.e. 0.25).
#The formula for calculating interest is balance * rate/100
#Example: If the interest rate is 0.25 and the balance is $10,000, then the interest that is returned is $25 and the new balance becomes $10,025.

# janice = Bank::SavingsAccount.new(333, 60)
# janice = Bank::SavingsAccount.new(333, 10)
#
# puts janice.add_interest(0.25)
# puts janice.balance
69 changes: 41 additions & 28 deletions specs/savings_account_spec.rb
Original file line number Diff line number Diff line change
@@ -27,36 +27,24 @@

it "Requires an initial balance of at least $10" do

proc {
Bank::SavingsAccount.new(1337, -100.0)
}.must_raise ArgumentError
proc {Bank::SavingsAccount.new(1337, -100.0)}.must_raise ArgumentError

proc {
Bank::SavingsAccount.new(1337, -0.0)
}.must_raise ArgumentError
proc {Bank::SavingsAccount.new(1337, -0.0)}.must_raise ArgumentError

proc {
Bank::SavingsAccount.new(1337, 9.0)
}.must_raise ArgumentError
proc {Bank::SavingsAccount.new(1337, 9.0)}.must_raise ArgumentError

end
end

describe "#withdraw" do

# it "Applies a $2 fee each time" do
# # TODO: Your test code here!
# end

it "Outputs a warning if the balance would go below $10" do

start_balance = 50.0
withdrawal_amount = 48.0
account = Bank::SavingsAccount.new(1337, start_balance)

proc {
account.withdraw(withdrawal_amount)
}.must_output /.+/
proc {account.withdraw(withdrawal_amount)}.must_output /.+/

end

@@ -83,7 +71,7 @@
end


it "Doesn't modify the balance if it would go below $10 due to the $2 fee" do
it "Doesn't modify the balance if it would go below $10 due to the $2 fee" do

start_balance = 11
withdrawal_amount = 1
@@ -92,22 +80,47 @@
updated_balance = account.withdraw(withdrawal_amount)
updated_balance.must_equal start_balance
account.balance.must_equal start_balance
end

end


end

#describe "#add_interest" do
it "Returns the interest calculated" do
# TODO: Your test code here!
end
describe "#add_interest" do

it "Returns the interest calculated" do

start_balance = 10000
rate = 0.25
account = Bank::SavingsAccount.new(1337, start_balance)
calculated_interest = start_balance * (rate/100)

calculated_interest.must_equal account.add_interest(rate)

end

it "Updates the balance with calculated interest" do

it "Updates the balance with calculated interest" do
# TODO: Your test code here!
end
start_balance = 12000
rate = 0.13
account = Bank::SavingsAccount.new(1337, start_balance)
account.add_interest(rate)
new_balance = start_balance * (1 + (rate/100))

it "Requires a positive rate" do
# TODO: Your test code here!
end
new_balance.must_equal account.balance

end

it "Requires a positive rate" do

start_balance = 12000
rate = -0.1
account = Bank::SavingsAccount.new(1337, start_balance)

proc {account.add_interest(rate)}.must_raise ArgumentError

end

end

end