From 4c6f7db731d995ee774f72885b11549651a024b1 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Tue, 21 Feb 2017 15:05:32 -0800 Subject: [PATCH 01/26] Started Bank module --- lib/account.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/account.rb b/lib/account.rb index e69de29b..8a35e6b3 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -0,0 +1,15 @@ +module Bank + class Account + + def initialize(id, balance) + @id = id + @balance = 0 + end + + def withdraw + end + + def deposit + end + end +end From c7f1bea314cc0b99c2c4872118422e1ea88fcde2 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Tue, 21 Feb 2017 16:29:01 -0800 Subject: [PATCH 02/26] Passing withdrawal tests --- lib/account.rb | 16 +++- specs/account_spec.rb | 196 +++++++++++++++++++++--------------------- 2 files changed, 110 insertions(+), 102 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 8a35e6b3..6ca9de4d 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,15 +1,23 @@ module Bank class Account - + attr_reader :id, :balance def initialize(id, balance) @id = id - @balance = 0 + @balance = balance + if @balance < 0 + raise ArgumentError.new "The starting balance cannot be negative" + end end - def withdraw + def withdraw(withdrawal_amount) + @balance -= withdrawal_amount + if @balance < 0 + puts "Warning, the balance cannot be negative" + end + return @balance end def deposit - end + end end end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 6c399139..8a9ddfe4 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -4,6 +4,7 @@ require_relative '../lib/account' describe "Wave 1" do + describe "Account#initialize" do it "Takes an ID and an initial balance" do id = 1337 @@ -51,7 +52,6 @@ account = Bank::Account.new(1337, start_balance) updated_balance = account.withdraw(withdrawal_amount) - expected_balance = start_balance - withdrawal_amount updated_balance.must_equal expected_balance end @@ -70,102 +70,102 @@ }.must_output /.+/ end - it "Doesn't modify the balance if the account would go negative" do - start_balance = 100.0 - withdrawal_amount = 200.0 - account = Bank::Account.new(1337, start_balance) - - updated_balance = account.withdraw(withdrawal_amount) - - # Both the value returned and the balance in the account - # must be un-modified. - updated_balance.must_equal start_balance - account.balance.must_equal start_balance - end - - it "Allows the balance to go to 0" do - account = Bank::Account.new(1337, 100.0) - updated_balance = account.withdraw(account.balance) - updated_balance.must_equal 0 - account.balance.must_equal 0 - end - - it "Requires a positive withdrawal amount" do - start_balance = 100.0 - withdrawal_amount = -25.0 - account = Bank::Account.new(1337, start_balance) - - proc { - account.withdraw(withdrawal_amount) - }.must_raise ArgumentError - end - end - - describe "Account#deposit" do - it "Increases the balance" do - start_balance = 100.0 - deposit_amount = 25.0 - account = Bank::Account.new(1337, start_balance) - - account.deposit(deposit_amount) - - expected_balance = start_balance + deposit_amount - account.balance.must_equal expected_balance - end - - it "Returns the modified balance" do - start_balance = 100.0 - deposit_amount = 25.0 - account = Bank::Account.new(1337, start_balance) - - updated_balance = account.deposit(deposit_amount) - - expected_balance = start_balance + deposit_amount - updated_balance.must_equal expected_balance - end - - it "Requires a positive deposit amount" do - start_balance = 100.0 - deposit_amount = -25.0 - account = Bank::Account.new(1337, start_balance) - - proc { - account.deposit(deposit_amount) - }.must_raise ArgumentError - end - end -end - -# TODO: change 'xdescribe' to 'describe' to run these tests -xdescribe "Wave 2" do - describe "Account.all" do - it "Returns an array of all accounts" do - # TODO: Your test code here! - # Useful checks might include: - # - Account.all returns an array - # - Everything in the array is an Account - # - The number of accounts is correct - # - The ID and balance of the first and last - # accounts match what's in the CSV file - # Feel free to split this into multiple tests if needed - end - end - - describe "Account.find" do - it "Returns an account that exists" do - # TODO: Your test code here! - end - - it "Can find the first account from the CSV" do - # TODO: Your test code here! - end - - it "Can find the last account from the CSV" do - # TODO: Your test code here! - end - - it "Raises an error for an account that doesn't exist" do - # TODO: Your test code here! + # it "Doesn't modify the balance if the account would go negative" do + # start_balance = 100.0 + # withdrawal_amount = 200.0 + # account = Bank::Account.new(1337, start_balance) + # + # updated_balance = account.withdraw(withdrawal_amount) + # + # # Both the value returned and the balance in the account + # # must be un-modified. + # updated_balance.must_equal start_balance + # account.balance.must_equal start_balance + # end + # + # it "Allows the balance to go to 0" do + # account = Bank::Account.new(1337, 100.0) + # updated_balance = account.withdraw(account.balance) + # updated_balance.must_equal 0 + # account.balance.must_equal 0 + # end + # + # it "Requires a positive withdrawal amount" do + # start_balance = 100.0 + # withdrawal_amount = -25.0 + # account = Bank::Account.new(1337, start_balance) + # + # proc { + # account.withdraw(withdrawal_amount) + # }.must_raise ArgumentError + # end + # end + # + # describe "Account#deposit" do + # it "Increases the balance" do + # start_balance = 100.0 + # deposit_amount = 25.0 + # account = Bank::Account.new(1337, start_balance) + # + # account.deposit(deposit_amount) + # + # expected_balance = start_balance + deposit_amount + # account.balance.must_equal expected_balance + # end + # + # it "Returns the modified balance" do + # start_balance = 100.0 + # deposit_amount = 25.0 + # account = Bank::Account.new(1337, start_balance) + # + # updated_balance = account.deposit(deposit_amount) + # + # expected_balance = start_balance + deposit_amount + # updated_balance.must_equal expected_balance + # end + # + # it "Requires a positive deposit amount" do + # start_balance = 100.0 + # deposit_amount = -25.0 + # account = Bank::Account.new(1337, start_balance) + # + # proc { + # account.deposit(deposit_amount) + # }.must_raise ArgumentError + # end +# end +# end + +# # TODO: change 'xdescribe' to 'describe' to run these tests +# xdescribe "Wave 2" do +# describe "Account.all" do +# it "Returns an array of all accounts" do +# # TODO: Your test code here! +# # Useful checks might include: +# # - Account.all returns an array +# # - Everything in the array is an Account +# # - The number of accounts is correct +# # - The ID and balance of the first and last +# # accounts match what's in the CSV file +# # Feel free to split this into multiple tests if needed +# end +# end +# +# describe "Account.find" do +# it "Returns an account that exists" do +# # TODO: Your test code here! +# end +# +# it "Can find the first account from the CSV" do +# # TODO: Your test code here! +# end +# +# it "Can find the last account from the CSV" do +# # TODO: Your test code here! +# end +# +# it "Raises an error for an account that doesn't exist" do +# # TODO: Your test code here! end end -end +# end From fc876097c61730c721e602d91701a46deacffe64 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Tue, 21 Feb 2017 17:10:00 -0800 Subject: [PATCH 03/26] need to add withdrawal --- lib/account.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 6ca9de4d..c0a15620 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -10,11 +10,14 @@ def initialize(id, balance) end def withdraw(withdrawal_amount) - @balance -= withdrawal_amount - if @balance < 0 + if withdrawal_amount > @balance puts "Warning, the balance cannot be negative" + @balance = @balance + elsif withdrawal_amount < 0 + raise ArgumentError.new "You cannot withdraw a negative amount" + else + @balance -= withdrawal_amount end - return @balance end def deposit From ff716757bceb1b793f99d6a5f8f99225965a9256 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Tue, 21 Feb 2017 17:26:44 -0800 Subject: [PATCH 04/26] Wave 1 done --- lib/account.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index c0a15620..87f5b8e5 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -20,7 +20,12 @@ def withdraw(withdrawal_amount) end end - def deposit + def deposit(deposit_amount) + if deposit_amount < 0 + raise ArgumentError.new "The deposit must be greater than 0" + else + @balance += deposit_amount + end end end end From d7ba438fdf90143d93b96625605df93ce133c145 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Wed, 22 Feb 2017 16:10:12 -0800 Subject: [PATCH 05/26] Added self.all class, starting to write tests --- lib/account.rb | 33 +++++++- specs/account_spec.rb | 170 +++++++++++++++++++++--------------------- 2 files changed, 119 insertions(+), 84 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 87f5b8e5..5c83f441 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,7 +1,24 @@ +require 'csv' module Bank + + class Account + + def self.all + account = [] + CSV.open("support/accounts.csv", "r").each do |account| + id = account[0] + balance = Integer(account[1]) + open_date = account[2] + new_account = Account.new(id, balance, open_date) + account << new_account + end + return account + + end + attr_reader :id, :balance - def initialize(id, balance) + def initialize(id, balance, open_date = nil) @id = id @balance = balance if @balance < 0 @@ -9,6 +26,8 @@ def initialize(id, balance) end end + + def withdraw(withdrawal_amount) if withdrawal_amount > @balance puts "Warning, the balance cannot be negative" @@ -21,11 +40,23 @@ def withdraw(withdrawal_amount) end def deposit(deposit_amount) + #raise ArgumentError.new("amount must be >= 0") if amount < 0 if deposit_amount < 0 raise ArgumentError.new "The deposit must be greater than 0" + else @balance += deposit_amount end end end end +# def withdraw(amount) +# raise ArgumentError.new("amount must be >= 0") if amount < 0 +# +# if @balance - amount < 0 +# puts "Oh no! Account will be negative" +# return @balance +# else +# @balance -= amount +# end +# end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 8a9ddfe4..102bc6bb 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -70,87 +70,91 @@ }.must_output /.+/ end - # it "Doesn't modify the balance if the account would go negative" do - # start_balance = 100.0 - # withdrawal_amount = 200.0 - # account = Bank::Account.new(1337, start_balance) - # - # updated_balance = account.withdraw(withdrawal_amount) - # - # # Both the value returned and the balance in the account - # # must be un-modified. - # updated_balance.must_equal start_balance - # account.balance.must_equal start_balance - # end - # - # it "Allows the balance to go to 0" do - # account = Bank::Account.new(1337, 100.0) - # updated_balance = account.withdraw(account.balance) - # updated_balance.must_equal 0 - # account.balance.must_equal 0 - # end - # - # it "Requires a positive withdrawal amount" do - # start_balance = 100.0 - # withdrawal_amount = -25.0 - # account = Bank::Account.new(1337, start_balance) - # - # proc { - # account.withdraw(withdrawal_amount) - # }.must_raise ArgumentError - # end - # end - # - # describe "Account#deposit" do - # it "Increases the balance" do - # start_balance = 100.0 - # deposit_amount = 25.0 - # account = Bank::Account.new(1337, start_balance) - # - # account.deposit(deposit_amount) - # - # expected_balance = start_balance + deposit_amount - # account.balance.must_equal expected_balance - # end - # - # it "Returns the modified balance" do - # start_balance = 100.0 - # deposit_amount = 25.0 - # account = Bank::Account.new(1337, start_balance) - # - # updated_balance = account.deposit(deposit_amount) - # - # expected_balance = start_balance + deposit_amount - # updated_balance.must_equal expected_balance - # end - # - # it "Requires a positive deposit amount" do - # start_balance = 100.0 - # deposit_amount = -25.0 - # account = Bank::Account.new(1337, start_balance) - # - # proc { - # account.deposit(deposit_amount) - # }.must_raise ArgumentError - # end -# end -# end + it "Doesn't modify the balance if the account would go negative" do + start_balance = 100.0 + withdrawal_amount = 200.0 + account = Bank::Account.new(1337, start_balance) + + updated_balance = account.withdraw(withdrawal_amount) + + # Both the value returned and the balance in the account + # must be un-modified. + updated_balance.must_equal start_balance + account.balance.must_equal start_balance + end + + it "Allows the balance to go to 0" do + account = Bank::Account.new(1337, 100.0) + updated_balance = account.withdraw(account.balance) + updated_balance.must_equal 0 + account.balance.must_equal 0 + end + + it "Requires a positive withdrawal amount" do + start_balance = 100.0 + withdrawal_amount = -25.0 + account = Bank::Account.new(1337, start_balance) + + proc { + account.withdraw(withdrawal_amount) + }.must_raise ArgumentError + end + end + + describe "Account#deposit" do + it "Increases the balance" do + start_balance = 100.0 + deposit_amount = 25.0 + account = Bank::Account.new(1337, start_balance) + + account.deposit(deposit_amount) + + expected_balance = start_balance + deposit_amount + account.balance.must_equal expected_balance + end + + it "Returns the modified balance" do + start_balance = 100.0 + deposit_amount = 25.0 + account = Bank::Account.new(1337, start_balance) + + updated_balance = account.deposit(deposit_amount) + + expected_balance = start_balance + deposit_amount + updated_balance.must_equal expected_balance + end + + it "Requires a positive deposit amount" do + start_balance = 100.0 + deposit_amount = -25.0 + account = Bank::Account.new(1337, start_balance) + + proc { + account.deposit(deposit_amount) + }.must_raise ArgumentError + end + end +end + +# TODO: change 'xdescribe' to 'describe' to run these tests +describe "Wave 2" do + describe "Account.all" do + it "Returns an array of all accounts" do + # TODO: Your test code here! + account = Bank::Account.all + account.class.must_equal Array + class.must_equal Array + + # Useful checks might include: + # - Account.all returns an array + # - Everything in the array is an Account + # - The number of accounts is correct + # - The ID and balance of the first and last + # accounts match what's in the CSV file + # Feel free to split this into multiple tests if needed + end + end -# # TODO: change 'xdescribe' to 'describe' to run these tests -# xdescribe "Wave 2" do -# describe "Account.all" do -# it "Returns an array of all accounts" do -# # TODO: Your test code here! -# # Useful checks might include: -# # - Account.all returns an array -# # - Everything in the array is an Account -# # - The number of accounts is correct -# # - The ID and balance of the first and last -# # accounts match what's in the CSV file -# # Feel free to split this into multiple tests if needed -# end -# end -# # describe "Account.find" do # it "Returns an account that exists" do # # TODO: Your test code here! @@ -166,6 +170,6 @@ # # it "Raises an error for an account that doesn't exist" do # # TODO: Your test code here! - end - end -# end + # end + # end +end From 5803629885a458d7db6c74c2f7674598e761f73d Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Wed, 22 Feb 2017 17:05:17 -0800 Subject: [PATCH 06/26] Starting tests, wrote find.all method --- lib/account.rb | 13 ++++++++++++- specs/account_spec.rb | 9 +++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 5c83f441..8cd2f5bd 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -7,7 +7,7 @@ class Account def self.all account = [] CSV.open("support/accounts.csv", "r").each do |account| - id = account[0] + id = Integer(account[0]) balance = Integer(account[1]) open_date = account[2] new_account = Account.new(id, balance, open_date) @@ -17,10 +17,21 @@ def self.all end + def self.find(id) + Account.all.each do |account| + if account.id == id + return account + else + puts "That acct DNE" + end + end + end + attr_reader :id, :balance def initialize(id, balance, open_date = nil) @id = id @balance = balance + @open_date = open_date if @balance < 0 raise ArgumentError.new "The starting balance cannot be negative" end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 102bc6bb..c8ffd73b 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -142,14 +142,15 @@ it "Returns an array of all accounts" do # TODO: Your test code here! account = Bank::Account.all - account.class.must_equal Array - class.must_equal Array + # account.class.must_equal Array + account.must_be_instance_of Array +#loop through array to retrieve instance of bank account put assertion that account is instance # Useful checks might include: # - Account.all returns an array # - Everything in the array is an Account - # - The number of accounts is correct - # - The ID and balance of the first and last + # - The number of accounts is correct account.length = 12 + # - The ID and balance of the first and last ...pull out indexes, id must be equal to # accounts match what's in the CSV file # Feel free to split this into multiple tests if needed end From b28a680efedd2434536126679019dada12332b64 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Wed, 22 Feb 2017 18:55:07 -0800 Subject: [PATCH 07/26] Added more tests in .all method --- specs/account_spec.rb | 63 +++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index c8ffd73b..1d54f51c 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -140,37 +140,42 @@ describe "Wave 2" do describe "Account.all" do it "Returns an array of all accounts" do - # TODO: Your test code here! - account = Bank::Account.all + + account = Bank::Account.all # account.class.must_equal Array - account.must_be_instance_of Array -#loop through array to retrieve instance of bank account put assertion that account is instance + # Account.all returns an array + account.must_be_instance_of Array + + #loop through array to retrieve instance of bank account put assertion that account is instance - # Useful checks might include: - # - Account.all returns an array # - Everything in the array is an Account - # - The number of accounts is correct account.length = 12 - # - The ID and balance of the first and last ...pull out indexes, id must be equal to - # accounts match what's in the CSV file - # Feel free to split this into multiple tests if needed - end + account.each do |element| + element.must_be_instance_of Bank::Account + end + # - The number of accounts is correct account.length = 12 + + # - The ID and balance of the first and last ...pull out indexes, id must be equal to + # accounts match what's in the CSV file + # Feel free to split this into multiple tests if needed + # end + + # describe "Account.find" do + # it "Returns an account that exists" do + # # TODO: Your test code here! + # end + # + # it "Can find the first account from the CSV" do + # # TODO: Your test code here! + # end + # + # it "Can find the last account from the CSV" do + # # TODO: Your test code here! + # end + # + # it "Raises an error for an account that doesn't exist" do + # # TODO: Your test code here! + # end + # end end - -# describe "Account.find" do -# it "Returns an account that exists" do -# # TODO: Your test code here! -# end -# -# it "Can find the first account from the CSV" do -# # TODO: Your test code here! -# end -# -# it "Can find the last account from the CSV" do -# # TODO: Your test code here! -# end -# -# it "Raises an error for an account that doesn't exist" do -# # TODO: Your test code here! - # end - # end end +end From a57d631fe5fa525209ebbcef1b2fadeda5f6e0d8 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Wed, 22 Feb 2017 19:22:40 -0800 Subject: [PATCH 08/26] more tests added --- lib/account.rb | 12 +++++++---- specs/account_spec.rb | 50 +++++++++++++++++++++---------------------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 8cd2f5bd..6e0555a4 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -6,14 +6,16 @@ class Account def self.all account = [] - CSV.open("support/accounts.csv", "r").each do |account| - id = Integer(account[0]) - balance = Integer(account[1]) - open_date = account[2] + CSV.open("/Users/habsr/ada/projects/BankAccounts/support/accounts.csv", "r").each do |file| + id = Integer(file[0]) + balance = Integer(file[1]) + open_date = file[2] new_account = Account.new(id, balance, open_date) account << new_account + puts account end return account + # puts account end @@ -61,6 +63,8 @@ def deposit(deposit_amount) end end end + +puts Bank::Account.all # def withdraw(amount) # raise ArgumentError.new("amount must be >= 0") if amount < 0 # diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 1d54f51c..56728f1c 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -152,30 +152,30 @@ account.each do |element| element.must_be_instance_of Bank::Account end - # - The number of accounts is correct account.length = 12 - - # - The ID and balance of the first and last ...pull out indexes, id must be equal to - # accounts match what's in the CSV file - # Feel free to split this into multiple tests if needed - # end - - # describe "Account.find" do - # it "Returns an account that exists" do - # # TODO: Your test code here! - # end - # - # it "Can find the first account from the CSV" do - # # TODO: Your test code here! - # end - # - # it "Can find the last account from the CSV" do - # # TODO: Your test code here! - # end - # - # it "Raises an error for an account that doesn't exist" do - # # TODO: Your test code here! - # end - # end + # - The number of accounts is correct account.length = 12 + account.length.must_equal 12 + # - The ID and balance of the first and last ...pull out indexes, id must be equal to + # accounts match what's in the CSV file + # Feel free to split this into multiple tests if needed + # end + + # describe "Account.find" do + # it "Returns an account that exists" do + # # TODO: Your test code here! + # end + # + # it "Can find the first account from the CSV" do + # # TODO: Your test code here! + # end + # + # it "Can find the last account from the CSV" do + # # TODO: Your test code here! + # end + # + # it "Raises an error for an account that doesn't exist" do + # # TODO: Your test code here! + # end + # end + end end end -end From c9eca1b610f1409fc606f8b2016b5bca35e683f5 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Wed, 22 Feb 2017 19:30:42 -0800 Subject: [PATCH 09/26] Finished round 1 tests. Moving on to Find.all tests --- lib/account.rb | 2 +- specs/account_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index 6e0555a4..79af9b44 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -64,7 +64,7 @@ def deposit(deposit_amount) end end -puts Bank::Account.all +# puts Bank::Account.all # def withdraw(amount) # raise ArgumentError.new("amount must be >= 0") if amount < 0 # diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 56728f1c..cf43f99f 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -156,6 +156,10 @@ account.length.must_equal 12 # - The ID and balance of the first and last ...pull out indexes, id must be equal to # accounts match what's in the CSV file + account[0].id.must_equal 1212 + account[-1].id.must_equal 15156 + account[0].balance.must_equal 1235667 + account[-1].balance.must_equal 4356772 # Feel free to split this into multiple tests if needed # end From e210de6b17edb4f9663e4e605dbdb446c991c338 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Wed, 22 Feb 2017 20:17:16 -0800 Subject: [PATCH 10/26] Passed first find test --- lib/account.rb | 4 ++-- specs/account_spec.rb | 39 ++++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 79af9b44..0fb73d4b 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -12,7 +12,7 @@ def self.all open_date = file[2] new_account = Account.new(id, balance, open_date) account << new_account - puts account + # puts account end return account # puts account @@ -24,7 +24,7 @@ def self.find(id) if account.id == id return account else - puts "That acct DNE" + puts "That account Does Not Exist" end end end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index cf43f99f..18a7bda3 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -163,23 +163,28 @@ # Feel free to split this into multiple tests if needed # end - # describe "Account.find" do - # it "Returns an account that exists" do - # # TODO: Your test code here! - # end - # - # it "Can find the first account from the CSV" do - # # TODO: Your test code here! - # end - # - # it "Can find the last account from the CSV" do - # # TODO: Your test code here! - # end - # - # it "Raises an error for an account that doesn't exist" do - # # TODO: Your test code here! - # end - # end + describe "Account.find" do + it "Returns an account that exists" do + # TODO: Your test code here! + accounts = Bank::Account.all + account = Bank::Account.find(1212) + account.id.must_equal accounts[0].id + end + + it "Can find the first account from the CSV" do + # TODO: Your test code here! + + end + + # it "Can find the last account from the CSV" do + # # TODO: Your test code here! + # end + # + # it "Raises an error for an account that doesn't exist" do + # # TODO: Your test code here! + # end + # end + end end end end From 365102383129cafd8e970965098e14da5f14e6fc Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Wed, 22 Feb 2017 21:22:30 -0800 Subject: [PATCH 11/26] Wave 2 primary done --- lib/account.rb | 4 +- specs/account_spec.rb | 307 +++++++++++++++++++++--------------------- 2 files changed, 158 insertions(+), 153 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 0fb73d4b..f71cfe9b 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -23,10 +23,10 @@ def self.find(id) Account.all.each do |account| if account.id == id return account - else - puts "That account Does Not Exist" end + end + puts "That account Does Not Exist" end attr_reader :id, :balance diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 18a7bda3..167950a5 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -3,138 +3,138 @@ require 'minitest/skip_dsl' require_relative '../lib/account' -describe "Wave 1" do - - describe "Account#initialize" do - it "Takes an ID and an initial balance" do - id = 1337 - balance = 100.0 - account = Bank::Account.new(id, balance) - - account.must_respond_to :id - account.id.must_equal id - - account.must_respond_to :balance - account.balance.must_equal balance - end - - it "Raises an ArgumentError when created with a negative balance" do - # Note: we haven't talked about procs yet. You can think - # of them like blocks that sit by themselves. - # This code checks that, when the proc is executed, it - # raises an ArgumentError. - proc { - Bank::Account.new(1337, -100.0) - }.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) - end - end - - describe "Account#withdraw" do - it "Reduces the balance" do - start_balance = 100.0 - withdrawal_amount = 25.0 - account = Bank::Account.new(1337, start_balance) - - account.withdraw(withdrawal_amount) - - expected_balance = start_balance - withdrawal_amount - account.balance.must_equal expected_balance - end - - it "Returns the modified balance" do - start_balance = 100.0 - withdrawal_amount = 25.0 - account = Bank::Account.new(1337, start_balance) - - updated_balance = account.withdraw(withdrawal_amount) - expected_balance = start_balance - withdrawal_amount - updated_balance.must_equal expected_balance - end - - it "Outputs a warning if the account would go negative" do - start_balance = 100.0 - withdrawal_amount = 200.0 - account = Bank::Account.new(1337, start_balance) - - # Another proc! This test expects something to be printed - # to the terminal, using 'must_output'. /.+/ is a regular - # expression matching one or more characters - as long as - # anything at all is printed out the test will pass. - proc { - account.withdraw(withdrawal_amount) - }.must_output /.+/ - end - - it "Doesn't modify the balance if the account would go negative" do - start_balance = 100.0 - withdrawal_amount = 200.0 - account = Bank::Account.new(1337, start_balance) - - updated_balance = account.withdraw(withdrawal_amount) - - # Both the value returned and the balance in the account - # must be un-modified. - updated_balance.must_equal start_balance - account.balance.must_equal start_balance - end - - it "Allows the balance to go to 0" do - account = Bank::Account.new(1337, 100.0) - updated_balance = account.withdraw(account.balance) - updated_balance.must_equal 0 - account.balance.must_equal 0 - end - - it "Requires a positive withdrawal amount" do - start_balance = 100.0 - withdrawal_amount = -25.0 - account = Bank::Account.new(1337, start_balance) - - proc { - account.withdraw(withdrawal_amount) - }.must_raise ArgumentError - end - end - - describe "Account#deposit" do - it "Increases the balance" do - start_balance = 100.0 - deposit_amount = 25.0 - account = Bank::Account.new(1337, start_balance) - - account.deposit(deposit_amount) - - expected_balance = start_balance + deposit_amount - account.balance.must_equal expected_balance - end - - it "Returns the modified balance" do - start_balance = 100.0 - deposit_amount = 25.0 - account = Bank::Account.new(1337, start_balance) - - updated_balance = account.deposit(deposit_amount) - - expected_balance = start_balance + deposit_amount - updated_balance.must_equal expected_balance - end - - it "Requires a positive deposit amount" do - start_balance = 100.0 - deposit_amount = -25.0 - account = Bank::Account.new(1337, start_balance) - - proc { - account.deposit(deposit_amount) - }.must_raise ArgumentError - end - end -end +# describe "Wave 1" do +# +# describe "Account#initialize" do +# it "Takes an ID and an initial balance" do +# id = 1337 +# balance = 100.0 +# account = Bank::Account.new(id, balance) +# +# account.must_respond_to :id +# account.id.must_equal id +# +# account.must_respond_to :balance +# account.balance.must_equal balance +# end +# +# it "Raises an ArgumentError when created with a negative balance" do +# # Note: we haven't talked about procs yet. You can think +# # of them like blocks that sit by themselves. +# # This code checks that, when the proc is executed, it +# # raises an ArgumentError. +# proc { +# Bank::Account.new(1337, -100.0) +# }.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) +# end +# end +# +# describe "Account#withdraw" do +# it "Reduces the balance" do +# start_balance = 100.0 +# withdrawal_amount = 25.0 +# account = Bank::Account.new(1337, start_balance) +# +# account.withdraw(withdrawal_amount) +# +# expected_balance = start_balance - withdrawal_amount +# account.balance.must_equal expected_balance +# end +# +# it "Returns the modified balance" do +# start_balance = 100.0 +# withdrawal_amount = 25.0 +# account = Bank::Account.new(1337, start_balance) +# +# updated_balance = account.withdraw(withdrawal_amount) +# expected_balance = start_balance - withdrawal_amount +# updated_balance.must_equal expected_balance +# end +# +# it "Outputs a warning if the account would go negative" do +# start_balance = 100.0 +# withdrawal_amount = 200.0 +# account = Bank::Account.new(1337, start_balance) +# +# # Another proc! This test expects something to be printed +# # to the terminal, using 'must_output'. /.+/ is a regular +# # expression matching one or more characters - as long as +# # anything at all is printed out the test will pass. +# proc { +# account.withdraw(withdrawal_amount) +# }.must_output /.+/ +# end +# +# it "Doesn't modify the balance if the account would go negative" do +# start_balance = 100.0 +# withdrawal_amount = 200.0 +# account = Bank::Account.new(1337, start_balance) +# +# updated_balance = account.withdraw(withdrawal_amount) +# +# # Both the value returned and the balance in the account +# # must be un-modified. +# updated_balance.must_equal start_balance +# account.balance.must_equal start_balance +# end +# +# it "Allows the balance to go to 0" do +# account = Bank::Account.new(1337, 100.0) +# updated_balance = account.withdraw(account.balance) +# updated_balance.must_equal 0 +# account.balance.must_equal 0 +# end +# +# it "Requires a positive withdrawal amount" do +# start_balance = 100.0 +# withdrawal_amount = -25.0 +# account = Bank::Account.new(1337, start_balance) +# +# proc { +# account.withdraw(withdrawal_amount) +# }.must_raise ArgumentError +# end +# end +# +# describe "Account#deposit" do +# it "Increases the balance" do +# start_balance = 100.0 +# deposit_amount = 25.0 +# account = Bank::Account.new(1337, start_balance) +# +# account.deposit(deposit_amount) +# +# expected_balance = start_balance + deposit_amount +# account.balance.must_equal expected_balance +# end +# +# it "Returns the modified balance" do +# start_balance = 100.0 +# deposit_amount = 25.0 +# account = Bank::Account.new(1337, start_balance) +# +# updated_balance = account.deposit(deposit_amount) +# +# expected_balance = start_balance + deposit_amount +# updated_balance.must_equal expected_balance +# end +# +# it "Requires a positive deposit amount" do +# start_balance = 100.0 +# deposit_amount = -25.0 +# account = Bank::Account.new(1337, start_balance) +# +# proc { +# account.deposit(deposit_amount) +# }.must_raise ArgumentError +# end +# end +# end # TODO: change 'xdescribe' to 'describe' to run these tests describe "Wave 2" do @@ -161,29 +161,34 @@ account[0].balance.must_equal 1235667 account[-1].balance.must_equal 4356772 # Feel free to split this into multiple tests if needed - # end + end - describe "Account.find" do - it "Returns an account that exists" do - # TODO: Your test code here! - accounts = Bank::Account.all - account = Bank::Account.find(1212) - account.id.must_equal accounts[0].id - end + describe "Account.find" do + it "Returns an account that exists" do + # TODO: Your test code here! + account = Bank::Account.find(1212) + account.must_be_instance_of Bank::Account + end - it "Can find the first account from the CSV" do - # TODO: Your test code here! + it "Can find the first account from the CSV" do + # TODO: Your test code here! + accounts = Bank::Account.all + account = Bank::Account.find(1212) + account.id.must_equal accounts[0].id + end - end + it "Can find the last account from the CSV" do + # TODO: Your test code here! + accounts = Bank::Account.all + account = Bank::Account.find(15156) + account.id.must_equal accounts[-1].id + end - # it "Can find the last account from the CSV" do - # # TODO: Your test code here! - # end - # - # it "Raises an error for an account that doesn't exist" do - # # TODO: Your test code here! - # end - # end + it "Raises an error for an account that doesn't exist" do + # TODO: Your test code here! + proc { + Bank::Account.find(111111) + }.must_output /.+/ end end end From fbd92771b9f58f8320a563832e20736b0375c761 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Thu, 23 Feb 2017 20:04:03 -0800 Subject: [PATCH 12/26] Fixed errors I was having with Wave 2 and adding inheritance to checking account --- .DS_Store | Bin 0 -> 6148 bytes lib/account.rb | 6 +- lib/checking_account.rb | 28 ++++ lib/owner.rb | 10 ++ lib/savings_account.rb | 0 specs/account_spec.rb | 270 +++++++++++++++++---------------- specs/checking_account_spec.rb | 30 +++- support/.DS_Store | Bin 0 -> 6148 bytes 8 files changed, 205 insertions(+), 139 deletions(-) create mode 100644 .DS_Store create mode 100644 lib/checking_account.rb create mode 100644 lib/owner.rb create mode 100644 lib/savings_account.rb create mode 100644 support/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..4ad951ed05884cbd7cdfd3cfde963da717735926 GIT binary patch literal 6148 zcmeHKI|>3p3{6x}u(7n9D|mxJ^aNhOLa-4PfAv4~1Rnu_J*3^R_E`d0 zECH;EO&~Hb4Jt6Gnj?k=9r==VHL(c{x@Zm`nori8P}HA}^NW{@)<8xoKm}eE=*D(r z{eKSsF#o@jxT6A8;I96?4j=a->{24G^XjI_W3fuwdN)_b* literal 0 HcmV?d00001 diff --git a/lib/account.rb b/lib/account.rb index f71cfe9b..f547c893 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -24,7 +24,6 @@ def self.find(id) if account.id == id return account end - end puts "That account Does Not Exist" end @@ -63,7 +62,12 @@ def deposit(deposit_amount) end end end +# puts Bank::Account.withdraw(10) +# class CheckingAccount < Account +# end +# +# puts CheckingAccount # puts Bank::Account.all # def withdraw(amount) # raise ArgumentError.new("amount must be >= 0") if amount < 0 diff --git a/lib/checking_account.rb b/lib/checking_account.rb new file mode 100644 index 00000000..74770d5b --- /dev/null +++ b/lib/checking_account.rb @@ -0,0 +1,28 @@ +require 'csv' +require_relative '../lib/account' + +module Bank + +class CheckingAccount < Account + +def withdraw(withdrawal_amount) +check_balance = @balance - (withdrawal_amount + 1) + if check_balance < 0 + puts "Warning, this will be below 0 , " + (@balance.to_s) + # return @balance + else + super + (-1) + end +end + +def withdraw_with_check(amount) + +end + + + +# checking_account = CheckingAccount.new(11, 200) +# +# puts checking_account.withdraw(10) +end +end diff --git a/lib/owner.rb b/lib/owner.rb new file mode 100644 index 00000000..8eb0ee81 --- /dev/null +++ b/lib/owner.rb @@ -0,0 +1,10 @@ +module Bank + class Owner + + def initialize(owner_hash) + @name = owner_hash[:name] + @address = owner_hash[:address] + @account_number = owner_hash[:account_number] + end + end +end diff --git a/lib/savings_account.rb b/lib/savings_account.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 167950a5..86e215ab 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -3,144 +3,148 @@ require 'minitest/skip_dsl' require_relative '../lib/account' -# describe "Wave 1" do -# -# describe "Account#initialize" do -# it "Takes an ID and an initial balance" do -# id = 1337 -# balance = 100.0 -# account = Bank::Account.new(id, balance) -# -# account.must_respond_to :id -# account.id.must_equal id -# -# account.must_respond_to :balance -# account.balance.must_equal balance -# end -# -# it "Raises an ArgumentError when created with a negative balance" do -# # Note: we haven't talked about procs yet. You can think -# # of them like blocks that sit by themselves. -# # This code checks that, when the proc is executed, it -# # raises an ArgumentError. -# proc { -# Bank::Account.new(1337, -100.0) -# }.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) -# end -# end -# -# describe "Account#withdraw" do -# it "Reduces the balance" do -# start_balance = 100.0 -# withdrawal_amount = 25.0 -# account = Bank::Account.new(1337, start_balance) -# -# account.withdraw(withdrawal_amount) -# -# expected_balance = start_balance - withdrawal_amount -# account.balance.must_equal expected_balance -# end -# -# it "Returns the modified balance" do -# start_balance = 100.0 -# withdrawal_amount = 25.0 -# account = Bank::Account.new(1337, start_balance) -# -# updated_balance = account.withdraw(withdrawal_amount) -# expected_balance = start_balance - withdrawal_amount -# updated_balance.must_equal expected_balance -# end -# -# it "Outputs a warning if the account would go negative" do -# start_balance = 100.0 -# withdrawal_amount = 200.0 -# account = Bank::Account.new(1337, start_balance) -# -# # Another proc! This test expects something to be printed -# # to the terminal, using 'must_output'. /.+/ is a regular -# # expression matching one or more characters - as long as -# # anything at all is printed out the test will pass. -# proc { -# account.withdraw(withdrawal_amount) -# }.must_output /.+/ -# end -# -# it "Doesn't modify the balance if the account would go negative" do -# start_balance = 100.0 -# withdrawal_amount = 200.0 -# account = Bank::Account.new(1337, start_balance) -# -# updated_balance = account.withdraw(withdrawal_amount) -# -# # Both the value returned and the balance in the account -# # must be un-modified. -# updated_balance.must_equal start_balance -# account.balance.must_equal start_balance -# end -# -# it "Allows the balance to go to 0" do -# account = Bank::Account.new(1337, 100.0) -# updated_balance = account.withdraw(account.balance) -# updated_balance.must_equal 0 -# account.balance.must_equal 0 -# end -# -# it "Requires a positive withdrawal amount" do -# start_balance = 100.0 -# withdrawal_amount = -25.0 -# account = Bank::Account.new(1337, start_balance) -# -# proc { -# account.withdraw(withdrawal_amount) -# }.must_raise ArgumentError -# end -# end -# -# describe "Account#deposit" do -# it "Increases the balance" do -# start_balance = 100.0 -# deposit_amount = 25.0 -# account = Bank::Account.new(1337, start_balance) -# -# account.deposit(deposit_amount) -# -# expected_balance = start_balance + deposit_amount -# account.balance.must_equal expected_balance -# end -# -# it "Returns the modified balance" do -# start_balance = 100.0 -# deposit_amount = 25.0 -# account = Bank::Account.new(1337, start_balance) -# -# updated_balance = account.deposit(deposit_amount) -# -# expected_balance = start_balance + deposit_amount -# updated_balance.must_equal expected_balance -# end -# -# it "Requires a positive deposit amount" do -# start_balance = 100.0 -# deposit_amount = -25.0 -# account = Bank::Account.new(1337, start_balance) -# -# proc { -# account.deposit(deposit_amount) -# }.must_raise ArgumentError -# end -# end -# end +describe "Wave 1" do + + describe "Account#initialize" do + it "Takes an ID and an initial balance" do + id = 1337 + balance = 100.0 + account = Bank::Account.new(id, balance) + + account.must_respond_to :id + account.id.must_equal id + + account.must_respond_to :balance + account.balance.must_equal balance + end + + it "Raises an ArgumentError when created with a negative balance" do + # Note: we haven't talked about procs yet. You can think + # of them like blocks that sit by themselves. + # This code checks that, when the proc is executed, it + # raises an ArgumentError. + proc { + Bank::Account.new(1337, -100.0) + }.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) + end + end + + describe "Account#withdraw" do + it "Reduces the balance" do + start_balance = 100.0 + withdrawal_amount = 25.0 + account = Bank::Account.new(1337, start_balance) + + account.withdraw(withdrawal_amount) + + expected_balance = start_balance - withdrawal_amount + account.balance.must_equal expected_balance + end + + it "Returns the modified balance" do + start_balance = 100.0 + withdrawal_amount = 25.0 + account = Bank::Account.new(1337, start_balance) + + updated_balance = account.withdraw(withdrawal_amount) + expected_balance = start_balance - withdrawal_amount + updated_balance.must_equal expected_balance + end + + it "Outputs a warning if the account would go negative" do + start_balance = 100.0 + withdrawal_amount = 200.0 + account = Bank::Account.new(1337, start_balance) + + # Another proc! This test expects something to be printed + # to the terminal, using 'must_output'. /.+/ is a regular + # expression matching one or more characters - as long as + # anything at all is printed out the test will pass. + proc { + account.withdraw(withdrawal_amount) + }.must_output /.+/ + end + + it "Doesn't modify the balance if the account would go negative" do + start_balance = 100.0 + withdrawal_amount = 200.0 + account = Bank::Account.new(1337, start_balance) + + updated_balance = account.withdraw(withdrawal_amount) + + # Both the value returned and the balance in the account + # must be un-modified. + updated_balance.must_equal start_balance + account.balance.must_equal start_balance + end + + it "Allows the balance to go to 0" do + account = Bank::Account.new(1337, 100.0) + updated_balance = account.withdraw(account.balance) + updated_balance.must_equal 0 + account.balance.must_equal 0 + end + + it "Requires a positive withdrawal amount" do + start_balance = 100.0 + withdrawal_amount = -25.0 + account = Bank::Account.new(1337, start_balance) + + proc { + account.withdraw(withdrawal_amount) + }.must_raise ArgumentError + end + end + + describe "Account#deposit" do + it "Increases the balance" do + start_balance = 100.0 + deposit_amount = 25.0 + account = Bank::Account.new(1337, start_balance) + + account.deposit(deposit_amount) + + expected_balance = start_balance + deposit_amount + account.balance.must_equal expected_balance + end + + it "Returns the modified balance" do + start_balance = 100.0 + deposit_amount = 25.0 + account = Bank::Account.new(1337, start_balance) + + updated_balance = account.deposit(deposit_amount) + + expected_balance = start_balance + deposit_amount + updated_balance.must_equal expected_balance + end + + it "Requires a positive deposit amount" do + start_balance = 100.0 + deposit_amount = -25.0 + account = Bank::Account.new(1337, start_balance) + + proc { + account.deposit(deposit_amount) + }.must_raise ArgumentError + end + end +end # TODO: change 'xdescribe' to 'describe' to run these tests describe "Wave 2" do describe "Account.all" do it "Returns an array of all accounts" do + #before do + # @accounts = Bank::Account.all + # end + account = Bank::Account.all # account.class.must_equal Array # Account.all returns an array @@ -153,7 +157,7 @@ element.must_be_instance_of Bank::Account end # - The number of accounts is correct account.length = 12 - account.length.must_equal 12 + account.length.must_equal 12 #CSV.read("support/accounts.csv").length # - The ID and balance of the first and last ...pull out indexes, id must be equal to # accounts match what's in the CSV file account[0].id.must_equal 1212 diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 7f95339e..f69bee60 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -1,17 +1,20 @@ require 'minitest/autorun' require 'minitest/reporters' require 'minitest/skip_dsl' +require_relative '../lib/checking_account' +require_relative '../lib/account' -# TODO: uncomment the next line once you start wave 3 and add lib/checking_account.rb -# require_relative '../lib/checking_account' +# TODO: uncomment the next line once you start wave 3 and add + +# # Because a CheckingAccount is a kind # of Account, and we've already tested a bunch of functionality # on Account, we effectively get all that testing for free! # Here we'll only test things that are different. -# TODO: change 'xdescribe' to 'describe' to run these tests -xdescribe "CheckingAccount" do + # TODO: change 'xdescribe' to 'describe' to run these tests +describe "CheckingAccount" do describe "#initialize" do # Check that a CheckingAccount is in fact a kind of account it "Is a kind of Account" do @@ -23,48 +26,65 @@ describe "#withdraw" do it "Applies a $1 fee each time" do # TODO: Your test code here! + checking_account = Bank::CheckingAccount.new(11, 200) + new_balance = checking_account.withdraw(10) + new_balance.must_equal 189 end it "Doesn't modify the balance if the fee would put it negative" do - # TODO: Your test code here! + # skip + checking_account = Bank::CheckingAccount.new(11, 200) + # new_balance = checking_account.withdraw(500) + proc { checking_account.withdraw(200)}.must_output(/.+/) + + end end describe "#withdraw_using_check" do + # skip it "Reduces the balance" do # TODO: Your test code here! end it "Returns the modified balance" do + # skip # TODO: Your test code here! end it "Allows the balance to go down to -$10" do + # skip # TODO: Your test code here! end it "Outputs a warning if the account would go below -$10" do + # skip # TODO: Your test code here! end it "Doesn't modify the balance if the account would go below -$10" do + # skip # TODO: Your test code here! end it "Requires a positive withdrawal amount" do + # skip # TODO: Your test code here! end it "Allows 3 free uses" do + # skip # TODO: Your test code here! end it "Applies a $2 fee after the third use" do + # skip # TODO: Your test code here! end end describe "#reset_checks" do + # skip it "Can be called without error" do # TODO: Your test code here! end diff --git a/support/.DS_Store b/support/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1594eef07ff0ddddc4a7101b0fa3e8b65b404b32 GIT binary patch literal 6148 zcmeHKF-`+P3>-s>2q+>d$}Opo_`xX(NVM<(Ab~E*NrXUq59Ci_#$HeY2L%N}$d2rB zy!P(hNVmHNVB^)@DKG*sqzX+=k0{(bv{RFJiRN>xu)rg((c-yhqQ4l@vmfFXGyYm^ zKK}yuc)$`T99iP&V&2ZC^LEO7k#$ZzUc1l(4nEBBRo#o~sJ33K413Piw`_T7HW7U+3 zO~o#dBNU5LVw75KF)Yd%FEy{J*ab#8tTrE3SAJ_=%vb09#nWL;VA^CL8Q5k(y)R{? z^Z$&WOmCC#DQS{{WZ=ItV1vokWX!j#XX~f;)LC1oH&lu8Iyn^jTbBU-(LQqIgE3y@ ZGq0)G1!@+>y_}dA0VgC)GVluwyaJyXHsSyP literal 0 HcmV?d00001 From 4a88a924f7858d158383b36f81b236a32fb78b9a Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Thu, 23 Feb 2017 20:30:17 -0800 Subject: [PATCH 13/26] Set crazy warnings in Rakefile to false --- Rakefile | 2 +- lib/checking_account.rb | 68 +++++++++++++++++++++++----------- specs/checking_account_spec.rb | 8 ++++ 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/Rakefile b/Rakefile index deb52f2c..f4f704fc 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,7 @@ require 'rake/testtask' Rake::TestTask.new do |t| t.libs = ["lib"] - t.warning = true + t.warning = false t.test_files = FileList['specs/*_spec.rb'] end diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 74770d5b..b187494f 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -3,26 +3,52 @@ module Bank -class CheckingAccount < Account - -def withdraw(withdrawal_amount) -check_balance = @balance - (withdrawal_amount + 1) - if check_balance < 0 - puts "Warning, this will be below 0 , " + (@balance.to_s) - # return @balance - else - super + (-1) + class CheckingAccount < Account + attr_reader :id, :balance + def initialize(id, balance) + @id = id + @balance = balance + @check_num = 0 + @withdrawal_fee = 0 + + def withdraw(withdrawal_amount) + check_balance = @balance - (withdrawal_amount + 1) + if check_balance < 0 + puts "Warning, this will be below 0 , " + (@balance.to_s) + # return @balance + else + super + (-1) + end + end + + def withdraw_with_check(withdrawal_amount) + # counter to see how many checks drawn + # keep track of what check fee is, at one point at 4 goes up to 2 + + if @balance - withdrawal_amount < -10 + puts "Warning, the balance cannot be negative " + return + end + + if @check_num >= 3 + @withdrawal_fee = 2 + end + + @balance -= withdrawal_amount + return @balance + + end + + def reset_checks + # if reset_checks >= 3 + # reset_checks = 0 + # end + end + end + + + # checking_account = CheckingAccount.new(11, 200) + # + # puts checking_account.withdraw(10) end end - -def withdraw_with_check(amount) - -end - - - -# checking_account = CheckingAccount.new(11, 200) -# -# puts checking_account.withdraw(10) -end -end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index f69bee60..bf8d2e60 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -45,11 +45,19 @@ # skip it "Reduces the balance" do # TODO: Your test code here! + checking_account = Bank::CheckingAccount.new(11, 200) + checking_account.balance.must_equal 200 + checking_account.withdraw_with_check(10) + checking_account.balance.must_equal 190 end it "Returns the modified balance" do # skip # TODO: Your test code here! + checking_account = Bank::CheckingAccount.new(11, 200) + checking_account.withdraw_with_check(10) + checking_account.balance.must_equal 190 + checking_account.balance.must_equal end it "Allows the balance to go down to -$10" do From e6c979c5d89906af2f15a0d12da9573c5335b682 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Thu, 23 Feb 2017 22:51:04 -0800 Subject: [PATCH 14/26] Working on withdraw_with_check method --- lib/checking_account.rb | 4 ++-- specs/account_spec.rb | 5 ++--- specs/checking_account_spec.rb | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index b187494f..42e1fd26 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -34,8 +34,8 @@ def withdraw_with_check(withdrawal_amount) @withdrawal_fee = 2 end - @balance -= withdrawal_amount - return @balance + @balance -= (withdrawal_amount + 1) + end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 86e215ab..d0448827 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -65,9 +65,8 @@ # to the terminal, using 'must_output'. /.+/ is a regular # expression matching one or more characters - as long as # anything at all is printed out the test will pass. - proc { - account.withdraw(withdrawal_amount) - }.must_output /.+/ + proc { account.withdraw(withdrawal_amount) + }.must_output(/.+/) end it "Doesn't modify the balance if the account would go negative" do diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index bf8d2e60..a33b2768 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -48,26 +48,35 @@ checking_account = Bank::CheckingAccount.new(11, 200) checking_account.balance.must_equal 200 checking_account.withdraw_with_check(10) - checking_account.balance.must_equal 190 + checking_account.balance.must_equal 189 end it "Returns the modified balance" do # skip # TODO: Your test code here! checking_account = Bank::CheckingAccount.new(11, 200) + checking_account.balance.must_equal 200 checking_account.withdraw_with_check(10) - checking_account.balance.must_equal 190 - checking_account.balance.must_equal + checking_account.balance.must_equal 189 end it "Allows the balance to go down to -$10" do # skip # TODO: Your test code here! + checking_account = Bank::CheckingAccount.new(11, 200) + checking_account.balance.must_equal 200 + checking_account.withdraw_with_check(209) + checking_account.balance.must_equal -10 end it "Outputs a warning if the account would go below -$10" do # skip # TODO: Your test code here! + checking_account = Bank::CheckingAccount.new(11, 200) + checking_account.balance.must_equal 200 + checking_account.withdraw_with_check(210) + checking_account.balance.must_equal -11 + proc { checking_account.withdraw_with_check(210)}.must_output(/.+/) end it "Doesn't modify the balance if the account would go below -$10" do From 088191162b335f25bbc7c5d2f51349a1313e56fb Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Thu, 23 Feb 2017 23:21:58 -0800 Subject: [PATCH 15/26] Started Savings Account Inheritance, still working on Checking Account reset_checks method --- lib/checking_account.rb | 9 ++++++--- lib/savings_account.rb | 15 +++++++++++++++ specs/checking_account_spec.rb | 16 ++++++++++++---- specs/savings_account_spec.rb | 3 ++- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 42e1fd26..71392040 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -24,10 +24,13 @@ def withdraw(withdrawal_amount) def withdraw_with_check(withdrawal_amount) # counter to see how many checks drawn # keep track of what check fee is, at one point at 4 goes up to 2 - - if @balance - withdrawal_amount < -10 + if withdrawal_amount < 0 + raise ArgumentError.new "You cannot withdraw a negative amount" + elsif @balance - (withdrawal_amount + 1) < -10 puts "Warning, the balance cannot be negative " - return + return @balance + # elsif withdrawal_amount < 0 + # raise ArgumentError.new "You cannot withdraw a negative amount" end if @check_num >= 3 diff --git a/lib/savings_account.rb b/lib/savings_account.rb index e69de29b..54690392 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -0,0 +1,15 @@ +require 'csv' +require_relative '../lib/account' + +module Bank + + class SavingsAccount < Account + attr_reader :id, :balance + def initialize(id, balance) + @id = id + @balance = balance + end + end + + +end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index a33b2768..44243977 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -34,10 +34,8 @@ it "Doesn't modify the balance if the fee would put it negative" do # skip checking_account = Bank::CheckingAccount.new(11, 200) - # new_balance = checking_account.withdraw(500) proc { checking_account.withdraw(200)}.must_output(/.+/) - - + checking_account.balance.must_equal 200 end end @@ -75,18 +73,28 @@ checking_account = Bank::CheckingAccount.new(11, 200) checking_account.balance.must_equal 200 checking_account.withdraw_with_check(210) - checking_account.balance.must_equal -11 + checking_account.balance.must_equal 200 proc { checking_account.withdraw_with_check(210)}.must_output(/.+/) end it "Doesn't modify the balance if the account would go below -$10" do # skip # TODO: Your test code here! + checking_account = Bank::CheckingAccount.new(11, 200) + checking_account.balance.must_equal 200 + checking_account.withdraw_with_check(210) + checking_account.balance.must_equal 200 end it "Requires a positive withdrawal amount" do # skip # TODO: Your test code here! + start_balance = 100.0 + withdrawal_amount = -25.0 + checking_account = Bank::CheckingAccount.new(11, start_balance) + proc { + checking_account.withdraw_with_check(withdrawal_amount) + }.must_raise(ArgumentError) end it "Allows 3 free uses" do diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 3f4d1e4a..b52f212c 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -1,9 +1,10 @@ require 'minitest/autorun' require 'minitest/reporters' require 'minitest/skip_dsl' +require_relative '../lib/savings_account' # TODO: uncomment the next line once you start wave 3 and add lib/savings_account.rb -# require_relative '../lib/savings_account' + # Because a SavingsAccount is a kind # of Account, and we've already tested a bunch of functionality From 897a05e1bf8b68b125cac3aca21cf58be2487e04 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Thu, 23 Feb 2017 23:50:19 -0800 Subject: [PATCH 16/26] SavingsAccount withdraw method initialized --- lib/savings_account.rb | 13 ++++++++++++- specs/savings_account_spec.rb | 7 ++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 54690392..d1879b92 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -5,11 +5,22 @@ module Bank class SavingsAccount < Account attr_reader :id, :balance + def initialize(id, balance) + + raise ArgumentError.new "Balance must be at least $10" unless balance >= 10 @id = id @balance = balance end + + def withdraw(withdrawal_amount) + super + (-2) + end + + + + end -end +end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index b52f212c..23563809 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -12,7 +12,7 @@ # Here we'll only test things that are different. # TODO: change 'xdescribe' to 'describe' to run these tests -xdescribe "SavingsAccount" do +describe "SavingsAccount" do describe "#initialize" do it "Is a kind of Account" do # Check that a SavingsAccount is in fact a kind of account @@ -22,12 +22,17 @@ it "Requires an initial balance of at least $10" do # TODO: Your test code here! + proc{ account = Bank::SavingsAccount.new(1212, 9) + }.must_raise(ArgumentError) end end describe "#withdraw" do it "Applies a $2 fee each time" do # TODO: Your test code here! + savings_account = Bank::SavingsAccount.new(11, 200) + new_balance = savings_account.withdraw(10) + new_balance.must_equal 188 end it "Outputs a warning if the balance would go below $10" do From c9db8c4d843b3113317ee193e25243ddbd9cbb0a Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Fri, 24 Feb 2017 00:14:01 -0800 Subject: [PATCH 17/26] Working on Savings Account, getting failure with balance below 0 test. --- lib/savings_account.rb | 12 +++++++++--- specs/account_spec.rb | 7 ++----- specs/checking_account_spec.rb | 2 +- specs/savings_account_spec.rb | 8 ++++++++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index d1879b92..e4c9e2f3 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -14,13 +14,19 @@ def initialize(id, balance) end def withdraw(withdrawal_amount) - super + (-2) - end + # c_balance = @balance - (withdrawal_amount + 1) + if @balance < 10 + puts "Warning, this will be below 0 ," + (@balance.to_s) + @balance = @balance + else + super + (-2) + end - end + end + end end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index d0448827..06cd5ae6 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -39,9 +39,7 @@ start_balance = 100.0 withdrawal_amount = 25.0 account = Bank::Account.new(1337, start_balance) - account.withdraw(withdrawal_amount) - expected_balance = start_balance - withdrawal_amount account.balance.must_equal expected_balance end @@ -189,9 +187,8 @@ it "Raises an error for an account that doesn't exist" do # TODO: Your test code here! - proc { - Bank::Account.find(111111) - }.must_output /.+/ + proc { Bank::Account.find(111111) + }.must_output(/.+/) end end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 44243977..4d20bc1e 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -64,7 +64,7 @@ checking_account = Bank::CheckingAccount.new(11, 200) checking_account.balance.must_equal 200 checking_account.withdraw_with_check(209) - checking_account.balance.must_equal -10 + checking_account.balance.must_equal(-10) end it "Outputs a warning if the account would go below -$10" do diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 23563809..022f05df 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -37,10 +37,18 @@ it "Outputs a warning if the balance would go below $10" do # TODO: Your test code here! + savings_account = Bank::SavingsAccount.new(11, 200) + savings_account.balance.must_equal 200 + savings_account.withdraw(191) + proc { savings_account.withdraw(191)}.must_output(/.+/) end it "Doesn't modify the balance if it would go below $10" do # TODO: Your test code here! + savings_account = Bank::SavingsAccount.new(1212, 200) + # savings_account.balance.must_equal 200 + savings_account.withdraw(191) + savings_account.balance.must_equal 200 end it "Doesn't modify the balance if the fee would put it below $10" do From 1671c8bb0a59cbbd635caf0792c4ad3433d0917b Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Fri, 24 Feb 2017 11:25:35 -0800 Subject: [PATCH 18/26] Working on savings_account, finished withdraw method --- lib/checking_account.rb | 5 ++--- lib/savings_account.rb | 8 ++++---- specs/account_spec.rb | 4 ++-- specs/savings_account_spec.rb | 8 +++++++- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 71392040..2c803b12 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -15,7 +15,6 @@ def withdraw(withdrawal_amount) check_balance = @balance - (withdrawal_amount + 1) if check_balance < 0 puts "Warning, this will be below 0 , " + (@balance.to_s) - # return @balance else super + (-1) end @@ -29,8 +28,8 @@ def withdraw_with_check(withdrawal_amount) elsif @balance - (withdrawal_amount + 1) < -10 puts "Warning, the balance cannot be negative " return @balance - # elsif withdrawal_amount < 0 - # raise ArgumentError.new "You cannot withdraw a negative amount" + # elsif withdrawal_amount < 0 + # raise ArgumentError.new "You cannot withdraw a negative amount" end if @check_num >= 3 diff --git a/lib/savings_account.rb b/lib/savings_account.rb index e4c9e2f3..64f69195 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -14,10 +14,10 @@ def initialize(id, balance) end def withdraw(withdrawal_amount) - # c_balance = @balance - (withdrawal_amount + 1) - if @balance < 10 - puts "Warning, this will be below 0 ," + (@balance.to_s) - @balance = @balance + temp_balance = @balance - (withdrawal_amount + 2) + if temp_balance < 10 + puts "Warning, this will make your balance below your mininum , the current balance is " + (@balance.to_s) + @balance else super + (-2) end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 06cd5ae6..d2d6893d 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -139,8 +139,8 @@ it "Returns an array of all accounts" do #before do - # @accounts = Bank::Account.all - # end + # @accounts = Bank::Account.all + # end account = Bank::Account.all # account.class.must_equal Array diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 022f05df..233a423b 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -23,7 +23,7 @@ it "Requires an initial balance of at least $10" do # TODO: Your test code here! proc{ account = Bank::SavingsAccount.new(1212, 9) - }.must_raise(ArgumentError) + }.must_raise(ArgumentError) end end @@ -49,10 +49,16 @@ # savings_account.balance.must_equal 200 savings_account.withdraw(191) savings_account.balance.must_equal 200 + proc { savings_account.withdraw(191)}.must_output(/.+/) end it "Doesn't modify the balance if the fee would put it below $10" do # TODO: Your test code here! + savings_account = Bank::SavingsAccount.new(1212, 200) + # savings_account.balance.must_equal 200 + savings_account.withdraw(189) + savings_account.balance.must_equal 200 + proc { savings_account.withdraw(189)}.must_output(/.+/) end end From f9af0b6db6cc3125585c28784198af42d378aa09 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Fri, 24 Feb 2017 13:25:55 -0800 Subject: [PATCH 19/26] Updated interest calculation for savings_account --- lib/savings_account.rb | 14 ++++++++++---- specs/savings_account_spec.rb | 6 ++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 64f69195..70c834d7 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -4,13 +4,14 @@ module Bank class SavingsAccount < Account - attr_reader :id, :balance + attr_reader :id, :balance, :interest def initialize(id, balance) raise ArgumentError.new "Balance must be at least $10" unless balance >= 10 @id = id @balance = balance + @interest = interest end def withdraw(withdrawal_amount) @@ -21,12 +22,17 @@ def withdraw(withdrawal_amount) else super + (-2) end + end - - - + def add_interest(rate) + # rate = 0.25 + interest = @balance * (rate / 100).to_f + @balance += interest + return interest end end + + end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 233a423b..7b22658a 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -65,10 +65,16 @@ describe "#add_interest" do it "Returns the interest calculated" do # TODO: Your test code here! + savings_account = Bank::SavingsAccount.new(11, 10000) + interest = savings_account.add_interest(0.25) + interest.must_equal 25.0 end it "Updates the balance with calculated interest" do # TODO: Your test code here! + savings_account = Bank::SavingsAccount.new(11, 10000) + savings_account.add_interest(0.25) + savings_account.balance.must_equal 10025.0 end it "Requires a positive rate" do From 5ddf7120c5f746102fe21a3c274576ceee79e492 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Fri, 24 Feb 2017 13:52:50 -0800 Subject: [PATCH 20/26] savingd_account.rb primary potentially done --- lib/savings_account.rb | 12 +++++++----- specs/savings_account_spec.rb | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 70c834d7..c4250b6e 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -25,13 +25,15 @@ def withdraw(withdrawal_amount) end def add_interest(rate) - # rate = 0.25 - interest = @balance * (rate / 100).to_f - @balance += interest - return interest + if rate < 0 + raise ArgumentError.new "The interest rate cannot be negative" + else + interest = @balance * (rate / 100).to_f + @balance += interest + return interest + end end - end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 7b22658a..134de478 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -49,16 +49,13 @@ # savings_account.balance.must_equal 200 savings_account.withdraw(191) savings_account.balance.must_equal 200 - proc { savings_account.withdraw(191)}.must_output(/.+/) end it "Doesn't modify the balance if the fee would put it below $10" do # TODO: Your test code here! savings_account = Bank::SavingsAccount.new(1212, 200) - # savings_account.balance.must_equal 200 savings_account.withdraw(189) savings_account.balance.must_equal 200 - proc { savings_account.withdraw(189)}.must_output(/.+/) end end @@ -79,6 +76,10 @@ it "Requires a positive rate" do # TODO: Your test code here! + savings_account = Bank::SavingsAccount.new(11, 10000) + proc{ savings_account.add_interest(-1) + }.must_raise(ArgumentError) + end end end From 44d888c783c8440cd38c7084a06b7e293419bd36 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Fri, 24 Feb 2017 15:12:36 -0800 Subject: [PATCH 21/26] refined withdraw_with_check method for checking_account.rb --- lib/account.rb | 2 +- lib/checking_account.rb | 38 ++++++++++++++++------------------- specs/savings_account_spec.rb | 1 - 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index f547c893..7561cb93 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -62,7 +62,7 @@ def deposit(deposit_amount) end end end -# puts Bank::Account.withdraw(10) +# puts Bank::Account.withdraw(10) # class CheckingAccount < Account # end diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 2c803b12..05fb5bd2 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -8,8 +8,8 @@ class CheckingAccount < Account def initialize(id, balance) @id = id @balance = balance - @check_num = 0 - @withdrawal_fee = 0 + @check_num = 3 + # @withdrawal_fee = 0 def withdraw(withdrawal_amount) check_balance = @balance - (withdrawal_amount + 1) @@ -25,32 +25,28 @@ def withdraw_with_check(withdrawal_amount) # keep track of what check fee is, at one point at 4 goes up to 2 if withdrawal_amount < 0 raise ArgumentError.new "You cannot withdraw a negative amount" - elsif @balance - (withdrawal_amount + 1) < -10 - puts "Warning, the balance cannot be negative " - return @balance - # elsif withdrawal_amount < 0 - # raise ArgumentError.new "You cannot withdraw a negative amount" end - if @check_num >= 3 - @withdrawal_fee = 2 + if (@balance - withdrawal_amount) < -10 + puts "Warning, the balance cannot be negative " + return @balance + else + withdrawal_fee = 0 + @balance -= withdrawal_amount + withdrawal_fee + if check_num < 1 + withdrawal_fee = 2 + @balance + withdrawal_fee + end end - - @balance -= (withdrawal_amount + 1) - - end + end - def reset_checks - # if reset_checks >= 3 - # reset_checks = 0 - # end + + def reset_checks + if @check_num >= 3 + @check_num = 0 end end - - # checking_account = CheckingAccount.new(11, 200) - # - # puts checking_account.withdraw(10) end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 134de478..a639d3c1 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -79,7 +79,6 @@ savings_account = Bank::SavingsAccount.new(11, 10000) proc{ savings_account.add_interest(-1) }.must_raise(ArgumentError) - end end end From e6a8ccca5ad3ef7d338cb5a71e54b1b022be78e6 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Fri, 24 Feb 2017 15:39:47 -0800 Subject: [PATCH 22/26] Refactor withdraw_with_check method in checking_account.rb --- lib/checking_account.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 05fb5bd2..a442797f 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -21,21 +21,17 @@ def withdraw(withdrawal_amount) end def withdraw_with_check(withdrawal_amount) - # counter to see how many checks drawn - # keep track of what check fee is, at one point at 4 goes up to 2 if withdrawal_amount < 0 raise ArgumentError.new "You cannot withdraw a negative amount" - end - - if (@balance - withdrawal_amount) < -10 + elsif (@balance - withdrawal_amount) <= -10 puts "Warning, the balance cannot be negative " return @balance else withdrawal_fee = 0 - @balance -= withdrawal_amount + withdrawal_fee - if check_num < 1 + @balance -= withdrawal_amount + 1 + withdrawal_fee + if @check_num < 1 withdrawal_fee = 2 - @balance + withdrawal_fee + @balance -= withdrawal_fee end end end From dea67d06ff91416540023ce8921d64807984b5ea Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Fri, 24 Feb 2017 15:47:08 -0800 Subject: [PATCH 23/26] Refactored withdraw_with_check method in checking_account.rb, with no failures at this point --- lib/checking_account.rb | 4 ++-- specs/checking_account_spec.rb | 15 ++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index a442797f..31cb92c2 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -23,12 +23,12 @@ def withdraw(withdrawal_amount) def withdraw_with_check(withdrawal_amount) if withdrawal_amount < 0 raise ArgumentError.new "You cannot withdraw a negative amount" - elsif (@balance - withdrawal_amount) <= -10 + elsif (@balance - withdrawal_amount) <= -11 puts "Warning, the balance cannot be negative " return @balance else withdrawal_fee = 0 - @balance -= withdrawal_amount + 1 + withdrawal_fee + @balance -= withdrawal_amount + withdrawal_fee if @check_num < 1 withdrawal_fee = 2 @balance -= withdrawal_fee diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 4d20bc1e..94bba1f9 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -46,7 +46,7 @@ checking_account = Bank::CheckingAccount.new(11, 200) checking_account.balance.must_equal 200 checking_account.withdraw_with_check(10) - checking_account.balance.must_equal 189 + checking_account.balance.must_equal 190 end it "Returns the modified balance" do @@ -55,15 +55,14 @@ checking_account = Bank::CheckingAccount.new(11, 200) checking_account.balance.must_equal 200 checking_account.withdraw_with_check(10) - checking_account.balance.must_equal 189 + checking_account.balance.must_equal 190 end it "Allows the balance to go down to -$10" do # skip # TODO: Your test code here! checking_account = Bank::CheckingAccount.new(11, 200) - checking_account.balance.must_equal 200 - checking_account.withdraw_with_check(209) + checking_account.withdraw_with_check(210) checking_account.balance.must_equal(-10) end @@ -71,18 +70,16 @@ # skip # TODO: Your test code here! checking_account = Bank::CheckingAccount.new(11, 200) + checking_account.withdraw_with_check(211) checking_account.balance.must_equal 200 - checking_account.withdraw_with_check(210) - checking_account.balance.must_equal 200 - proc { checking_account.withdraw_with_check(210)}.must_output(/.+/) + proc { checking_account.withdraw_with_check(211)}.must_output(/.+/) end it "Doesn't modify the balance if the account would go below -$10" do # skip # TODO: Your test code here! checking_account = Bank::CheckingAccount.new(11, 200) - checking_account.balance.must_equal 200 - checking_account.withdraw_with_check(210) + checking_account.withdraw_with_check(211) checking_account.balance.must_equal 200 end From 0c0d33fb97e5122740cdf3e4f332f1e6e52abcf2 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Sat, 25 Feb 2017 13:21:04 -0800 Subject: [PATCH 24/26] Primary Requirements Done --- lib/checking_account.rb | 8 ++++---- specs/checking_account_spec.rb | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 31cb92c2..6495b308 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -9,7 +9,6 @@ def initialize(id, balance) @id = id @balance = balance @check_num = 3 - # @withdrawal_fee = 0 def withdraw(withdrawal_amount) check_balance = @balance - (withdrawal_amount + 1) @@ -29,7 +28,8 @@ def withdraw_with_check(withdrawal_amount) else withdrawal_fee = 0 @balance -= withdrawal_amount + withdrawal_fee - if @check_num < 1 + @check_num -= 1 + if @check_num < 0 withdrawal_fee = 2 @balance -= withdrawal_fee end @@ -39,8 +39,8 @@ def withdraw_with_check(withdrawal_amount) def reset_checks - if @check_num >= 3 - @check_num = 0 + if @check_num <= 0 + @check_num = 3 end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 94bba1f9..7fde5831 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -13,7 +13,7 @@ # on Account, we effectively get all that testing for free! # Here we'll only test things that are different. - # TODO: change 'xdescribe' to 'describe' to run these tests +# TODO: change 'xdescribe' to 'describe' to run these tests describe "CheckingAccount" do describe "#initialize" do # Check that a CheckingAccount is in fact a kind of account @@ -97,11 +97,19 @@ it "Allows 3 free uses" do # skip # TODO: Your test code here! + checking_account = Bank::CheckingAccount.new(11, 80) + 3.times do checking_account.withdraw_with_check(20) + end + checking_account.balance.must_equal 20 end it "Applies a $2 fee after the third use" do # skip # TODO: Your test code here! + checking_account = Bank::CheckingAccount.new(11, 100) + 4.times do checking_account.withdraw_with_check(20) + end + checking_account.balance.must_equal 18 end end @@ -109,14 +117,30 @@ # skip it "Can be called without error" do # TODO: Your test code here! + checking_account = Bank::CheckingAccount.new(11, 200) + 4.times do checking_account.withdraw_with_check(20) + end + checking_account.reset_checks + checking_account.withdraw_with_check(20) + checking_account.balance.must_equal 98 end it "Makes the next three checks free if less than 3 checks had been used" do # TODO: Your test code here! + checking_account = Bank::CheckingAccount.new(11, 200) + 3.times do checking_account.withdraw_with_check(20) + end + checking_account.balance.must_equal 140 end it "Makes the next three checks free if more than 3 checks had been used" do # TODO: Your test code here! + checking_account = Bank::CheckingAccount.new(11, 200) + 4.times do checking_account.withdraw_with_check(20) + end + checking_account.reset_checks + checking_account.withdraw_with_check(20) + checking_account.balance.must_equal 98 end end end From 6a900161ec597c94b68f019be34ae83ea79b8359 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Sun, 26 Feb 2017 23:50:27 -0800 Subject: [PATCH 25/26] Bank Accounts submitting --- lib/account.rb | 23 ----------------- lib/checking_account.rb | 1 - lib/savings_account.rb | 3 --- specs/account_spec.rb | 31 +++-------------------- specs/checking_account_spec.rb | 46 +++++++++++----------------------- specs/savings_account_spec.rb | 19 +------------- 6 files changed, 18 insertions(+), 105 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 7561cb93..44faaddc 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -12,11 +12,8 @@ def self.all open_date = file[2] new_account = Account.new(id, balance, open_date) account << new_account - # puts account end return account - # puts account - end def self.find(id) @@ -38,8 +35,6 @@ def initialize(id, balance, open_date = nil) end end - - def withdraw(withdrawal_amount) if withdrawal_amount > @balance puts "Warning, the balance cannot be negative" @@ -55,27 +50,9 @@ def deposit(deposit_amount) #raise ArgumentError.new("amount must be >= 0") if amount < 0 if deposit_amount < 0 raise ArgumentError.new "The deposit must be greater than 0" - else @balance += deposit_amount end end end end -# puts Bank::Account.withdraw(10) - -# class CheckingAccount < Account -# end -# -# puts CheckingAccount -# puts Bank::Account.all -# def withdraw(amount) -# raise ArgumentError.new("amount must be >= 0") if amount < 0 -# -# if @balance - amount < 0 -# puts "Oh no! Account will be negative" -# return @balance -# else -# @balance -= amount -# end -# end diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 6495b308..1fcd968c 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -37,7 +37,6 @@ def withdraw_with_check(withdrawal_amount) end end - def reset_checks if @check_num <= 0 @check_num = 3 diff --git a/lib/savings_account.rb b/lib/savings_account.rb index c4250b6e..a48fbbad 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -33,8 +33,5 @@ def add_interest(rate) return interest end end - end - - end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index d2d6893d..ce305ec4 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -13,23 +13,18 @@ account.must_respond_to :id account.id.must_equal id - + account.must_respond_to :balance account.balance.must_equal balance end it "Raises an ArgumentError when created with a negative balance" do - # Note: we haven't talked about procs yet. You can think - # of them like blocks that sit by themselves. - # This code checks that, when the proc is executed, it - # raises an ArgumentError. proc { Bank::Account.new(1337, -100.0) }.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) end end @@ -59,10 +54,6 @@ withdrawal_amount = 200.0 account = Bank::Account.new(1337, start_balance) - # Another proc! This test expects something to be printed - # to the terminal, using 'must_output'. /.+/ is a regular - # expression matching one or more characters - as long as - # anything at all is printed out the test will pass. proc { account.withdraw(withdrawal_amount) }.must_output(/.+/) end @@ -73,15 +64,13 @@ account = Bank::Account.new(1337, start_balance) updated_balance = account.withdraw(withdrawal_amount) - - # Both the value returned and the balance in the account - # must be un-modified. updated_balance.must_equal start_balance account.balance.must_equal start_balance end it "Allows the balance to go to 0" do account = Bank::Account.new(1337, 100.0) + updated_balance = account.withdraw(account.balance) updated_balance.must_equal 0 account.balance.must_equal 0 @@ -105,7 +94,6 @@ account = Bank::Account.new(1337, start_balance) account.deposit(deposit_amount) - expected_balance = start_balance + deposit_amount account.balance.must_equal expected_balance end @@ -116,7 +104,6 @@ account = Bank::Account.new(1337, start_balance) updated_balance = account.deposit(deposit_amount) - expected_balance = start_balance + deposit_amount updated_balance.must_equal expected_balance end @@ -133,21 +120,13 @@ end end -# TODO: change 'xdescribe' to 'describe' to run these tests describe "Wave 2" do describe "Account.all" do it "Returns an array of all accounts" do - #before do - # @accounts = Bank::Account.all - # end - account = Bank::Account.all - # account.class.must_equal Array - # Account.all returns an array - account.must_be_instance_of Array - #loop through array to retrieve instance of bank account put assertion that account is instance + account.must_be_instance_of Array # - Everything in the array is an Account account.each do |element| @@ -166,27 +145,23 @@ describe "Account.find" do it "Returns an account that exists" do - # TODO: Your test code here! account = Bank::Account.find(1212) account.must_be_instance_of Bank::Account end it "Can find the first account from the CSV" do - # TODO: Your test code here! accounts = Bank::Account.all account = Bank::Account.find(1212) account.id.must_equal accounts[0].id end it "Can find the last account from the CSV" do - # TODO: Your test code here! accounts = Bank::Account.all account = Bank::Account.find(15156) account.id.must_equal accounts[-1].id end it "Raises an error for an account that doesn't exist" do - # TODO: Your test code here! proc { Bank::Account.find(111111) }.must_output(/.+/) end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 7fde5831..0144b2d3 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -4,19 +4,9 @@ require_relative '../lib/checking_account' require_relative '../lib/account' -# TODO: uncomment the next line once you start wave 3 and add - -# -# Because a CheckingAccount is a kind -# of Account, and we've already tested a bunch of functionality -# on Account, we effectively get all that testing for free! -# Here we'll only test things that are different. - -# TODO: change 'xdescribe' to 'describe' to run these tests describe "CheckingAccount" do describe "#initialize" do - # Check that a CheckingAccount is in fact a kind of account it "Is a kind of Account" do account = Bank::CheckingAccount.new(12345, 100.0) account.must_be_kind_of Bank::Account @@ -25,88 +15,81 @@ describe "#withdraw" do it "Applies a $1 fee each time" do - # TODO: Your test code here! checking_account = Bank::CheckingAccount.new(11, 200) + new_balance = checking_account.withdraw(10) new_balance.must_equal 189 end it "Doesn't modify the balance if the fee would put it negative" do - # skip checking_account = Bank::CheckingAccount.new(11, 200) + proc { checking_account.withdraw(200)}.must_output(/.+/) checking_account.balance.must_equal 200 end end describe "#withdraw_using_check" do - # skip it "Reduces the balance" do - # TODO: Your test code here! checking_account = Bank::CheckingAccount.new(11, 200) + checking_account.balance.must_equal 200 checking_account.withdraw_with_check(10) checking_account.balance.must_equal 190 end it "Returns the modified balance" do - # skip - # TODO: Your test code here! checking_account = Bank::CheckingAccount.new(11, 200) + checking_account.balance.must_equal 200 checking_account.withdraw_with_check(10) checking_account.balance.must_equal 190 end it "Allows the balance to go down to -$10" do - # skip - # TODO: Your test code here! checking_account = Bank::CheckingAccount.new(11, 200) + checking_account.withdraw_with_check(210) checking_account.balance.must_equal(-10) end it "Outputs a warning if the account would go below -$10" do - # skip - # TODO: Your test code here! checking_account = Bank::CheckingAccount.new(11, 200) + checking_account.withdraw_with_check(211) checking_account.balance.must_equal 200 + proc { checking_account.withdraw_with_check(211)}.must_output(/.+/) end it "Doesn't modify the balance if the account would go below -$10" do - # skip - # TODO: Your test code here! checking_account = Bank::CheckingAccount.new(11, 200) + checking_account.withdraw_with_check(211) checking_account.balance.must_equal 200 end it "Requires a positive withdrawal amount" do - # skip - # TODO: Your test code here! start_balance = 100.0 withdrawal_amount = -25.0 checking_account = Bank::CheckingAccount.new(11, start_balance) + proc { checking_account.withdraw_with_check(withdrawal_amount) }.must_raise(ArgumentError) end it "Allows 3 free uses" do - # skip - # TODO: Your test code here! checking_account = Bank::CheckingAccount.new(11, 80) + 3.times do checking_account.withdraw_with_check(20) end checking_account.balance.must_equal 20 end it "Applies a $2 fee after the third use" do - # skip - # TODO: Your test code here! checking_account = Bank::CheckingAccount.new(11, 100) + 4.times do checking_account.withdraw_with_check(20) end checking_account.balance.must_equal 18 @@ -114,10 +97,9 @@ end describe "#reset_checks" do - # skip it "Can be called without error" do - # TODO: Your test code here! checking_account = Bank::CheckingAccount.new(11, 200) + 4.times do checking_account.withdraw_with_check(20) end checking_account.reset_checks @@ -126,16 +108,16 @@ end it "Makes the next three checks free if less than 3 checks had been used" do - # TODO: Your test code here! checking_account = Bank::CheckingAccount.new(11, 200) + 3.times do checking_account.withdraw_with_check(20) end checking_account.balance.must_equal 140 end it "Makes the next three checks free if more than 3 checks had been used" do - # TODO: Your test code here! checking_account = Bank::CheckingAccount.new(11, 200) + 4.times do checking_account.withdraw_with_check(20) end checking_account.reset_checks diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index a639d3c1..1078da83 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -3,15 +3,6 @@ require 'minitest/skip_dsl' require_relative '../lib/savings_account' -# TODO: uncomment the next line once you start wave 3 and add lib/savings_account.rb - - -# Because a SavingsAccount is a kind -# of Account, and we've already tested a bunch of functionality -# on Account, we effectively get all that testing for free! -# Here we'll only test things that are different. - -# TODO: change 'xdescribe' to 'describe' to run these tests describe "SavingsAccount" do describe "#initialize" do it "Is a kind of Account" do @@ -21,22 +12,19 @@ end it "Requires an initial balance of at least $10" do - # TODO: Your test code here! proc{ account = Bank::SavingsAccount.new(1212, 9) }.must_raise(ArgumentError) end end - + describe "#withdraw" do it "Applies a $2 fee each time" do - # TODO: Your test code here! savings_account = Bank::SavingsAccount.new(11, 200) new_balance = savings_account.withdraw(10) new_balance.must_equal 188 end it "Outputs a warning if the balance would go below $10" do - # TODO: Your test code here! savings_account = Bank::SavingsAccount.new(11, 200) savings_account.balance.must_equal 200 savings_account.withdraw(191) @@ -44,7 +32,6 @@ end it "Doesn't modify the balance if it would go below $10" do - # TODO: Your test code here! savings_account = Bank::SavingsAccount.new(1212, 200) # savings_account.balance.must_equal 200 savings_account.withdraw(191) @@ -52,7 +39,6 @@ end it "Doesn't modify the balance if the fee would put it below $10" do - # TODO: Your test code here! savings_account = Bank::SavingsAccount.new(1212, 200) savings_account.withdraw(189) savings_account.balance.must_equal 200 @@ -61,21 +47,18 @@ describe "#add_interest" do it "Returns the interest calculated" do - # TODO: Your test code here! savings_account = Bank::SavingsAccount.new(11, 10000) interest = savings_account.add_interest(0.25) interest.must_equal 25.0 end it "Updates the balance with calculated interest" do - # TODO: Your test code here! savings_account = Bank::SavingsAccount.new(11, 10000) savings_account.add_interest(0.25) savings_account.balance.must_equal 10025.0 end it "Requires a positive rate" do - # TODO: Your test code here! savings_account = Bank::SavingsAccount.new(11, 10000) proc{ savings_account.add_interest(-1) }.must_raise(ArgumentError) From 3a8e0e81332e439e63b90d9a17a7f1182e477e19 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Mon, 27 Feb 2017 09:18:11 -0800 Subject: [PATCH 26/26] Removed extraneous interest variable from savings_account --- lib/savings_account.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index a48fbbad..f7825f0c 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -11,7 +11,6 @@ def initialize(id, balance) raise ArgumentError.new "Balance must be at least $10" unless balance >= 10 @id = id @balance = balance - @interest = interest end def withdraw(withdrawal_amount)