From 18657e36abc2e40385eeb0461b893aa0ddd859b4 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Tue, 21 Feb 2017 14:52:40 -0800 Subject: [PATCH 01/42] created initial structure of module and class --- lib/account.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/account.rb b/lib/account.rb index e69de29b..14b8dd8f 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -0,0 +1,7 @@ +module Bank + class Account + + + end + +end From 49f6f0134308e055f00cdc220e11f05837fe7a7a Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Tue, 21 Feb 2017 15:00:58 -0800 Subject: [PATCH 02/42] initialized with ID and initial balance --- lib/account.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/account.rb b/lib/account.rb index 14b8dd8f..9ea2d9b9 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -2,6 +2,15 @@ module Bank class Account + + def initialize (id, balance) + @id = id + @balance = balance + + end + + + end end From 26b1e13ff495f1ae69844a3571e3c14676e57a74 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Tue, 21 Feb 2017 15:02:20 -0800 Subject: [PATCH 03/42] added withdraw method --- lib/account.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/account.rb b/lib/account.rb index 9ea2d9b9..c3df13af 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -10,6 +10,9 @@ def initialize (id, balance) end + def withdraw(money_to_withdraw) + @balance = @balance - money_to_withdraw + end end From 22f4fcf9731d1557f44f2725af04eeb83dd44631 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Tue, 21 Feb 2017 15:03:05 -0800 Subject: [PATCH 04/42] added deposit method --- lib/account.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index c3df13af..8e63573a 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -2,18 +2,20 @@ module Bank class Account - def initialize (id, balance) @id = id @balance = balance end - def withdraw(money_to_withdraw) @balance = @balance - money_to_withdraw end + def deposit(money_to_deposit) + @balance = @balance + money_to_deposit + end + end end From 8d3b6de8f6a0532522f9ebd1a2b856490d91fe91 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Tue, 21 Feb 2017 15:03:49 -0800 Subject: [PATCH 05/42] added balance attr_reader so balance can be accessed any time --- lib/account.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index 8e63573a..e63d74cf 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,6 +1,7 @@ module Bank - class Account + attr_reader :balance + class Account def initialize (id, balance) @id = id From abfe8f3b56d32ff783fb9113e1b51a032ba9e108 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Tue, 21 Feb 2017 15:04:35 -0800 Subject: [PATCH 06/42] updated attr_reader to go inside class Account --- lib/account.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index e63d74cf..1977df84 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,12 +1,12 @@ module Bank - attr_reader :balance class Account + attr_reader :balance + def initialize (id, balance) @id = id @balance = balance - end def withdraw(money_to_withdraw) From 69429f1b97a401ebcc0bb5fe4cee97f949b4cc3d Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Tue, 21 Feb 2017 15:09:39 -0800 Subject: [PATCH 07/42] added if/else statement in initialize to make sure initial balance is positive --- lib/account.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index 1977df84..ce252b12 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -6,7 +6,11 @@ class Account def initialize (id, balance) @id = id - @balance = balance + if balance > 0 + @balance = balance + else + raise ArgumentError.new "The initial balance must not be a negative number" + end end def withdraw(money_to_withdraw) From 16af257596245935afb3d952a149d7a32248033a Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Tue, 21 Feb 2017 15:20:26 -0800 Subject: [PATCH 08/42] updated if/else statement to include initial balances of 0 --- lib/account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index ce252b12..71790b49 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -6,7 +6,7 @@ class Account def initialize (id, balance) @id = id - if balance > 0 + if balance >= 0 @balance = balance else raise ArgumentError.new "The initial balance must not be a negative number" From 150a523f48346b271ecb819cd067fcb1c5ed177d Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Tue, 21 Feb 2017 15:30:01 -0800 Subject: [PATCH 09/42] added :id as a reader attribute --- lib/account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index 71790b49..34594a10 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -2,7 +2,7 @@ module Bank class Account - attr_reader :balance + attr_reader :id, :balance def initialize (id, balance) @id = id From 09f980aa54448c1e252a1352bf30e2742f908760 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Tue, 21 Feb 2017 16:02:22 -0800 Subject: [PATCH 10/42] added start and update balance local variables in withdraw method --- lib/account.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index 34594a10..de5f1182 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -14,7 +14,15 @@ def initialize (id, balance) end def withdraw(money_to_withdraw) - @balance = @balance - money_to_withdraw + if money_to_withdraw > @balance + puts "Amount to withdraw must be greater than balance" + start_balance = @balance + updated_balance = start_balance + else + start_balance = @balance + updated_balance = @balance - money_to_withdraw + @balance = updated_balance + end end def deposit(money_to_deposit) From ff4a4113a36389a6cd5ac5f98adab0a313eb1231 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Tue, 21 Feb 2017 16:06:35 -0800 Subject: [PATCH 11/42] added conditional to account for a withdraw amount that's negative --- lib/account.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index de5f1182..fe9ae58c 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -14,14 +14,18 @@ def initialize (id, balance) end def withdraw(money_to_withdraw) - if money_to_withdraw > @balance - puts "Amount to withdraw must be greater than balance" - start_balance = @balance - updated_balance = start_balance + if money_to_withdraw > 0 + if money_to_withdraw > @balance + puts "Amount to withdraw must be greater than balance" + start_balance = @balance + updated_balance = start_balance + else + start_balance = @balance + updated_balance = @balance - money_to_withdraw + @balance = updated_balance + end else - start_balance = @balance - updated_balance = @balance - money_to_withdraw - @balance = updated_balance + raise ArgumentError.new "The amount to withdraw must be greater than zero" end end From 8928a434ea3d49e5d4190747cffebbc7d3f5fbf3 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Tue, 21 Feb 2017 16:11:59 -0800 Subject: [PATCH 12/42] added conditional to deposit method to require amount greater than zero and also update the balance with the deposit amount --- lib/account.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index fe9ae58c..f89baca2 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -19,6 +19,7 @@ def withdraw(money_to_withdraw) puts "Amount to withdraw must be greater than balance" start_balance = @balance updated_balance = start_balance + @balance = updated_balance else start_balance = @balance updated_balance = @balance - money_to_withdraw @@ -30,7 +31,13 @@ def withdraw(money_to_withdraw) end def deposit(money_to_deposit) - @balance = @balance + money_to_deposit + if money_to_deposit > 0 + start_balance = @balance + updated_balance = start_balance + money_to_deposit + @balance = updated_balance + else + raise ArgumentError.new "The deposit amount must be greater than zero" + end end end From 52127dd3775b1f11142137ba1779ed45948e08af Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Tue, 21 Feb 2017 16:53:20 -0800 Subject: [PATCH 13/42] created an Owner class that takes in user info hashes --- lib/account.rb | 4 ++-- lib/owner.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 lib/owner.rb diff --git a/lib/account.rb b/lib/account.rb index f89baca2..0dd8c16c 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -14,8 +14,8 @@ def initialize (id, balance) end def withdraw(money_to_withdraw) - if money_to_withdraw > 0 - if money_to_withdraw > @balance + if money_to_withdraw > 0 #requires positive withdrawal amount + if money_to_withdraw > @balance #requires withdrawal amount less than balance puts "Amount to withdraw must be greater than balance" start_balance = @balance updated_balance = start_balance diff --git a/lib/owner.rb b/lib/owner.rb new file mode 100644 index 00000000..dee5b610 --- /dev/null +++ b/lib/owner.rb @@ -0,0 +1,18 @@ +module Bank + + class Owner + + attr_reader :name, :address, :account_type + + def initialize(owner_info_hash) + @name = owner_info_hash[:name] + @address = owner_info_hash[:address] + @account_type = owner_info_hash[:account_type] + end + end + +end + + +# Create an Owner class which will store information about those who own the Accounts. +# This should have info like name and address and any other identifying information that an account owner would have. From c5eda715e56983971fcd0dfa21d2e18b7980b1a4 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Tue, 21 Feb 2017 16:54:00 -0800 Subject: [PATCH 14/42] added test for initializing owner info --- specs/account_spec.rb | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 6c399139..9f720c47 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -2,6 +2,7 @@ require 'minitest/reporters' require 'minitest/skip_dsl' require_relative '../lib/account' +require_relative '../lib/owner' describe "Wave 1" do describe "Account#initialize" do @@ -33,8 +34,11 @@ 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) @@ -46,6 +50,7 @@ end it "Returns the modified balance" do + start_balance = 100.0 withdrawal_amount = 25.0 account = Bank::Account.new(1337, start_balance) @@ -57,6 +62,7 @@ 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) @@ -71,6 +77,7 @@ 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) @@ -84,6 +91,7 @@ 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 @@ -91,6 +99,7 @@ end it "Requires a positive withdrawal amount" do + start_balance = 100.0 withdrawal_amount = -25.0 account = Bank::Account.new(1337, start_balance) @@ -102,7 +111,9 @@ 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) @@ -114,6 +125,7 @@ end it "Returns the modified balance" do + start_balance = 100.0 deposit_amount = 25.0 account = Bank::Account.new(1337, start_balance) @@ -125,6 +137,7 @@ end it "Requires a positive deposit amount" do + start_balance = 100.0 deposit_amount = -25.0 account = Bank::Account.new(1337, start_balance) @@ -136,10 +149,37 @@ end end + +describe "Wave 1 - optional" do + + describe "Owner#initialize" do + it "takes owner info as hash" do + owner1_test = { :name => "Sally Mae", :address => "1234 Some Street, Seattle, WA 98144", :account_type => :checking } + new_owner = Bank::Owner.new(owner1_test) + + new_owner.must_respond_to :name + new_owner.name.must_equal owner1_test[:name] + + new_owner.must_respond_to :address + new_owner.address.must_equal owner1_test[:address] + + new_owner.must_respond_to :account_type + new_owner.account_type.must_equal owner1_test[:account_type] + 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 + skip # TODO: Your test code here! # Useful checks might include: # - Account.all returns an array @@ -151,20 +191,26 @@ end end + describe "Account.find" do + it "Returns an account that exists" do + skip # TODO: Your test code here! end it "Can find the first account from the CSV" do + skip # TODO: Your test code here! end it "Can find the last account from the CSV" do + skip # TODO: Your test code here! end it "Raises an error for an account that doesn't exist" do + skip # TODO: Your test code here! end end From 5641ef25efe372a7f5ba65d9d050dd8dc29a1086 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Wed, 22 Feb 2017 15:44:46 -0800 Subject: [PATCH 15/42] created Accounts.all class method and updated spec file to check for array. --- lib/account.rb | 57 +++++++++++++++++---- specs/account_spec.rb | 113 +++++++++++++++++++++++++++++++++--------- 2 files changed, 136 insertions(+), 34 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 0dd8c16c..46a0e4d9 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,30 +1,61 @@ +require 'csv' + module Bank class Account - attr_reader :id, :balance + attr_reader :id, :balance, :open_date - def initialize (id, balance) + def initialize (id, balance, open_date = nil) @id = id if balance >= 0 @balance = balance else raise ArgumentError.new "The initial balance must not be a negative number" end + + + # raise ArgumentError.new("The initial balance must not be a negative number") if balance < 0 + # + # @id = id + # @balance = balance + + # owner1 = Bank::Owner.new(owner) + + # @owner = owner + # @account = Accounts.all + # @owner = Bank::Owner.new(owner_info_hash) + # @owner_name = owner1.name + + + end + + def self.all + accounts = [] + CSV.open("../support/accounts.csv").each do |line| + id = line[0] + balance = line[1].to_i + open_date = line[2] + + new_account = Account.new(id, balance, open_date) + accounts << new_account + # accounts[ line[0] ] = line[1..-1] + # puts line + # accounts[line[0]] = line[1..-1] + + end + return accounts end + def withdraw(money_to_withdraw) if money_to_withdraw > 0 #requires positive withdrawal amount if money_to_withdraw > @balance #requires withdrawal amount less than balance puts "Amount to withdraw must be greater than balance" - start_balance = @balance - updated_balance = start_balance - @balance = updated_balance else - start_balance = @balance - updated_balance = @balance - money_to_withdraw - @balance = updated_balance + @balance -= money_to_withdraw end + return @balance else raise ArgumentError.new "The amount to withdraw must be greater than zero" end @@ -32,14 +63,18 @@ def withdraw(money_to_withdraw) def deposit(money_to_deposit) if money_to_deposit > 0 - start_balance = @balance - updated_balance = start_balance + money_to_deposit - @balance = updated_balance + # start_balance = @balance + # updated_balance = start_balance + money_to_deposit + @balance += money_to_deposit else raise ArgumentError.new "The deposit amount must be greater than zero" end end + # def add_owner + # + # end + end end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 9f720c47..f55a490f 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -5,10 +5,27 @@ require_relative '../lib/owner' describe "Wave 1" do + + # before do + # owner1_test = { :name => "Sally Mae", :address => "1234 Some Street, Seattle, WA 98144", :account_type => :checking } + # + # new_owner = Bank::Owner.new(owner1_test) + # end + describe "Account#initialize" do + + # before do + # owner1_test = { :name => "Sally Mae", :address => "1234 Some Street, Seattle, WA 98144", :account_type => :checking } + # + # new_owner = Bank::Owner.new(owner1_test) + # end + it "Takes an ID and an initial balance" do id = 1337 balance = 100.0 + # owner1_test = { :name => "Sally Mae", :address => "1234 Some Street, Seattle, WA 98144", :account_type => :checking } + # + # new_owner = Bank::Owner.new(owner1_test) account = Bank::Account.new(id, balance) account.must_respond_to :id @@ -16,9 +33,15 @@ account.must_respond_to :balance account.balance.must_equal balance + + # account.must_respond_to :owner + # account.owner.must_equal new_owner 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 @@ -29,6 +52,8 @@ 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 @@ -37,8 +62,15 @@ describe "Account#withdraw" do + # before do + # owner1_test = { :name => "Sally Mae", :address => "1234 Some Street, Seattle, WA 98144", :account_type => :checking } + # + # new_owner = Bank::Owner.new(owner1_test) + # end + it "Reduces the balance" do + start_balance = 100.0 withdrawal_amount = 25.0 account = Bank::Account.new(1337, start_balance) @@ -51,6 +83,7 @@ it "Returns the modified balance" do + start_balance = 100.0 withdrawal_amount = 25.0 account = Bank::Account.new(1337, start_balance) @@ -63,6 +96,7 @@ 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) @@ -78,6 +112,7 @@ 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) @@ -112,6 +147,13 @@ describe "Account#deposit" do + # before do + # owner1_test = { :name => "Sally Mae", :address => "1234 Some Street, Seattle, WA 98144", :account_type => :checking } + # + # new_owner = Bank::Owner.new(owner1_test) + # end + + it "Increases the balance" do start_balance = 100.0 @@ -149,40 +191,65 @@ end end +# +# describe "Wave 1 - optional" do +# +# describe "Owner#initialize" do +# it "takes owner info as hash" do +# owner1_test = { :name => "Sally Mae", :address => "1234 Some Street, Seattle, WA 98144", :account_type => :checking } +# new_owner = Bank::Owner.new(owner1_test) +# +# new_owner.must_respond_to :name +# new_owner.name.must_equal owner1_test[:name] +# +# new_owner.must_respond_to :address +# new_owner.address.must_equal owner1_test[:address] +# +# new_owner.must_respond_to :account_type +# new_owner.account_type.must_equal owner1_test[:account_type] +# end +# end +# +# describe "Account#initialize" do +# it "Takes an ID, initial balance, and owner_info" do +# id = 1337 +# balance = 100.0 +# owner2_test = { :name => "Jim Bob", :address => "5678 Some Street, Seattle, WA 98109", :account_type => :savings } +# 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 +# +# account.owner_name.must_respond_to :name +# acount.owner_name.must_equal Bank::Owner.name +# end +# end +# +# +# end -describe "Wave 1 - optional" do - describe "Owner#initialize" do - it "takes owner info as hash" do - owner1_test = { :name => "Sally Mae", :address => "1234 Some Street, Seattle, WA 98144", :account_type => :checking } - new_owner = Bank::Owner.new(owner1_test) - new_owner.must_respond_to :name - new_owner.name.must_equal owner1_test[:name] +# TODO: change 'xdescribe' to 'describe' to run these tests +describe "Wave 2" do - new_owner.must_respond_to :address - new_owner.address.must_equal owner1_test[:address] + describe "Account.all" do + it "Returns an array of all accounts" do - new_owner.must_respond_to :account_type - new_owner.account_type.must_equal owner1_test[:account_type] - end - end + # TODO: Your test code here! + # Useful checks might include: + # - Account.all returns an array -end + account_array = Bank::Account.all + account_array.class.must_equal Array -# 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 - skip - # 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 From d8d361ee3a88ac21a8f4dc0488a96a1629cc82af Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Wed, 22 Feb 2017 16:09:02 -0800 Subject: [PATCH 16/42] added test to check if eveverything in Array is an Account. Also created test to make sure the number of accounts is correct --- specs/account_spec.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index f55a490f..ed60ce79 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -244,15 +244,25 @@ # Useful checks might include: # - Account.all returns an array - - account_array = Bank::Account.all account_array.class.must_equal Array # - Everything in the array is an Account + + # account_array.each do |element| + # element.class + # end + + account_array[0].must_be_instance_of Bank::Account + + # - The number of accounts is correct + account_array.length.must_equal 12 + # - 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 From 78ec7a3dffc6b95e520278173e2805bcd55593a8 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Wed, 22 Feb 2017 16:21:34 -0800 Subject: [PATCH 17/42] added tests to check ID/balance of first and last elements --- specs/account_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index ed60ce79..5e6615d2 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -262,6 +262,17 @@ # - The ID and balance of the first and last + first_account_id = account_array[0].id + first_account_balance = account_array[0].balance + + first_account_id.must_equal "1212" + first_account_balance.must_equal 1235667 + + last_account_id = account_array[-1].id + last_account_balance = account_array[-1].balance + + last_account_id.must_equal "15156" + last_account_balance.must_equal 4356772 # accounts match what's in the CSV file # Feel free to split this into multiple tests if needed From f6805270a288bca43a514e585d73d991d6e43207 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Wed, 22 Feb 2017 16:28:48 -0800 Subject: [PATCH 18/42] created separate it/do's for each test --- specs/account_spec.rb | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 5e6615d2..15a7d4a2 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -235,6 +235,10 @@ # TODO: change 'xdescribe' to 'describe' to run these tests describe "Wave 2" do + before do + + @account_array = Bank::Account.all + end describe "Account.all" do it "Returns an array of all accounts" do @@ -244,39 +248,43 @@ # Useful checks might include: # - Account.all returns an array - account_array = Bank::Account.all - - account_array.class.must_equal Array - # - Everything in the array is an Account + @account_array.class.must_equal Array + end + # - Everything in the array is an Account - # account_array.each do |element| - # element.class - # end + # account_array.each do |element| + # element.class + # end - account_array[0].must_be_instance_of Bank::Account + it "Everything in array is an Account" do + @account_array[0].must_be_instance_of Bank::Account + end + it "The number of accounts matches number of lines in csv file" do # - The number of accounts is correct + @account_array.length.must_equal 12 + end - # - The number of accounts is correct - account_array.length.must_equal 12 + it "ID/balance of first and last accounts match csv file" do # - The ID and balance of the first and last + # accounts match what's in the CSV file - first_account_id = account_array[0].id - first_account_balance = account_array[0].balance + first_account_id = @account_array[0].id + first_account_balance = @account_array[0].balance first_account_id.must_equal "1212" first_account_balance.must_equal 1235667 - last_account_id = account_array[-1].id - last_account_balance = account_array[-1].balance + last_account_id = @account_array[-1].id + last_account_balance = @account_array[-1].balance last_account_id.must_equal "15156" last_account_balance.must_equal 4356772 + end - # accounts match what's in the CSV file # Feel free to split this into multiple tests if needed - end + end From d6a10e4176765194b3c5df9c75ca68933a35a5c5 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Wed, 22 Feb 2017 23:08:59 -0800 Subject: [PATCH 19/42] created Account.find class method and set up test to ensure it returns an exisiting account --- lib/account.rb | 16 ++++++++++++++++ specs/account_spec.rb | 15 +++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 46a0e4d9..8d73109a 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -48,6 +48,22 @@ def self.all end + def self.find(search_id) + # new_search = Account.all + match = nil + + Bank::Account.all.each do |account| + if account.id == search_id + match = search_id + break + else + match = nil + end + end + return match + + end + def withdraw(money_to_withdraw) if money_to_withdraw > 0 #requires positive withdrawal amount if money_to_withdraw > @balance #requires withdrawal amount less than balance diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 15a7d4a2..c0fd9276 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -258,8 +258,10 @@ # end it "Everything in array is an Account" do - @account_array[0].must_be_instance_of Bank::Account + @account_array.each do |element| + element.must_be_instance_of Bank::Account end + end it "The number of accounts matches number of lines in csv file" do # - The number of accounts is correct @account_array.length.must_equal 12 @@ -290,8 +292,17 @@ describe "Account.find" do + it "Returns an account that exists" do - skip + + + + # account_id = @account_array[3].id + # + + Bank::Account.find("1215").must_equal "1215" + + # TODO: Your test code here! end From 461974a30515984fbc27078d64c73a6fdad6cbe0 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Wed, 22 Feb 2017 23:12:44 -0800 Subject: [PATCH 20/42] added tests to ensure .find class method can find the first and last account from csv --- specs/account_spec.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index c0fd9276..0211f4e4 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -299,7 +299,6 @@ # account_id = @account_array[3].id # - Bank::Account.find("1215").must_equal "1215" @@ -307,12 +306,17 @@ end it "Can find the first account from the CSV" do - skip + + Bank::Account.find(Bank::Account.all[0].id).must_equal "1212" + + # TODO: Your test code here! end it "Can find the last account from the CSV" do - skip + + Bank::Account.find(Bank::Account.all[-1].id).must_equal "15156" + # TODO: Your test code here! end From 760a46bb82ce5e39728c26c37b53fb4a318feca0 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Wed, 22 Feb 2017 23:22:11 -0800 Subject: [PATCH 21/42] created test to check for accounts that don't exist and added code in accounts.rb to raise an error if there is an unexisting account passed in when using the .find class method --- lib/account.rb | 6 +++++- specs/account_spec.rb | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 8d73109a..35aadba1 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -60,7 +60,11 @@ def self.find(search_id) match = nil end end - return match + if match == nil + raise ArgumentError.new("There are no accounts with that ID") + else + return match + end end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 0211f4e4..edc9e665 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -321,7 +321,11 @@ end it "Raises an error for an account that doesn't exist" do - skip + + proc { + Bank::Account.find("00000") + }.must_raise ArgumentError + # TODO: Your test code here! end end From 1b8ec981ebec78bfca7dfe4e450a10bf94b74c8d Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Wed, 22 Feb 2017 23:25:00 -0800 Subject: [PATCH 22/42] refactored .find class method to get rid of if/else when raising argument error --- lib/account.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 35aadba1..e2b24554 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -60,11 +60,11 @@ def self.find(search_id) match = nil end end - if match == nil - raise ArgumentError.new("There are no accounts with that ID") - else - return match - end + + raise ArgumentError.new("There are no accounts with that ID") if match == nil + + return match + end From 4efca9d5bf40421e4405e76bb53783ccad022f2a Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Wed, 22 Feb 2017 23:30:44 -0800 Subject: [PATCH 23/42] refactored code in initialize, withdraw, and deposit methods to get rid of some if/else statements by putting raise ArgumentError first --- lib/account.rb | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index e2b24554..a1a13597 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -8,11 +8,10 @@ class Account def initialize (id, balance, open_date = nil) @id = id - if balance >= 0 - @balance = balance - else - raise ArgumentError.new "The initial balance must not be a negative number" - end + raise ArgumentError.new "The initial balance must not be a negative number" if balance < 0 + + @balance = balance + # raise ArgumentError.new("The initial balance must not be a negative number") if balance < 0 @@ -62,33 +61,28 @@ def self.find(search_id) end raise ArgumentError.new("There are no accounts with that ID") if match == nil - + return match end def withdraw(money_to_withdraw) - if money_to_withdraw > 0 #requires positive withdrawal amount - if money_to_withdraw > @balance #requires withdrawal amount less than balance + raise ArgumentError.new "The amount to withdraw must be greater than zero" if money_to_withdraw < 0 #requires positive withdrawal amount + if money_to_withdraw > @balance #requires withdrawal amount less than balance puts "Amount to withdraw must be greater than balance" - else - @balance -= money_to_withdraw - end - return @balance else - raise ArgumentError.new "The amount to withdraw must be greater than zero" + @balance -= money_to_withdraw end + return @balance end def deposit(money_to_deposit) - if money_to_deposit > 0 + raise ArgumentError.new "The deposit amount must be greater than zero" if money_to_deposit < 0 # start_balance = @balance # updated_balance = start_balance + money_to_deposit @balance += money_to_deposit - else - raise ArgumentError.new "The deposit amount must be greater than zero" - end + end # def add_owner From 21b764fb16f5e758be6055d249d04b3251cdf917 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Wed, 22 Feb 2017 23:34:41 -0800 Subject: [PATCH 24/42] refactored specs code to get rid of unnecessary variables, instead using 'Bank::Account.all' --- lib/account.rb | 2 +- specs/account_spec.rb | 36 +++++++++++++++++------------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index a1a13597..18718c59 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -6,7 +6,7 @@ class Account attr_reader :id, :balance, :open_date - def initialize (id, balance, open_date = nil) + def initialize(id, balance, open_date = nil) @id = id raise ArgumentError.new "The initial balance must not be a negative number" if balance < 0 diff --git a/specs/account_spec.rb b/specs/account_spec.rb index edc9e665..845ac1c1 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -235,10 +235,10 @@ # TODO: change 'xdescribe' to 'describe' to run these tests describe "Wave 2" do - before do - - @account_array = Bank::Account.all - end + # before do + # + # @account_array = Bank::Account.all + # end describe "Account.all" do it "Returns an array of all accounts" do @@ -249,7 +249,7 @@ # - Account.all returns an array - @account_array.class.must_equal Array + Bank::Account.all.class.must_equal Array end # - Everything in the array is an Account @@ -258,13 +258,13 @@ # end it "Everything in array is an Account" do - @account_array.each do |element| + Bank::Account.all.each do |element| element.must_be_instance_of Bank::Account + end end - end it "The number of accounts matches number of lines in csv file" do # - The number of accounts is correct - @account_array.length.must_equal 12 + Bank::Account.all.length.must_equal 12 end @@ -272,21 +272,21 @@ # - The ID and balance of the first and last # accounts match what's in the CSV file - first_account_id = @account_array[0].id - first_account_balance = @account_array[0].balance + first_account_id = Bank::Account.all[0].id + first_account_balance = Bank::Account.all[0].balance first_account_id.must_equal "1212" first_account_balance.must_equal 1235667 - last_account_id = @account_array[-1].id - last_account_balance = @account_array[-1].balance + last_account_id = Bank::Account.all[-1].id + last_account_balance = Bank::Account.all[-1].balance last_account_id.must_equal "15156" last_account_balance.must_equal 4356772 end - # Feel free to split this into multiple tests if needed - + # Feel free to split this into multiple tests if needed + end @@ -295,11 +295,9 @@ it "Returns an account that exists" do - - - # account_id = @account_array[3].id - # - Bank::Account.find("1215").must_equal "1215" + # account_id = @account_array[3].id + # + Bank::Account.find("1215").must_equal "1215" # TODO: Your test code here! From bc5e8cab114a34bd60a640d53a7693cf6df3308a Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Thu, 23 Feb 2017 10:12:02 -0800 Subject: [PATCH 25/42] refactored code back to add variable @account_array set to Bank::Account.all so that the file is read only once when tested. --- specs/account_spec.rb | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 845ac1c1..82faffb5 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -235,10 +235,10 @@ # TODO: change 'xdescribe' to 'describe' to run these tests describe "Wave 2" do - # before do - # - # @account_array = Bank::Account.all - # end + before do + + @account_array = Bank::Account.all + end describe "Account.all" do it "Returns an array of all accounts" do @@ -249,7 +249,7 @@ # - Account.all returns an array - Bank::Account.all.class.must_equal Array + @account_array.class.must_equal Array end # - Everything in the array is an Account @@ -258,13 +258,15 @@ # end it "Everything in array is an Account" do - Bank::Account.all.each do |element| + @account_array.each do |element| element.must_be_instance_of Bank::Account end end it "The number of accounts matches number of lines in csv file" do # - The number of accounts is correct - Bank::Account.all.length.must_equal 12 + @account_array.length.must_equal 12 + + # @accounts.length.must_equal CSV.read("support/accounts.csv").length end @@ -272,26 +274,30 @@ # - The ID and balance of the first and last # accounts match what's in the CSV file - first_account_id = Bank::Account.all[0].id - first_account_balance = Bank::Account.all[0].balance + first_account_id = @account_array[0].id + first_account_balance = @account_array[0].balance first_account_id.must_equal "1212" first_account_balance.must_equal 1235667 - last_account_id = Bank::Account.all[-1].id - last_account_balance = Bank::Account.all[-1].balance + last_account_id = @account_array[-1].id + last_account_balance = @account_array[-1].balance last_account_id.must_equal "15156" last_account_balance.must_equal 4356772 end # Feel free to split this into multiple tests if needed - + end describe "Account.find" do + before do + + @account_array = Bank::Account.all + end it "Returns an account that exists" do @@ -305,7 +311,7 @@ it "Can find the first account from the CSV" do - Bank::Account.find(Bank::Account.all[0].id).must_equal "1212" + Bank::Account.find(@account_array[0].id).must_equal "1212" # TODO: Your test code here! @@ -313,7 +319,7 @@ it "Can find the last account from the CSV" do - Bank::Account.find(Bank::Account.all[-1].id).must_equal "15156" + Bank::Account.find(@account_array[-1].id).must_equal "15156" # TODO: Your test code here! end From b034bd12fb4c43c1ef84989a87023583b5ba22f3 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Thu, 23 Feb 2017 12:58:42 -0800 Subject: [PATCH 26/42] created class files for SavingsAccount and CheckingAccount --- lib/checkingaccount.rb | 5 +++++ lib/savingsaccount.rb | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 lib/checkingaccount.rb create mode 100644 lib/savingsaccount.rb diff --git a/lib/checkingaccount.rb b/lib/checkingaccount.rb new file mode 100644 index 00000000..772f14f6 --- /dev/null +++ b/lib/checkingaccount.rb @@ -0,0 +1,5 @@ +class CheckingAccount < Bank::Account + + + +end diff --git a/lib/savingsaccount.rb b/lib/savingsaccount.rb new file mode 100644 index 00000000..f07d6661 --- /dev/null +++ b/lib/savingsaccount.rb @@ -0,0 +1,4 @@ +class SavingsAccount < Bank::Account + + +end From 240f03e9a138a3c540fb4ef36bad2c107edae449 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Thu, 23 Feb 2017 19:52:45 -0800 Subject: [PATCH 27/42] changed file name to savings_account.rb and added initialize super --- lib/checkingaccount.rb | 2 ++ lib/savings_account.rb | 22 ++++++++++++++++++++++ lib/savingsaccount.rb | 4 ---- specs/savings_account_spec.rb | 12 +++++++++++- 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 lib/savings_account.rb delete mode 100644 lib/savingsaccount.rb diff --git a/lib/checkingaccount.rb b/lib/checkingaccount.rb index 772f14f6..2735eb23 100644 --- a/lib/checkingaccount.rb +++ b/lib/checkingaccount.rb @@ -2,4 +2,6 @@ class CheckingAccount < Bank::Account + + end diff --git a/lib/savings_account.rb b/lib/savings_account.rb new file mode 100644 index 00000000..bdbeddfd --- /dev/null +++ b/lib/savings_account.rb @@ -0,0 +1,22 @@ +require 'account' +require 'csv' + +module Bank + + class SavingsAccount < Bank::Account + + def initialize(id, balance, open_date = nil) + super(id, balance, open_date = nil) + raise ArgumentError.new "The initial balance must not be less than 10" if balance < 10 + end + + end +end + + +# Create a SavingsAccount class which should inherit behavior from the Account class. It should include the following updated functionality: +# +# The initial balance cannot be less than $10. If it is, this will raise an ArgumentError +# Updated withdrawal functionality: +# Each withdrawal 'transaction' incurs a fee of $2 that is taken out of the balance. +# Does not allow the account to go below the $10 minimum balance - Will output a warning message and return the original un-modified balance diff --git a/lib/savingsaccount.rb b/lib/savingsaccount.rb deleted file mode 100644 index f07d6661..00000000 --- a/lib/savingsaccount.rb +++ /dev/null @@ -1,4 +0,0 @@ -class SavingsAccount < Bank::Account - - -end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 3f4d1e4a..fce4dcc3 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -1,17 +1,19 @@ 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 # 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 "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 @@ -20,38 +22,46 @@ end it "Requires an initial balance of at least $10" do + skip # TODO: Your test code here! end end describe "#withdraw" do it "Applies a $2 fee each time" do + skip # TODO: Your test code here! end it "Outputs a warning if the balance would go below $10" do + skip # TODO: Your test code here! end it "Doesn't modify the balance if it would go below $10" do + skip # TODO: Your test code here! end it "Doesn't modify the balance if the fee would put it below $10" do + skip # TODO: Your test code here! end end describe "#add_interest" do it "Returns the interest calculated" do + skip # TODO: Your test code here! end it "Updates the balance with calculated interest" do + skip # TODO: Your test code here! end it "Requires a positive rate" do + skip # TODO: Your test code here! end end From e9b3eb7a21ccc27dcd73c466cf6f6c065918310a Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Thu, 23 Feb 2017 20:42:51 -0800 Subject: [PATCH 28/42] added 'require_relative 'account'' and also added conditionals and super to withdraw method in SavingsAccount --- lib/savings_account.rb | 15 +++++++++-- specs/savings_account_spec.rb | 50 ++++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index bdbeddfd..1749d720 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -1,15 +1,26 @@ -require 'account' +require_relative 'account' require 'csv' module Bank - class SavingsAccount < Bank::Account + class SavingsAccount < Account def initialize(id, balance, open_date = nil) super(id, balance, open_date = nil) raise ArgumentError.new "The initial balance must not be less than 10" if balance < 10 end + def withdraw(money_to_withdraw) + if @balance - money_to_withdraw < 10 + puts "Warning! This withdrawal will put you under the $10 account minimum!" + return @balance + else + super(money_to_withdraw) + return @balance -= 2.0 + end + end + + end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index fce4dcc3..ea4bef7f 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -22,29 +22,67 @@ end it "Requires an initial balance of at least $10" do - skip + # account = Bank::SavingsAccount.new(3453, 8) + # TODO: Your test code here! + proc { + Bank::SavingsAccount.new(1337, 4.0) + }.must_raise ArgumentError + end end describe "#withdraw" do it "Applies a $2 fee each time" do - skip + start_balance = 300.0 + withdrawal_amount = 120.0 + account = Bank::SavingsAccount.new(12345, start_balance) + + account.withdraw(withdrawal_amount) + + + expected_balance = start_balance - withdrawal_amount - 2.0 + account.balance.must_equal expected_balance # TODO: Your test code here! end it "Outputs a warning if the balance would go below $10" do - skip + start_balance = 300.0 + withdrawal_amount = 291.0 + account = Bank::SavingsAccount.new(1234, start_balance) + + # account.withdraw(withdrawal_amount) + + proc { + account.withdraw(withdrawal_amount) + }.must_output /.+/ + + # TODO: Your test code here! end it "Doesn't modify the balance if it would go below $10" do - skip - # TODO: Your test code here! + # TODO: Your test code here! + start_balance = 300.0 + withdrawal_amount = 291.0 + account = Bank::SavingsAccount.new(1234, start_balance) + updated_balance = account.withdraw(withdrawal_amount) + + updated_balance.must_equal start_balance + account.balance.must_equal start_balance + end it "Doesn't modify the balance if the fee would put it below $10" do - skip + + start_balance = 300.0 + withdrawal_amount = 289.0 + account = Bank::SavingsAccount.new(1234, start_balance) + updated_balance = account.withdraw(withdrawal_amount) + + updated_balance.must_equal start_balance + account.balance.must_equal start_balance + # TODO: Your test code here! end end From 2b8a2b8f01b0c5650d938e916311c25ce8dbd73a Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Thu, 23 Feb 2017 20:44:32 -0800 Subject: [PATCH 29/42] adjusted withdraw method to account for withdrawals that will put account under with the transaction fee --- lib/savings_account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 1749d720..3ec0c4a4 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -11,7 +11,7 @@ def initialize(id, balance, open_date = nil) end def withdraw(money_to_withdraw) - if @balance - money_to_withdraw < 10 + if @balance - (money_to_withdraw + 2) < 10 puts "Warning! This withdrawal will put you under the $10 account minimum!" return @balance else From 352a57655e5345cedc3f8b3d88e5917c21a2c655 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Thu, 23 Feb 2017 20:55:33 -0800 Subject: [PATCH 30/42] added add_interest method to SavingsAccount and created test --- lib/savings_account.rb | 7 +++++++ specs/savings_account_spec.rb | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 3ec0c4a4..3054baf3 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -8,6 +8,7 @@ class SavingsAccount < Account def initialize(id, balance, open_date = nil) super(id, balance, open_date = nil) raise ArgumentError.new "The initial balance must not be less than 10" if balance < 10 + @interest end def withdraw(money_to_withdraw) @@ -20,6 +21,12 @@ def withdraw(money_to_withdraw) end end + def add_interest(rate) + @interest = balance * rate / 100 + + + + end end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index ea4bef7f..4edb38ad 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -89,12 +89,18 @@ describe "#add_interest" do it "Returns the interest calculated" do - skip + account = Bank::SavingsAccount.new(1234, 120) + + interest = account.add_interest(25.0) + + interest.must_equal 30 + # TODO: Your test code here! end it "Updates the balance with calculated interest" do - skip + + # TODO: Your test code here! end From f06688fc573a7b5758724456e1d8598ea3708735 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Thu, 23 Feb 2017 21:02:51 -0800 Subject: [PATCH 31/42] restructured add_interest rate and test to only show interest rate --- lib/savings_account.rb | 4 +--- specs/savings_account_spec.rb | 7 ++++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 3054baf3..377cf128 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -4,7 +4,7 @@ module Bank class SavingsAccount < Account - + attr_reader :interest def initialize(id, balance, open_date = nil) super(id, balance, open_date = nil) raise ArgumentError.new "The initial balance must not be less than 10" if balance < 10 @@ -24,8 +24,6 @@ def withdraw(money_to_withdraw) def add_interest(rate) @interest = balance * rate / 100 - - end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 4edb38ad..313cf451 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -91,15 +91,16 @@ it "Returns the interest calculated" do account = Bank::SavingsAccount.new(1234, 120) - interest = account.add_interest(25.0) + balance_with_interest = account.add_interest(25.0) - interest.must_equal 30 + + account.interest.must_equal 30 # TODO: Your test code here! end it "Updates the balance with calculated interest" do - + # TODO: Your test code here! end From ec2bcdfabbd1aa81333c133511da0900666b66bf Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Thu, 23 Feb 2017 21:25:16 -0800 Subject: [PATCH 32/42] adjusted test to check for only interest added on add_interest method --- lib/savings_account.rb | 12 +++++++++--- specs/savings_account_spec.rb | 22 +++++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 377cf128..f4333c8a 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -4,11 +4,11 @@ module Bank class SavingsAccount < Account - attr_reader :interest + attr_reader :calculated_interest def initialize(id, balance, open_date = nil) super(id, balance, open_date = nil) raise ArgumentError.new "The initial balance must not be less than 10" if balance < 10 - @interest + @calculated_interest = 0 end def withdraw(money_to_withdraw) @@ -22,10 +22,16 @@ def withdraw(money_to_withdraw) end def add_interest(rate) - @interest = balance * rate / 100 + @calculated_interest = balance * rate / 100 + @balance += @calculated_interest + return @calculated_interest end + # def calculate_interest(rate) + # @calculated_interest = balance * rate / 100 + # end + end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 313cf451..72393f2f 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -89,17 +89,33 @@ describe "#add_interest" do it "Returns the interest calculated" do - account = Bank::SavingsAccount.new(1234, 120) + start_balance = 120 + account = Bank::SavingsAccount.new(1234, start_balance) + + rate = 25.0 + interest = start_balance * rate / 100 - balance_with_interest = account.add_interest(25.0) + # balance_with_interest = account.add_interest(25.0) - account.interest.must_equal 30 + account.add_interest(25.0).must_equal interest # TODO: Your test code here! end it "Updates the balance with calculated interest" do + # skip + # start_balance = 120 + # + # account = Bank::SavingsAccount.new(1234, start_balance) + # account.interest = 25.0 + # + # balance_with_interest = start_balance + account.interest + # + # balance_with_interest = account.add_interest(25.0) + # + account.add_interest(25.0).must_equal balance_with_interest + account.balance.must_equal balance_with_interest # TODO: Your test code here! From 62f197ab25e021bc988deff65d0369ac594dab00 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Thu, 23 Feb 2017 21:31:31 -0800 Subject: [PATCH 33/42] created test to make sure add_interest updates balance with the calculated interest --- specs/savings_account_spec.rb | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 72393f2f..3e735517 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -104,18 +104,17 @@ end it "Updates the balance with calculated interest" do - # skip - # start_balance = 120 - # - # account = Bank::SavingsAccount.new(1234, start_balance) - # account.interest = 25.0 - # - # balance_with_interest = start_balance + account.interest - # - # balance_with_interest = account.add_interest(25.0) - # - account.add_interest(25.0).must_equal balance_with_interest - account.balance.must_equal balance_with_interest + + start_balance = 120 + + account = Bank::SavingsAccount.new(1234, start_balance) + + rate = 25.0 + interest = account.add_interest(rate) + + account.calculated_interest.must_equal 30 + account.balance.must_equal start_balance + interest + account.balance.must_equal 150 # TODO: Your test code here! From 945477babe04ca8b0839494f3d9eba6e7a0a434b Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Fri, 24 Feb 2017 11:29:52 -0800 Subject: [PATCH 34/42] created CheckingAccount subclass with updated withdraw method. Added test to check for CheckingAccount and to see if withdrawing incurs fee --- lib/checking_account.rb | 29 +++++++++++++++++++++++++++++ lib/checkingaccount.rb | 7 ------- lib/savings_account.rb | 6 ++++-- specs/checking_account_spec.rb | 12 ++++++++++-- specs/savings_account_spec.rb | 14 ++++++++++++-- 5 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 lib/checking_account.rb delete mode 100644 lib/checkingaccount.rb diff --git a/lib/checking_account.rb b/lib/checking_account.rb new file mode 100644 index 00000000..9c951cda --- /dev/null +++ b/lib/checking_account.rb @@ -0,0 +1,29 @@ +require_relative 'account' +require 'csv' + +module Bank + class CheckingAccount < Account + + + def withdraw(withdrawal_amount) + if @balance - (withdrawal_amount + 2) < 10 + puts "Warning! This withdrawal will put you under the $10 account minimum!" + return @balance + else + super(withdrawal_amount) + return @balance -= 1.0 + end + end + + end +end + +# Create a CheckingAccount class which should inherit behavior from the Account class. It should include the following updated functionality: +# +# Updated withdrawal functionality: +# Each withdrawal 'transaction' incurs a fee of $1 that is taken out of the balance. Returns the updated account balance. +# Does not allow the account to go negative. Will output a warning message and return the original un-modified balance. +# #withdraw_using_check(amount): The input amount gets taken out of the account as a result of a check withdrawal. Returns the updated account balance. +# Allows the account to go into overdraft up to -$10 but not any lower +# The user is allowed three free check uses in one month, but any subsequent use adds a $2 transaction fee +# #reset_checks: Resets the number of checks used to zero diff --git a/lib/checkingaccount.rb b/lib/checkingaccount.rb deleted file mode 100644 index 2735eb23..00000000 --- a/lib/checkingaccount.rb +++ /dev/null @@ -1,7 +0,0 @@ -class CheckingAccount < Bank::Account - - - - - -end diff --git a/lib/savings_account.rb b/lib/savings_account.rb index f4333c8a..ebb37052 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -4,11 +4,12 @@ module Bank class SavingsAccount < Account - attr_reader :calculated_interest + attr_accessor :calculated_interest + def initialize(id, balance, open_date = nil) super(id, balance, open_date = nil) raise ArgumentError.new "The initial balance must not be less than 10" if balance < 10 - @calculated_interest = 0 + @calculated_interest = nil end def withdraw(money_to_withdraw) @@ -22,6 +23,7 @@ def withdraw(money_to_withdraw) end def add_interest(rate) + raise ArgumentError.new("interest rate must be greater than 0") if rate < 0 @calculated_interest = balance * rate / 100 @balance += @calculated_interest return @calculated_interest diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 7f95339e..a86b83cb 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -3,7 +3,7 @@ require 'minitest/skip_dsl' # TODO: uncomment the next line once you start wave 3 and add lib/checking_account.rb -# require_relative '../lib/checking_account' +require_relative '../lib/checking_account' # Because a CheckingAccount is a kind # of Account, and we've already tested a bunch of functionality @@ -11,7 +11,7 @@ # Here we'll only test things that are different. # TODO: change 'xdescribe' to 'describe' to run these tests -xdescribe "CheckingAccount" do +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,6 +23,14 @@ describe "#withdraw" do it "Applies a $1 fee each time" do # TODO: Your test code here! + start_balance = 100.0 + account = Bank::CheckingAccount.new(12345, start_balance) + withdraw_amount = 25 + updated_balance = account.withdraw(withdraw_amount) + + updated_balance.must_equal (start_balance - (withdraw_amount + 1)) + + end it "Doesn't modify the balance if the fee would put it negative" do diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 3e735517..43bc9847 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -112,7 +112,8 @@ rate = 25.0 interest = account.add_interest(rate) - account.calculated_interest.must_equal 30 + interest.must_equal 30 + account.calculated_interest.must_equal interest account.balance.must_equal start_balance + interest account.balance.must_equal 150 @@ -121,7 +122,16 @@ end it "Requires a positive rate" do - skip + + start_balance = 120 + + account = Bank::SavingsAccount.new(1234, start_balance) + + proc { + account.add_interest(-0.35) + }.must_raise ArgumentError + + # TODO: Your test code here! end end From fa780e15245e1b66d5e20a1099f2609e0c805179 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Fri, 24 Feb 2017 11:45:15 -0800 Subject: [PATCH 35/42] added test to make sure balance is not modified if fee would put it negative --- lib/checking_account.rb | 4 ++-- specs/checking_account_spec.rb | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 9c951cda..f9ab362d 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -6,8 +6,8 @@ class CheckingAccount < Account def withdraw(withdrawal_amount) - if @balance - (withdrawal_amount + 2) < 10 - puts "Warning! This withdrawal will put you under the $10 account minimum!" + if @balance - (withdrawal_amount + 1) < 0 + puts "Warning! This withdrawal will cause you to overdraft!" return @balance else super(withdrawal_amount) diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index a86b83cb..384e3748 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -30,11 +30,19 @@ updated_balance.must_equal (start_balance - (withdraw_amount + 1)) - end it "Doesn't modify the balance if the fee would put it negative" do # TODO: Your test code here! + + start_balance = 100.0 + account = Bank::CheckingAccount.new(12345, start_balance) + withdraw_amount = 100 + updated_balance = account.withdraw(withdraw_amount) + + updated_balance.must_equal start_balance + account.balance.must_equal start_balance + end end From 4dd4b1c560531dec5a714cc82057cf215b0a506b Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Fri, 24 Feb 2017 11:57:17 -0800 Subject: [PATCH 36/42] wrote test to check if withdraw_using check reduces balance. Added method withdraw using check, adding stipulations of when account goes under himBH10 --- lib/checking_account.rb | 10 ++++++++++ specs/checking_account_spec.rb | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index f9ab362d..c4f0c75b 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -15,6 +15,16 @@ def withdraw(withdrawal_amount) end end + def withdraw_using_check(check) + if @balance - (check) < -10 + puts "Warning! This withdrawal will cause you to be under more than ten dollars!" + return @balance + else + return @balance - check + end + + end + end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 384e3748..4244e472 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -49,6 +49,14 @@ describe "#withdraw_using_check" do it "Reduces the balance" do # TODO: Your test code here! + start_balance = 100.0 + account = Bank::CheckingAccount.new(1235, start_balance) + check_amount = 80 + updated_balance = account.withdraw_using_check(check_amount) + + updated_balance.must_equal (start_balance - check_amount) + updated_balance.must_equal 20 + end it "Returns the modified balance" do From 826af7cef5ce05871f0eed2298808585f5d098ea Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Fri, 24 Feb 2017 12:07:42 -0800 Subject: [PATCH 37/42] wrote test to make sure withdraw_check method returns modified balance. refactored code to make sure balance actually updates after running methods. --- lib/checking_account.rb | 12 +++++++----- specs/checking_account_spec.rb | 8 ++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index c4f0c75b..02bb9fdd 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -8,21 +8,23 @@ class CheckingAccount < Account def withdraw(withdrawal_amount) if @balance - (withdrawal_amount + 1) < 0 puts "Warning! This withdrawal will cause you to overdraft!" - return @balance + # return @balance else super(withdrawal_amount) - return @balance -= 1.0 + @balance -= 1.0 end + return @balance + end def withdraw_using_check(check) if @balance - (check) < -10 puts "Warning! This withdrawal will cause you to be under more than ten dollars!" - return @balance + # return @balance else - return @balance - check + @balance -= check end - + return @balance end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 4244e472..ba0b33c7 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -61,6 +61,14 @@ it "Returns the modified balance" do # TODO: Your test code here! + + start_balance = 100.0 + account = Bank::CheckingAccount.new(1235, start_balance) + check_amount = 80 + updated_balance = account.withdraw_using_check(check_amount) + + account.balance.must_equal updated_balance + account.balance.must_equal (start_balance - check_amount) end it "Allows the balance to go down to -$10" do From 2376c12934442211cdb10944960c3aba1aa4879c Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Fri, 24 Feb 2017 12:11:15 -0800 Subject: [PATCH 38/42] created test to make sure method allows withdrawing checks that puts account down to negative 10 dollars --- specs/checking_account_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index ba0b33c7..ee3f08c8 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -73,6 +73,15 @@ it "Allows the balance to go down to -$10" do # TODO: Your test code here! + start_balance = 100.0 + account = Bank::CheckingAccount.new(1235, start_balance) + check_amount = 110.00 + updated_balance = account.withdraw_using_check(check_amount) + + account.balance.must_equal updated_balance + account.balance.must_equal (start_balance - check_amount) + account.balance.must_equal -10 + end it "Outputs a warning if the account would go below -$10" do From 4f7eff086a72b9af650a7790cc727e9124e7b2ec Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Fri, 24 Feb 2017 12:15:23 -0800 Subject: [PATCH 39/42] added test to see if method outputs warning if account goes below negative ten --- specs/checking_account_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index ee3f08c8..623e805a 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -86,6 +86,15 @@ it "Outputs a warning if the account would go below -$10" do # TODO: Your test code here! + + start_balance = 100.0 + account = Bank::CheckingAccount.new(1235, start_balance) + check_amount = 110.01 + # updated_balance = account.withdraw_using_check(check_amount) + + proc { account.withdraw_using_check(check_amount)}.must_output /.+/ + + end it "Doesn't modify the balance if the account would go below -$10" do From b1fbb50d424530a0e44940e4c4b991f5c3927088 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Fri, 24 Feb 2017 12:19:47 -0800 Subject: [PATCH 40/42] added test and code to make sure check is a positive number --- lib/checking_account.rb | 1 + specs/checking_account_spec.rb | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 02bb9fdd..546338db 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -18,6 +18,7 @@ def withdraw(withdrawal_amount) end def withdraw_using_check(check) + raise ArgumentError.new("Check cannot be a negative amount") if check < 0 if @balance - (check) < -10 puts "Warning! This withdrawal will cause you to be under more than ten dollars!" # return @balance diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 623e805a..01bc3f0d 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -94,15 +94,30 @@ proc { account.withdraw_using_check(check_amount)}.must_output /.+/ - end it "Doesn't modify the balance if the account would go below -$10" do # TODO: Your test code here! + start_balance = 100.0 + account = Bank::CheckingAccount.new(1235, start_balance) + check_amount = 110.01 + updated_balance = account.withdraw_using_check(check_amount) + + updated_balance.must_equal start_balance + end it "Requires a positive withdrawal amount" do # TODO: Your test code here! + + start_balance = 100.0 + account = Bank::CheckingAccount.new(1235, start_balance) + check_amount = -10 + # updated_balance = account.withdraw_using_check(check_amount) + + # updated_balance.must_equal start_balance + proc { account.withdraw_using_check(check_amount)}.must_raise ArgumentError + end it "Allows 3 free uses" do From 16f2c499e24eac00c8dd02ccad05f06c0d792c4b Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Fri, 24 Feb 2017 14:35:55 -0800 Subject: [PATCH 41/42] created tests to allow three free checks and then apply 2 dollar fee after. Also created extra conditional in method to account for three free checks --- lib/checking_account.rb | 30 +++++++++++++++++++++++++----- specs/checking_account_spec.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 546338db..b5cb3aeb 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -3,6 +3,11 @@ module Bank class CheckingAccount < Account + attr_reader :check_count + def initialize(id, balance, open_date = nil) + super + @check_count = 1 + end def withdraw(withdrawal_amount) @@ -19,13 +24,28 @@ def withdraw(withdrawal_amount) def withdraw_using_check(check) raise ArgumentError.new("Check cannot be a negative amount") if check < 0 - if @balance - (check) < -10 - puts "Warning! This withdrawal will cause you to be under more than ten dollars!" - # return @balance + if @check_count < 4 + if (@balance - check) < -10 + puts "Warning! This withdrawal will cause you to be under more than ten dollars!" + # return @balance + + return @balance + else + @check_count += 1 + @balance -= check + end + else - @balance -= check + if (@balance - (check + 2.0)) < -10 + puts "Warning! This withdrawal will cause you to be under more than ten dollars!" + return @balance + else + @check_count += 1 + @balance = @balance - check - 2.0 + end + end - return @balance + end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 01bc3f0d..2a4cf8d5 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -122,10 +122,36 @@ it "Allows 3 free uses" do # TODO: Your test code here! + + start_balance = 100.0 + account = Bank::CheckingAccount.new(1235, start_balance) + check1 = 10 + check2 = 20 + check3 = 40 + # check4 = 5 + + account.withdraw_using_check(check1).must_equal 90 + account.withdraw_using_check(check2).must_equal 70 + account.withdraw_using_check(check3).must_equal 30 + end it "Applies a $2 fee after the third use" do # TODO: Your test code here! + start_balance = 100.0 + account = Bank::CheckingAccount.new(1235, start_balance) + check1 = 10 + check2 = 20 + check3 = 40 + check4 = 5 + + account.withdraw_using_check(check1).must_equal 90 + account.withdraw_using_check(check2).must_equal 70 + account.withdraw_using_check(check3).must_equal 30 + account.withdraw_using_check(check4).must_equal 23 + # account.check_count.must_equal + # account.withdraw_using_check(check4).must_equal 23 + end end From 87242c6373a845f393ce03e6d31a8aa09761cd16 Mon Sep 17 00:00:00 2001 From: Jackie Watanabe Date: Fri, 24 Feb 2017 15:01:13 -0800 Subject: [PATCH 42/42] created tests to check reset checks method. created method to reset check count. --- lib/checking_account.rb | 8 ++-- specs/checking_account_spec.rb | 74 +++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 5 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index b5cb3aeb..ff2b59ac 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -6,7 +6,7 @@ class CheckingAccount < Account attr_reader :check_count def initialize(id, balance, open_date = nil) super - @check_count = 1 + @check_count = 0 end @@ -24,7 +24,7 @@ def withdraw(withdrawal_amount) def withdraw_using_check(check) raise ArgumentError.new("Check cannot be a negative amount") if check < 0 - if @check_count < 4 + if @check_count < 3 if (@balance - check) < -10 puts "Warning! This withdrawal will cause you to be under more than ten dollars!" # return @balance @@ -43,9 +43,11 @@ def withdraw_using_check(check) @check_count += 1 @balance = @balance - check - 2.0 end - end + end + def reset_checks + @check_count = 0 end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 2a4cf8d5..13a4f254 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -149,8 +149,7 @@ account.withdraw_using_check(check2).must_equal 70 account.withdraw_using_check(check3).must_equal 30 account.withdraw_using_check(check4).must_equal 23 - # account.check_count.must_equal - # account.withdraw_using_check(check4).must_equal 23 + end end @@ -158,13 +157,84 @@ describe "#reset_checks" do it "Can be called without error" do # TODO: Your test code here! + + start_balance = 100.0 + account = Bank::CheckingAccount.new(1235, start_balance) + check1 = 10 + check2 = 20 + check3 = 40 + check4 = 5 + + account.withdraw_using_check(check1) + + account.check_count.must_equal 1 + account.withdraw_using_check(check2) + account.check_count.must_equal 2 + + account.reset_checks + account.check_count.must_equal 0 + end it "Makes the next three checks free if less than 3 checks had been used" do # TODO: Your test code here! + + start_balance = 100.0 + account = Bank::CheckingAccount.new(1235, start_balance) + check1 = 5 + check2 = 10 + check3 = 10 + check4 = 5 + check5 = 3 + check6 = 2 + + account.withdraw_using_check(check1) + account.withdraw_using_check(check2) + account.reset_checks + account.withdraw_using_check(check3) + account.withdraw_using_check(check4) + account.withdraw_using_check(check5).must_equal 67 + account.withdraw_using_check(check6).must_equal 63 + + account.check_count.must_equal 4 end it "Makes the next three checks free if more than 3 checks had been used" do + + start_balance = 100.0 + account = Bank::CheckingAccount.new(1235, start_balance) + check1 = 5 + check2 = 10 + check3 = 10 + check4 = 5 + check5 = 3 + check6 = 2 + check7 = 4 + check8 = 11 + + + account.withdraw_using_check(check1) + account.withdraw_using_check(check2) + account.withdraw_using_check(check3) + account.withdraw_using_check(check4) + + account.balance.must_equal 68 + account.check_count.must_equal 4 + + account.reset_checks + + account.check_count.must_equal 0 + + account.withdraw_using_check(check5) + account.withdraw_using_check(check6) + account.withdraw_using_check(check7) + + account.balance.must_equal 59 + account.check_count.must_equal 3 + + account.withdraw_using_check(check8) + account.balance.must_equal 46 + # TODO: Your test code here! end end