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
Added the optional. Attempted to add a "before" statement, but too ti…
…me-consuming. I have CSV'ing to do.
janicewilson committed Feb 22, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 44535b00df59370228d2f21f72c30cb22b54bfcf
34 changes: 29 additions & 5 deletions lib/account.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
module Bank

class Owner

attr_accessor :name, :phone

def initialize(hash)

@name = hash[:name]
@phone = hash[:phone]

end

end

class Account

attr_accessor :id, :balance, :start_balance
attr_accessor :id, :balance, :owner

def initialize(id, balance)
def initialize(id, balance, hash)

@id = id

@@ -16,7 +29,7 @@ def initialize(id, balance)

end

@start_balance
@owner = Bank::Owner.new(hash)

end

@@ -64,11 +77,22 @@ def deposit(deposit_amount)

end


# new_account = Bank::Account.new(133, 100)
# hash = {name: "Janice", phone: "303-349-1433"}
#
# owner_1 = Bank::Owner.new(hash)
#
# puts owner_1.name
#
# puts owner_1.phone
#
# new_account = Bank::Account.new(133, 100, hash)
#
# puts new_account.balance
#
# puts new_account.owner.name
#
# puts new_account.owner.phone
#
# expected_balance = new_account.withdraw(25)
#
# puts expected_balance
59 changes: 40 additions & 19 deletions specs/account_spec.rb
Original file line number Diff line number Diff line change
@@ -6,17 +6,25 @@
Minitest::Reporters.use!

describe "Wave 1" do
before do
@hash = {name: "Janice", phone: "303-349-1433"}
@id = 1337
@balance = 100.0
@account = Bank::Account.new(@id, @balance, @hash)
end
describe "Account#initialize" do
it "Takes an ID and an initial balance" do
id = 1337
balance = 100.0
account = Bank::Account.new(id, balance)
it "Takes an ID, an initial balance and account owner" do

account.must_respond_to :id
account.id.must_equal id
@account.must_respond_to :id
@account.id.must_equal @id

@account.must_respond_to :balance
@account.balance.must_equal @balance

@account.must_respond_to :owner
@account.owner.name.must_equal @hash[:name]
@account.owner.phone.must_equal @hash[:phone]

account.must_respond_to :balance
account.balance.must_equal balance
end

it "Raises an ArgumentError when created with a negative balance" do
@@ -25,21 +33,26 @@
# This code checks that, when the proc is executed, it
# raises an ArgumentError.
proc {
Bank::Account.new(1337, -100.0)
@hash
Bank::Account.new(@id, -100.0, @hash)
}.must_raise ArgumentError


end

it "Can be created with a balance of 0" do
# If this raises, the test will fail. No 'must's needed!
Bank::Account.new(1337, 0)
@hash
Bank::Account.new(@id, 0, @hash)
end
end

describe "Account#withdraw" do
it "Reduces the balance" do
hash = {name: "Janice", phone: "303-349-1433"}
start_balance = 100.0
withdrawal_amount = 25.0
account = Bank::Account.new(1337, start_balance)
account = Bank::Account.new(1337, start_balance, hash)

account.withdraw(withdrawal_amount)

@@ -48,9 +61,10 @@
end

it "Returns the modified balance" do
hash = {name: "Janice", phone: "303-349-1433"}
start_balance = 100.0
withdrawal_amount = 25.0
account = Bank::Account.new(1337, start_balance)
account = Bank::Account.new(1337, start_balance, hash)

updated_balance = account.withdraw(withdrawal_amount)

@@ -59,9 +73,10 @@
end

it "Outputs a warning if the account would go negative" do
hash = {name: "Janice", phone: "303-349-1433"}
start_balance = 100.0
withdrawal_amount = 200.0
account = Bank::Account.new(1337, start_balance)
account = Bank::Account.new(1337, start_balance, hash)

# Another proc! This test expects something to be printed
# to the terminal, using 'must_output'. /.+/ is a regular
@@ -73,9 +88,10 @@
end

it "Doesn't modify the balance if the account would go negative" do
hash = {name: "Janice", phone: "303-349-1433"}
start_balance = 100.0
withdrawal_amount = 200.0
account = Bank::Account.new(1337, start_balance)
account = Bank::Account.new(1337, start_balance, hash)

updated_balance = account.withdraw(withdrawal_amount)

@@ -86,16 +102,18 @@
end

it "Allows the balance to go to 0" do
account = Bank::Account.new(1337, 100.0)
hash = {name: "Janice", phone: "303-349-1433"}
account = Bank::Account.new(1337, 100.0, hash)
updated_balance = account.withdraw(account.balance)
updated_balance.must_equal 0
account.balance.must_equal 0
end

it "Requires a positive withdrawal amount" do
hash = {name: "Janice", phone: "303-349-1433"}
start_balance = 100.0
withdrawal_amount = -25.0
account = Bank::Account.new(1337, start_balance)
account = Bank::Account.new(1337, start_balance, hash)

proc {
account.withdraw(withdrawal_amount)
@@ -105,9 +123,10 @@

describe "Account#deposit" do
it "Increases the balance" do
hash = {name: "Janice", phone: "303-349-1433"}
start_balance = 100.0
deposit_amount = 25.0
account = Bank::Account.new(1337, start_balance)
account = Bank::Account.new(1337, start_balance, hash)

account.deposit(deposit_amount)

@@ -116,9 +135,10 @@
end

it "Returns the modified balance" do
hash = {name: "Janice", phone: "303-349-1433"}
start_balance = 100.0
deposit_amount = 25.0
account = Bank::Account.new(1337, start_balance)
account = Bank::Account.new(1337, start_balance, hash)

updated_balance = account.deposit(deposit_amount)

@@ -127,9 +147,10 @@
end

it "Requires a positive deposit amount" do
hash = {name: "Janice", phone: "303-349-1433"}
start_balance = 100.0
deposit_amount = -25.0
account = Bank::Account.new(1337, start_balance)
account = Bank::Account.new(1337, start_balance, hash)

proc {
account.deposit(deposit_amount)