From b092c16f6f9deb9ac0fe3b151947368bfbfe36d7 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Tue, 21 Feb 2017 17:36:08 -0800 Subject: [PATCH 01/32] sets up initial structure of module and class --- lib/account.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/account.rb b/lib/account.rb index e69de29b..6a8981f5 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -0,0 +1,24 @@ +module Bank + class Account + attr_reader :id, :balance + def initialize (id, balance) + @id + @balance + end + + def show_balance + return @balance + puts "its working" + + end + + + + + + end + +end + +my_account = Bank::Account.new(16, 1000) +puts my_account.show_balance From a7faa32a455ab0697ae049afe23c5647aef771ed Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Tue, 21 Feb 2017 17:55:48 -0800 Subject: [PATCH 02/32] adds show balance method and verifies that new objects are being instantiated --- lib/account.rb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 6a8981f5..5c417c6e 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,24 +1,20 @@ + module Bank class Account - attr_reader :id, :balance + attr_accessor :id, :balance + def initialize (id, balance) - @id - @balance + @id = id + @balance = balance end def show_balance - return @balance - puts "its working" - + puts "Your balance is: $#{@balance}" end - - - - end end my_account = Bank::Account.new(16, 1000) -puts my_account.show_balance +my_account.show_balance From 8f64dba5d8322a38ebb1de2c76230e4325ba873d Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Tue, 21 Feb 2017 18:14:27 -0800 Subject: [PATCH 03/32] working withdraw method, needs to be tested with spec file --- lib/account.rb | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 5c417c6e..6fb1a282 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,13 +1,36 @@ module Bank class Account - attr_accessor :id, :balance + attr_accessor :id, :balance, :withdraw def initialize (id, balance) + #need to call a method here that checks if balance is > 0; argument error @id = id @balance = balance + @withdraw end + def withdraw (withdraw_amount) + @withdraw = withdraw_amount + if @balance - @withdraw > 0 + puts "Here's your cash" + @balance = @balance - @withdraw + puts "Your new balance is: $#{@balance}" + else + puts "you do not have enough money in your account for this" + end + end + + def deposit + #make sure positive + #adjust balance + end + + def new_account_check + #make sure that new accounts are not started with negative balance + end + + def show_balance puts "Your balance is: $#{@balance}" end @@ -17,4 +40,5 @@ def show_balance end my_account = Bank::Account.new(16, 1000) -my_account.show_balance +# my_account.show_balance +my_account.withdraw(200) From 9d1ca5ba1782a8b308ebf5179067df0ad8bd2fb5 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Tue, 21 Feb 2017 18:56:49 -0800 Subject: [PATCH 04/32] withdraw method works and passes tests --- lib/account.rb | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 6fb1a282..8258bfac 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,44 +1,52 @@ module Bank class Account - attr_accessor :id, :balance, :withdraw + attr_accessor :id, :balance, :withdraw, :deposit def initialize (id, balance) #need to call a method here that checks if balance is > 0; argument error @id = id @balance = balance @withdraw + @deposit end def withdraw (withdraw_amount) @withdraw = withdraw_amount - if @balance - @withdraw > 0 - puts "Here's your cash" - @balance = @balance - @withdraw - puts "Your new balance is: $#{@balance}" + if @withdraw > 0 + if @balance - @withdraw >= 0 + return @balance -= @withdraw + # return @balance + else + puts "You don't have enough in your account for this" + return @balance + end else - puts "you do not have enough money in your account for this" + raise ArgumentError.new("You must enter a positive withdraw amount") end end - def deposit - #make sure positive - #adjust balance - end + # def deposit(deposit_amount) + # @deposit = deposit_amount + # if deposit_amount > 0 + # @balance += @deposit + # return @balance + # end + # #adjust balance + # end - def new_account_check - #make sure that new accounts are not started with negative balance - end + # def new_account_check + # #make sure that new accounts are not started with negative balance + # end - def show_balance - puts "Your balance is: $#{@balance}" - end + # def show_balance + # puts "Your balance is: $#{@balance}" + # end end end my_account = Bank::Account.new(16, 1000) -# my_account.show_balance -my_account.withdraw(200) +puts my_account.withdraw(200) From 5d96b68fb4c7d34042c0063f4396abd35e88ca12 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Tue, 21 Feb 2017 19:01:42 -0800 Subject: [PATCH 05/32] deposit feature working and passes tests --- lib/account.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 8258bfac..a7211896 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -26,14 +26,15 @@ def withdraw (withdraw_amount) end end - # def deposit(deposit_amount) - # @deposit = deposit_amount - # if deposit_amount > 0 - # @balance += @deposit - # return @balance - # end - # #adjust balance - # end + def deposit(deposit_amount) + @deposit = deposit_amount + if deposit_amount > 0 + @balance += @deposit + return @balance + else + raise ArgumentError.new("You need to enter a positive amount to deposit") + end + end # def new_account_check # #make sure that new accounts are not started with negative balance @@ -49,4 +50,5 @@ def withdraw (withdraw_amount) end my_account = Bank::Account.new(16, 1000) -puts my_account.withdraw(200) +# puts my_account.withdraw(200) +puts my_account.deposit(200) From 66f4bf07a870f2e4c0481c7c990df3ff29f93797 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Tue, 21 Feb 2017 19:15:57 -0800 Subject: [PATCH 06/32] adds error for negative starting balances and all tests for Wave 1 are working. --- lib/account.rb | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index a7211896..3dc01c1a 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -4,13 +4,17 @@ class Account attr_accessor :id, :balance, :withdraw, :deposit def initialize (id, balance) - #need to call a method here that checks if balance is > 0; argument error - @id = id + raise ArgumentError.new("You need some positive cash flow to open an account") if balance < 0 @balance = balance + @id = id @withdraw @deposit end + + + + #method to withdraw money def withdraw (withdraw_amount) @withdraw = withdraw_amount if @withdraw > 0 @@ -26,6 +30,9 @@ def withdraw (withdraw_amount) end end + + + #method to deposit money def deposit(deposit_amount) @deposit = deposit_amount if deposit_amount > 0 @@ -36,19 +43,19 @@ def deposit(deposit_amount) end end - # def new_account_check - # #make sure that new accounts are not started with negative balance - # end + #method to check balance at any time # def show_balance # puts "Your balance is: $#{@balance}" # end + + end end -my_account = Bank::Account.new(16, 1000) +# my_account = Bank::Account.new(16, -1000) # puts my_account.withdraw(200) -puts my_account.deposit(200) +# puts my_account.deposit(200) From 546ff3b08319459f641c382449173bb731c76bce Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Thu, 23 Feb 2017 14:05:11 -0800 Subject: [PATCH 07/32] phase one features are working --- lib/account.rb | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/account.rb b/lib/account.rb index e69de29b..e0317e95 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -0,0 +1,45 @@ +#this is the new, second try at this + +module Bank + attr_accessor :id, :balance + + class Account + def initialize (id, balance) + raise ArgumentError.new("You need some positive cash flow to open an account") if balance < 0 + @id = id + @balance = balance + end + + def withdraw (amount) + if amount > 0 + if @balance - amount < 0 + raise ArgumentError.new ("You do not have enough money to withdraw this amount") + end + @balance -=amount + return @balance + else + "You can only withdraw a positive amount of money" + end + end + + + def deposit (amount) + if amount > 0 + @balance +=amount + return @balance + end + end + + + def show_balance + return @balance + end + + end +end + + +my_account = Bank::Account.new(16, 1000) +# puts my_account.show_balance +puts my_account.withdraw(0) +# puts my_account.deposit(200) From 87df7fed9340bf466eb8f4742f3152a61ad2c4e2 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Thu, 23 Feb 2017 14:22:08 -0800 Subject: [PATCH 08/32] phase one is working and passes all tests --- lib/account.rb | 26 +++++++++++++++----------- specs/account_spec.rb | 8 +++++++- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index e0317e95..e1c31fa4 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,25 +1,26 @@ #this is the new, second try at this module Bank - attr_accessor :id, :balance - + class Account + attr_accessor :id, :balance def initialize (id, balance) - raise ArgumentError.new("You need some positive cash flow to open an account") if balance < 0 - @id = id - @balance = balance + raise ArgumentError.new("You need some positive cash flow to open an account") if balance < 0 + @id = id + @balance = balance end def withdraw (amount) if amount > 0 if @balance - amount < 0 - raise ArgumentError.new ("You do not have enough money to withdraw this amount") + puts "You do not have enough money to withdraw this amount" + else + @balance -=amount end - @balance -=amount - return @balance else - "You can only withdraw a positive amount of money" + raise ArgumentError.new("You can only withdraw a positive amount of money") end + return @balance end @@ -27,7 +28,10 @@ def deposit (amount) if amount > 0 @balance +=amount return @balance + else + raise ArgumentError.new("need positive amt") end + end @@ -39,7 +43,7 @@ def show_balance end -my_account = Bank::Account.new(16, 1000) +# my_account = Bank::Account.new(16, 1000) # puts my_account.show_balance -puts my_account.withdraw(0) +# puts my_account.withdraw(1200) # puts my_account.deposit(200) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 6c399139..af222f88 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -9,7 +9,6 @@ id = 1337 balance = 100.0 account = Bank::Account.new(id, balance) - account.must_respond_to :id account.id.must_equal id @@ -18,6 +17,7 @@ end it "Raises an ArgumentError when created with a negative balance" do + # skip # 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 @@ -28,12 +28,14 @@ end it "Can be created with a balance of 0" do + # skip # If this raises, the test will fail. No 'must's needed! Bank::Account.new(1337, 0) end end describe "Account#withdraw" do + # skip it "Reduces the balance" do start_balance = 100.0 withdrawal_amount = 25.0 @@ -46,6 +48,7 @@ end it "Returns the modified balance" do + # skip start_balance = 100.0 withdrawal_amount = 25.0 account = Bank::Account.new(1337, start_balance) @@ -57,6 +60,7 @@ end it "Outputs a warning if the account would go negative" do + # skip start_balance = 100.0 withdrawal_amount = 200.0 account = Bank::Account.new(1337, start_balance) @@ -71,6 +75,7 @@ end it "Doesn't modify the balance if the account would go negative" do + # skip start_balance = 100.0 withdrawal_amount = 200.0 account = Bank::Account.new(1337, start_balance) @@ -84,6 +89,7 @@ end it "Allows the balance to go to 0" do + # skip account = Bank::Account.new(1337, 100.0) updated_balance = account.withdraw(account.balance) updated_balance.must_equal 0 From 1131b7a37017522ae46e7823aa78da74d2716f66 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Thu, 23 Feb 2017 15:23:19 -0800 Subject: [PATCH 09/32] code and tests for self.all are working thanks to chris video --- lib/account.rb | 23 +++++++++++++++++++--- specs/account_spec.rb | 46 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index e1c31fa4..72a99b3a 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,15 +1,32 @@ #this is the new, second try at this +require "csv" module Bank - + class Account - attr_accessor :id, :balance - def initialize (id, balance) + attr_accessor :id, :balance, :opendate + def initialize (id, balance, opendate = nil) raise ArgumentError.new("You need some positive cash flow to open an account") if balance < 0 @id = id @balance = balance + @opendate end + + def self.all + accounts = [] + + CSV.read("support/accounts.csv").each do |line| + id = line[0].to_i + balance = line[1].to_i + opendate = line[2] + account = Bank::Account.new(id, balance, opendate) + accounts << account + end + return accounts + end + + def withdraw (amount) if amount > 0 if @balance - amount < 0 diff --git a/specs/account_spec.rb b/specs/account_spec.rb index af222f88..0fc95479 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -2,7 +2,7 @@ require 'minitest/reporters' require 'minitest/skip_dsl' require_relative '../lib/account' - +require 'csv' describe "Wave 1" do describe "Account#initialize" do it "Takes an ID and an initial balance" do @@ -35,7 +35,6 @@ end describe "Account#withdraw" do - # skip it "Reduces the balance" do start_balance = 100.0 withdrawal_amount = 25.0 @@ -71,7 +70,7 @@ # anything at all is printed out the test will pass. proc { account.withdraw(withdrawal_amount) - }.must_output /.+/ + }.must_output( /.+/) end it "Doesn't modify the balance if the account would go negative" do @@ -129,7 +128,7 @@ 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 @@ -143,18 +142,49 @@ end # TODO: change 'xdescribe' to 'describe' to run these tests -xdescribe "Wave 2" do +describe "Wave 2" do describe "Account.all" do + before do + @accounts = Bank::Account.all + end + 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 + @accounts.must_be_instance_of Array + end + + it "Everything in the array is an Account" do + @accounts.each do |account| + account.must_be_instance_of Bank::Account + end + end + + it "The number of accounts is correct" do + @accounts.length.must_equal 12 + end + # - The ID and balance of the first and last # accounts match what's in the CSV file + + it "element's first and last id and balance must equal what's in csv file" do + @accounts.first.id.must_equal 1212 + @accounts.first.balance.must_equal 1235667 + @accounts.last.id.must_equal 15156 + @accounts.last.balance.must_equal 4356772 + end + + it "All the elements match what's in the file" do + index = 0 + CSV.read("support/accounts.csv") do + accounts(index).id.must_equal line[0].to_i + accounts(index).balance.must_equal line[1].to_i + accounts(index).opendate.must_equal line[2] + index += 1 + end + end # Feel free to split this into multiple tests if needed - end end describe "Account.find" do From ae349583f016b445e45d6466ec73391bfb62531d Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Thu, 23 Feb 2017 15:51:28 -0800 Subject: [PATCH 10/32] find tests for verifying an account and that the first matches the csv works for everything but opendate --- lib/account.rb | 12 ++++++++++++ specs/account_spec.rb | 33 +++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 72a99b3a..f8e7a25d 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -27,6 +27,18 @@ def self.all end + def self.find(id) + accounts = Bank::Account.all + accounts.each do |account| + if account.id.to_i == id + return account + end + end + raise ArgumentError.new("this is not an account in our system") + end + + + def withdraw (amount) if amount > 0 if @balance - amount < 0 diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 0fc95479..b391e0da 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -143,6 +143,7 @@ # TODO: change 'xdescribe' to 'describe' to run these tests describe "Wave 2" do + #would it be possible to run the @accounts thing here so that it works for both .all and .find tests? describe "Account.all" do before do @accounts = Bank::Account.all @@ -188,14 +189,38 @@ end describe "Account.find" do - it "Returns an account that exists" do - # TODO: Your test code here! - end + + it "Returns an account that exists" do + # TODO: Your test code here! + account = Bank::Account.find(1217) + + account.must_be_instance_of Bank::Account + account.id.must_equal 1217 + account.balance.must_equal 12323 + # account.opendate.must_equal "2003-11-07 11:34:56 -0800" + end + + + it "Can find the first account from the CSV" do - # TODO: Your test code here! + CSV.read("support/accounts.csv") do + accounts(0).id.must_equal 1212 + accounts(0).balance.must_equal 1235667 + # accounts(0).opendate.must equal 1999-03-27 11:30:09 -0800 + end end + + + + + + + + + + it "Can find the last account from the CSV" do # TODO: Your test code here! end From d24e5e52b3dd35018e687857f11bf45dd9d1ce42 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Thu, 23 Feb 2017 16:02:33 -0800 Subject: [PATCH 11/32] wave one working except for open dates --- lib/account.rb | 2 +- specs/account_spec.rb | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index f8e7a25d..83d8e8c0 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -34,7 +34,7 @@ def self.find(id) return account end end - raise ArgumentError.new("this is not an account in our system") + raise ArgumentError.new("this is not an account in our system") end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index b391e0da..61fdf7f7 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -189,7 +189,7 @@ end describe "Account.find" do - + it "Returns an account that exists" do # TODO: Your test code here! account = Bank::Account.find(1217) @@ -213,20 +213,19 @@ - - - - - - - - it "Can find the last account from the CSV" do - # TODO: Your test code here! + CSV.read("support/accounts.csv") do + accounts(-1).id.must_equal 15156 + accounts(-1).balance.must_equal 4356772 + # accounts(-1).opendate.must_equal 1994-11-17 14:04:56 -0800 + end + end it "Raises an error for an account that doesn't exist" do - # TODO: Your test code here! + proc{ + Bank::Account.find(116) + }.must_raise ArgumentError end end end From d9f47c4139b7e72c67628a1da3731ca52e4c2280 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Thu, 23 Feb 2017 17:01:18 -0800 Subject: [PATCH 12/32] there is a new class savings that inherits from account and passes the first test --- lib/account.rb | 4 +--- lib/savings_account.rb | 11 +++++++++++ specs/account_spec.rb | 6 +++--- specs/savings_account_spec.rb | 3 ++- 4 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 lib/savings_account.rb diff --git a/lib/account.rb b/lib/account.rb index 83d8e8c0..cb6562eb 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,15 +1,13 @@ #this is the new, second try at this require "csv" - module Bank - class Account attr_accessor :id, :balance, :opendate def initialize (id, balance, opendate = nil) raise ArgumentError.new("You need some positive cash flow to open an account") if balance < 0 @id = id @balance = balance - @opendate + @opendate = opendate end diff --git a/lib/savings_account.rb b/lib/savings_account.rb new file mode 100644 index 00000000..a792571d --- /dev/null +++ b/lib/savings_account.rb @@ -0,0 +1,11 @@ +require_relative 'account.rb' + +module Bank + class SavingsAccount < Account + def initialize (id, balance, opendate = nil) + #raise error for insufficient balance + super + end + + end +end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 61fdf7f7..05980e88 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -197,7 +197,7 @@ account.must_be_instance_of Bank::Account account.id.must_equal 1217 account.balance.must_equal 12323 - # account.opendate.must_equal "2003-11-07 11:34:56 -0800" + account.opendate.must_equal "2003-11-07 11:34:56 -0800" end @@ -207,7 +207,7 @@ CSV.read("support/accounts.csv") do accounts(0).id.must_equal 1212 accounts(0).balance.must_equal 1235667 - # accounts(0).opendate.must equal 1999-03-27 11:30:09 -0800 + accounts(0).opendate.must equal "1999-03-27 11:30:09 -0800" end end @@ -217,7 +217,7 @@ CSV.read("support/accounts.csv") do accounts(-1).id.must_equal 15156 accounts(-1).balance.must_equal 4356772 - # accounts(-1).opendate.must_equal 1994-11-17 14:04:56 -0800 + accounts(-1).opendate.must_equal "1994-11-17 14:04:56 -0800" end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 3f4d1e4a..5451541c 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -1,6 +1,7 @@ require 'minitest/autorun' require 'minitest/reporters' require 'minitest/skip_dsl' +# require 'savings_account' # TODO: uncomment the next line once you start wave 3 and add lib/savings_account.rb # require_relative '../lib/savings_account' @@ -11,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 From 440ea50cfd75dba0d53250f5a10fc8de6f7c8846 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Thu, 23 Feb 2017 17:08:05 -0800 Subject: [PATCH 13/32] holy cow the initialize works and i just wrote a test before code and it worked --- lib/savings_account.rb | 2 +- specs/savings_account_spec.rb | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index a792571d..8306ae3a 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -3,7 +3,7 @@ module Bank class SavingsAccount < Account def initialize (id, balance, opendate = nil) - #raise error for insufficient balance + raise ArgumentError.new("You must have at least $10") if balance < 10 super end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 5451541c..2c724945 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -1,7 +1,7 @@ require 'minitest/autorun' require 'minitest/reporters' require 'minitest/skip_dsl' -# require 'savings_account' +require 'savings_account' # TODO: uncomment the next line once you start wave 3 and add lib/savings_account.rb # require_relative '../lib/savings_account' @@ -21,10 +21,23 @@ end it "Requires an initial balance of at least $10" do - # TODO: Your test code here! + + proc{ + Bank::SavingsAccount.new(117, 9) + }.must_raise ArgumentError end end + + + + + + + + + + describe "#withdraw" do it "Applies a $2 fee each time" do # TODO: Your test code here! From e84065a273e558a3a5f82ea59e97bfd01aaf845b Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Thu, 23 Feb 2017 17:36:45 -0800 Subject: [PATCH 14/32] transaction fee is working and the test is all green --- lib/savings_account.rb | 22 ++++++++++++++++++++++ specs/savings_account_spec.rb | 26 ++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 8306ae3a..f39ed81a 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -7,5 +7,27 @@ def initialize (id, balance, opendate = nil) super end + + def withdraw (amount) + #inherit withdraw functionality from Account + + #incur $2 fee each transaction + super + @balance -=2 + return @balance + + #can not go below $10 + end + + + + + + + + + + + end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 2c724945..fcfabdcc 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -30,6 +30,28 @@ + describe "#withdraw" do + it "Applies a $2 fee each time" do + id = 116 + balance = 20 + fee = 2 + amount = 2 + account = Bank::SavingsAccount.new(id,balance) + account.withdraw(amount) + account.balance.must_equal balance - (amount + fee) + end + + + + + + + + + + + + @@ -38,10 +60,6 @@ - describe "#withdraw" do - it "Applies a $2 fee each time" do - # TODO: Your test code here! - end it "Outputs a warning if the balance would go below $10" do # TODO: Your test code here! From 8184e59fb6937e6a4a6f5cf282c2da5a7bec892c Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Thu, 23 Feb 2017 17:50:04 -0800 Subject: [PATCH 15/32] withdraw fee tests and code works --- lib/savings_account.rb | 3 ++- specs/savings_account_spec.rb | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index f39ed81a..cad6b420 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -10,13 +10,14 @@ def initialize (id, balance, opendate = nil) def withdraw (amount) #inherit withdraw functionality from Account + #can not go below $10 + raise ArgumentError.new("You must leave a balance of $10 in your account") if @balance - amount < 10 #incur $2 fee each transaction super @balance -=2 return @balance - #can not go below $10 end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index fcfabdcc..c5583d5d 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -43,7 +43,17 @@ + it "Outputs a warning if the balance would go below $10" do + id = 116 + balance = 20 + amount = 11 + account = Bank::SavingsAccount.new(id, balance) + proc{ + account.withdraw(amount) + }.must_raise ArgumentError + # account.withdraw.must_raise ArgumentError + end @@ -61,9 +71,6 @@ - it "Outputs a warning if the balance would go below $10" do - # TODO: Your test code here! - end it "Doesn't modify the balance if it would go below $10" do # TODO: Your test code here! From 339a8ca70dc1a93c81e7191d7625a9b0ceee1891 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Thu, 23 Feb 2017 18:03:18 -0800 Subject: [PATCH 16/32] not letting withdraws happen if fee would put account under 10; tests working too --- lib/savings_account.rb | 5 +++-- specs/savings_account_spec.rb | 24 +++++++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index cad6b420..0e94633f 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -11,11 +11,12 @@ def initialize (id, balance, opendate = nil) def withdraw (amount) #inherit withdraw functionality from Account #can not go below $10 - raise ArgumentError.new("You must leave a balance of $10 in your account") if @balance - amount < 10 + fee = 2 + raise ArgumentError.new("You must leave a balance of $10 in your account") if @balance - amount < 10 || @balance - (amount + fee) < 10 #incur $2 fee each transaction super - @balance -=2 + @balance -=fee return @balance end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index c5583d5d..98d5a47d 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -61,6 +61,27 @@ + it "Doesn't modify the balance if it would go below $10" do + id = 116 + balance = 20 + amount = 9 + fee = 2 + account = Bank::SavingsAccount.new(id, balance) + + proc{ + account.withdraw(amount) + }.must_raise ArgumentError + end + + + + + + + + + + @@ -72,9 +93,6 @@ - it "Doesn't modify the balance if it would go below $10" do - # TODO: Your test code here! - end it "Doesn't modify the balance if the fee would put it below $10" do # TODO: Your test code here! From 9030ecfda9d130776b3ba56c1a456a61c770f737 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Thu, 23 Feb 2017 18:30:48 -0800 Subject: [PATCH 17/32] holy cow all of the tests and code for savings account work --- lib/savings_account.rb | 11 +++++++++-- specs/savings_account_spec.rb | 37 ++++++++++++++--------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 0e94633f..15519e86 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -8,16 +8,23 @@ def initialize (id, balance, opendate = nil) end + def withdraw (amount) #inherit withdraw functionality from Account #can not go below $10 fee = 2 - raise ArgumentError.new("You must leave a balance of $10 in your account") if @balance - amount < 10 || @balance - (amount + fee) < 10 - + if @balance - amount < 10 + puts "You don't have enough in your account for this" + return @balance + elsif @balance - (amount + fee) < 10 + puts "The transaction fee would make you go under $10" + return @balance + else #incur $2 fee each transaction super @balance -=fee return @balance + end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 98d5a47d..2dc16e23 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -49,14 +49,12 @@ amount = 11 account = Bank::SavingsAccount.new(id, balance) + proc{ account.withdraw(amount) - }.must_raise ArgumentError - # account.withdraw.must_raise ArgumentError - end - - + }.must_output( /.+/) + end @@ -64,17 +62,24 @@ it "Doesn't modify the balance if it would go below $10" do id = 116 balance = 20 - amount = 9 - fee = 2 + amount = 11 account = Bank::SavingsAccount.new(id, balance) + account.withdraw(amount) - proc{ - account.withdraw(amount) - }.must_raise ArgumentError + account.balance.must_equal balance end + it "Doesn't modify the balance if the fee would put it below $10" do + id = 116 + balance = 20 + amount = 9 + fee = 2 + account = Bank::SavingsAccount.new(id, balance) + account.balance.must_equal balance + end + end @@ -87,18 +92,6 @@ - - - - - - - - it "Doesn't modify the balance if the fee would put it below $10" do - # TODO: Your test code here! - end - end - describe "#add_interest" do it "Returns the interest calculated" do # TODO: Your test code here! From cac59ee1fe8191814ceb1f0a7d1a6aec2e652ad8 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Fri, 24 Feb 2017 11:12:22 -0800 Subject: [PATCH 18/32] savings account interest is being tracked and tests all work. --- lib/checking_account.rb | 21 ++++++++++++++++ lib/savings_account.rb | 11 +++++++++ specs/checking_account_spec.rb | 4 ++-- specs/savings_account_spec.rb | 44 ++++++++++++++++++++++------------ 4 files changed, 63 insertions(+), 17 deletions(-) create mode 100644 lib/checking_account.rb diff --git a/lib/checking_account.rb b/lib/checking_account.rb new file mode 100644 index 00000000..1a4143df --- /dev/null +++ b/lib/checking_account.rb @@ -0,0 +1,21 @@ +#creates a new subclass of Account class that is +require_relative 'account.rb' +module Bank + class CheckingAccount < Account + def initialize (id, balance, opendate = nil) + #super sets the instance variables found in the Account initialize method + super + end + + + + + end + + + + + + + +end diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 15519e86..8ec94124 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -2,8 +2,10 @@ module Bank class SavingsAccount < Account + attr_accessor :interest def initialize (id, balance, opendate = nil) raise ArgumentError.new("You must have at least $10") if balance < 10 + @interest = 0 super end @@ -28,8 +30,17 @@ def withdraw (amount) end + def add_interest(rate) + @interest = @balance * rate/100 + @balance += @interest + return @interest + end + + # return @balance +account = Bank::SavingsAccount.new(116,10000) +puts account.add_interest(0.25) diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 7f95339e..f51261cb 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 diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 2dc16e23..eebb7feb 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -1,10 +1,10 @@ require 'minitest/autorun' require 'minitest/reporters' require 'minitest/skip_dsl' -require 'savings_account' +# require 'savings_account' # TODO: uncomment the next line once you start wave 3 and add lib/savings_account.rb -# require_relative '../lib/savings_account' +require_relative '../lib/savings_account' # Because a SavingsAccount is a kind # of Account, and we've already tested a bunch of functionality @@ -70,36 +70,50 @@ end + it "Doesn't modify the balance if the fee would put it below $10" do id = 116 - balance = 20 - amount = 9 - fee = 2 - account = Bank::SavingsAccount.new(id, balance) + balance = 20 + amount = 9 + fee = 2 + account = Bank::SavingsAccount.new(id, balance) - account.balance.must_equal balance + account.balance.must_equal balance end end +#this does not work and i don't understand for the life of me! + describe "#add_interest" do + it "Returns the interest calculated" do + id = 116 + balance = 10000 + rate = 0.25 + interest = balance * rate/100 + account = Bank::SavingsAccount.new(id,balance) + account.add_interest(rate).must_equal interest + # account.interest.must_equal interest + end + it "Updates the balance with calculated interest" do + id = 116 + balance = 10000 + rate = 0.25 + interest = balance * rate/100 + new_balance = interest + balance + account = Bank::SavingsAccount.new(id,balance) + account.add_interest(rate) + account.balance.must_equal new_balance + end - describe "#add_interest" do - it "Returns the interest calculated" do - # TODO: Your test code here! - end - - it "Updates the balance with calculated interest" do - # TODO: Your test code here! - end it "Requires a positive rate" do # TODO: Your test code here! From 102fed77b5e2c08a6f0b1335b0a60467255bc7be Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Fri, 24 Feb 2017 11:14:10 -0800 Subject: [PATCH 19/32] changed interest to a local variable, tests still pass, savings account is finished --- lib/savings_account.rb | 12 +++++------- specs/savings_account_spec.rb | 1 - 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 8ec94124..64bc9103 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -2,10 +2,8 @@ module Bank class SavingsAccount < Account - attr_accessor :interest def initialize (id, balance, opendate = nil) raise ArgumentError.new("You must have at least $10") if balance < 10 - @interest = 0 super end @@ -31,16 +29,16 @@ def withdraw (amount) end def add_interest(rate) - @interest = @balance * rate/100 - @balance += @interest - return @interest + interest = @balance * rate/100 + @balance += interest + return interest end # return @balance -account = Bank::SavingsAccount.new(116,10000) -puts account.add_interest(0.25) +# account = Bank::SavingsAccount.new(116,10000) +# puts account.add_interest(0.25) diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index eebb7feb..eac1253c 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -93,7 +93,6 @@ account = Bank::SavingsAccount.new(id,balance) account.add_interest(rate).must_equal interest - # account.interest.must_equal interest end From e27d6b0003f55936427ff81f0b23b64970d0e308 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Fri, 24 Feb 2017 11:22:06 -0800 Subject: [PATCH 20/32] tests and code working for initializing and fee for withdraw method --- lib/checking_account.rb | 28 ++++++++++++++++++++++++++++ specs/checking_account_spec.rb | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 1a4143df..062c24b0 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -9,6 +9,34 @@ def initialize (id, balance, opendate = nil) + def withdraw(amount) + #fee of $1 for each withdraw + super + fee = 1 + @balance -=fee + return @balance + + #display new balance + #balance can't go below -10 including fee + #if below -10 PUTS message + #if enter negative withdraw amount PUTS message + + end + + + def withdraw_using_check + + end + + def reset_checks + + end + + + + + + end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index f51261cb..45b1d334 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -20,11 +20,42 @@ end end + + describe "#withdraw" do it "Applies a $1 fee each time" do - # TODO: Your test code here! + id = 16 + balance = 20 + fee = 1 + # new_balance = balance - (withdraw + fee) + + account = Bank::CheckingAccount.new(id, balance) + account.withdraw(9) + account.balance.must_equal 10 end + + + + + + + + + + + + + + + + + + + + + + it "Doesn't modify the balance if the fee would put it negative" do # TODO: Your test code here! end From b736ce59beca660532c42bc916c963143ce19b78 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Fri, 24 Feb 2017 12:53:47 -0800 Subject: [PATCH 21/32] trying to make variables of minimum and fee to share the load of withdraw in account class --- lib/account.rb | 23 ++++++++++++++++++++++- lib/checking_account.rb | 12 ++++++++---- lib/savings_account.rb | 28 ++++++++++++++++------------ specs/checking_account_spec.rb | 21 --------------------- 4 files changed, 46 insertions(+), 38 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index cb6562eb..6c55b2e5 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -39,7 +39,7 @@ def self.find(id) def withdraw (amount) if amount > 0 - if @balance - amount < 0 + if @balance - amount < minimum puts "You do not have enough money to withdraw this amount" else @balance -=amount @@ -51,6 +51,27 @@ def withdraw (amount) end + def withdraw(amount) + if amount > 0 + if @balance - amount < @minimum || @balance - [amount + @fee] < @minimum + puts "You don't have enough money in your account for this transaction" + else + @balance -=[amount + fee] + return @balance + end + else + puts "You must enter a positive amount of money to withdraw" + end + + end + + + + + + + + def deposit (amount) if amount > 0 @balance +=amount diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 062c24b0..82bc9d9d 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -2,7 +2,10 @@ require_relative 'account.rb' module Bank class CheckingAccount < Account + attr_reader :minimum, :fee def initialize (id, balance, opendate = nil) + @fee + @minimum #super sets the instance variables found in the Account initialize method super end @@ -11,10 +14,11 @@ def initialize (id, balance, opendate = nil) def withdraw(amount) #fee of $1 for each withdraw - super - fee = 1 - @balance -=fee - return @balance + # super + @fee = 1 + @minimum = 0 + # @balance -=fee + # return @balance #display new balance #balance can't go below -10 including fee diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 64bc9103..69846f2f 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -2,7 +2,10 @@ module Bank class SavingsAccount < Account + attr_reader :minimum, :fee def initialize (id, balance, opendate = nil) + @fee + @minimum raise ArgumentError.new("You must have at least $10") if balance < 10 super end @@ -12,18 +15,19 @@ def initialize (id, balance, opendate = nil) def withdraw (amount) #inherit withdraw functionality from Account #can not go below $10 - fee = 2 - if @balance - amount < 10 - puts "You don't have enough in your account for this" - return @balance - elsif @balance - (amount + fee) < 10 - puts "The transaction fee would make you go under $10" - return @balance - else - #incur $2 fee each transaction - super - @balance -=fee - return @balance + @fee = 2 + @minimum = 10 + # if @balance - amount < minimum + # puts "You don't have enough in your account for this" + # return @balance + # elsif @balance - (amount + fee) < minimum + # puts "The transaction fee would make you go under $10" + # return @balance + # else + # #incur $2 fee each transaction + # super + # @balance -=fee + # return @balance end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 45b1d334..47545fcb 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -35,27 +35,6 @@ end - - - - - - - - - - - - - - - - - - - - - it "Doesn't modify the balance if the fee would put it negative" do # TODO: Your test code here! end From 4fcfd35c43e6b26e1dbf75ef7ff282512d65251b Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Fri, 24 Feb 2017 13:48:37 -0800 Subject: [PATCH 22/32] woohooooooo savings and checking withdraw are inheriting stuff from the big brother accounts class and tests are clean; using methods for minimum and fee --- lib/account.rb | 35 ++++++++-------------------- lib/checking_account.rb | 47 +++++++++++-------------------------- lib/savings_account.rb | 51 +++++++++++------------------------------ 3 files changed, 37 insertions(+), 96 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 6c55b2e5..097086ba 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -3,7 +3,7 @@ module Bank class Account attr_accessor :id, :balance, :opendate - def initialize (id, balance, opendate = nil) + def initialize (id, balance, opendate = nil ) raise ArgumentError.new("You need some positive cash flow to open an account") if balance < 0 @id = id @balance = balance @@ -35,14 +35,21 @@ def self.find(id) raise ArgumentError.new("this is not an account in our system") end + def fee + 0 + end + + def minimum + 0 + end def withdraw (amount) if amount > 0 - if @balance - amount < minimum + if @balance - amount < 0 || @balance - amount < minimum || @balance - (amount + fee) < minimum puts "You do not have enough money to withdraw this amount" else - @balance -=amount + @balance -=(amount + fee) end else raise ArgumentError.new("You can only withdraw a positive amount of money") @@ -50,28 +57,6 @@ def withdraw (amount) return @balance end - - def withdraw(amount) - if amount > 0 - if @balance - amount < @minimum || @balance - [amount + @fee] < @minimum - puts "You don't have enough money in your account for this transaction" - else - @balance -=[amount + fee] - return @balance - end - else - puts "You must enter a positive amount of money to withdraw" - end - - end - - - - - - - - def deposit (amount) if amount > 0 @balance +=amount diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 82bc9d9d..fb27c579 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -4,50 +4,29 @@ module Bank class CheckingAccount < Account attr_reader :minimum, :fee def initialize (id, balance, opendate = nil) - @fee - @minimum #super sets the instance variables found in the Account initialize method super end - - def withdraw(amount) - #fee of $1 for each withdraw - # super - @fee = 1 - @minimum = 0 - # @balance -=fee - # return @balance - - #display new balance - #balance can't go below -10 including fee - #if below -10 PUTS message - #if enter negative withdraw amount PUTS message - - end - - - def withdraw_using_check - + #method which returns 1, so fee for any object in checking account is now 1 + def fee + 1 end - def reset_checks - + #method which returns 0 for the minimum for a checking account is now 0 + def minimum + 0 end - - - - - + # def withdraw_using_check + # + # end + # + # def reset_checks + # + # end end - - - - - - end diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 69846f2f..93188fe2 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -4,52 +4,29 @@ module Bank class SavingsAccount < Account attr_reader :minimum, :fee def initialize (id, balance, opendate = nil) - @fee - @minimum - raise ArgumentError.new("You must have at least $10") if balance < 10 - super + super + # @fee = 2 + # @minimum = 10 + raise ArgumentError.new("You must have at least $10") if balance < 10 end - - def withdraw (amount) - #inherit withdraw functionality from Account - #can not go below $10 - @fee = 2 - @minimum = 10 - # if @balance - amount < minimum - # puts "You don't have enough in your account for this" - # return @balance - # elsif @balance - (amount + fee) < minimum - # puts "The transaction fee would make you go under $10" - # return @balance - # else - # #incur $2 fee each transaction - # super - # @balance -=fee - # return @balance + def fee + 2 end - end - - def add_interest(rate) - interest = @balance * rate/100 - @balance += interest - return interest - end - - # return @balance - - -# account = Bank::SavingsAccount.new(116,10000) -# puts account.add_interest(0.25) - - - + def minimum + 10 + end + def add_interest(rate) + interest = @balance * rate/100 + @balance += interest + return interest + end end end From dbfd30d64437dfc22d29c8fd8eeafae375768fd4 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Fri, 24 Feb 2017 13:58:51 -0800 Subject: [PATCH 23/32] withdraw tests all done for checking working --- lib/account.rb | 1 + specs/checking_account_spec.rb | 32 +++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 097086ba..cec96dcc 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -57,6 +57,7 @@ def withdraw (amount) return @balance end + def deposit (amount) if amount > 0 @balance +=amount diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 47545fcb..23229dbb 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -26,8 +26,7 @@ it "Applies a $1 fee each time" do id = 16 balance = 20 - fee = 1 - # new_balance = balance - (withdraw + fee) + account = Bank::CheckingAccount.new(id, balance) account.withdraw(9) @@ -36,10 +35,37 @@ it "Doesn't modify the balance if the fee would put it negative" do - # TODO: Your test code here! + id = 16 + balance = 20 + + account = Bank::CheckingAccount.new(id, balance) + account.withdraw(20) + account.balance.must_equal balance end end + + + + + + + + + + + + + + + + + + + + + + describe "#withdraw_using_check" do it "Reduces the balance" do # TODO: Your test code here! From cb2b1420c3a60a835ae8c8b94234d1459058adce Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Fri, 24 Feb 2017 14:14:35 -0800 Subject: [PATCH 24/32] test for withdraw using check working and new balance is being returned --- lib/checking_account.rb | 28 ++++++++++++++++++++++++---- specs/checking_account_spec.rb | 14 ++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index fb27c579..948c48e1 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -20,10 +20,30 @@ def minimum end - # def withdraw_using_check - # - # end - # + def withdraw_using_check(amount) + @balance -=amount + return @balance + end + + + + + + + + + + + + + + + + + + + + # def reset_checks # # end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 23229dbb..f1cc2793 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -45,8 +45,18 @@ end + describe "#withdraw_using_check" do + it "Reduces the balance" do + id = 116 + balance = 20 + amount = 15 + new_balance = balance - amount + account = Bank::CheckingAccount.new(id,balance) + account.withdraw_using_check(amount) + account.balance.must_equal new_balance + end @@ -66,10 +76,6 @@ - describe "#withdraw_using_check" do - it "Reduces the balance" do - # TODO: Your test code here! - end it "Returns the modified balance" do # TODO: Your test code here! From 5008cf3764baf17ebdd3fc0c821b13bc1c008902 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Fri, 24 Feb 2017 14:29:27 -0800 Subject: [PATCH 25/32] does not allow to go below -10 --- lib/checking_account.rb | 9 ++++-- specs/checking_account_spec.rb | 59 +++++++++++++++++++++++++--------- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 948c48e1..3fc701f8 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -21,8 +21,13 @@ def minimum def withdraw_using_check(amount) - @balance -=amount - return @balance + if @balance - amount < -10 + puts "You do not have enough money in your account for this" + + else + @balance -=amount + return @balance + end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index f1cc2793..da6711d6 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -47,19 +47,55 @@ describe "#withdraw_using_check" do it "Reduces the balance" do - id = 116 - balance = 20 - amount = 15 - new_balance = balance - amount + id = 116 + balance = 20 + amount = 15 + + account = Bank::CheckingAccount.new(id, balance) + account.withdraw_using_check(amount) + account.balance.must_be :<, balance + end - account = Bank::CheckingAccount.new(id,balance) - account.withdraw_using_check(amount) - account.balance.must_equal new_balance + it "Returns the modified balance" do + id = 116 + balance = 20 + amount = 15 + new_balance = balance - amount + account = Bank::CheckingAccount.new(id,balance) + account.withdraw_using_check(amount) + account.balance.must_equal new_balance end + it "Allows the balance to go down to -$10" do + id = 116 + balance = 10 + amount = 20 + account = Bank::CheckingAccount.new(id, balance) + account.withdraw_using_check(amount) + account.balance.must_equal (balance - amount) + end + + + it "Outputs a warning if the account would go below -$10" do + id = 116 + balance = 10 + amount = 21 + + account = Bank::CheckingAccount.new(id, balance) + + proc{ + account.withdraw_using_check(amount) + }.must_output( /.+/) + + + + + + + end @@ -77,17 +113,8 @@ - it "Returns the modified balance" do - # TODO: Your test code here! - end - it "Allows the balance to go down to -$10" do - # TODO: Your test code here! - end - it "Outputs a warning if the account would go below -$10" do - # TODO: Your test code here! - end it "Doesn't modify the balance if the account would go below -$10" do # TODO: Your test code here! From 3994ad11fa25f2033f4ad09ea0e03954330bddf6 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Fri, 24 Feb 2017 14:44:10 -0800 Subject: [PATCH 26/32] doesn't allow to withdraw below -10 and requires a positive withdraw amount --- lib/checking_account.rb | 16 +++++++++----- specs/checking_account_spec.rb | 40 +++++++++++----------------------- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 3fc701f8..2fe4e005 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -21,12 +21,16 @@ def minimum def withdraw_using_check(amount) - if @balance - amount < -10 - puts "You do not have enough money in your account for this" - - else - @balance -=amount - return @balance + if amount < 0 + puts "You must withdraw a positive amount" + else + if @balance - amount < -10 + puts "You do not have enough money in your account for this" + + else + @balance -=amount + return @balance + end end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index da6711d6..5e15f4eb 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -89,39 +89,25 @@ proc{ account.withdraw_using_check(amount) }.must_output( /.+/) - - - - - - end - - - - - - - - - - - - - - - - - - - it "Doesn't modify the balance if the account would go below -$10" do - # TODO: Your test code here! + id = 116 + balance = 10 + amount = 21 + + account = Bank::CheckingAccount.new(id, balance) + account.withdraw_using_check(amount) + account.balance.must_equal balance end it "Requires a positive withdrawal amount" do - # TODO: Your test code here! + id = 116 + balance = 10 + amount = -10 + + account = Bank::CheckingAccount.new(id, balance) + account.balance.must_equal balance end it "Allows 3 free uses" do From 760dae033e2f872f547613e7708a92a7104d8e53 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Fri, 24 Feb 2017 15:07:50 -0800 Subject: [PATCH 27/32] allows three free checks; there are some warnings about unused variables in savings account spec that need to be dealt with --- lib/checking_account.rb | 16 +++++++++----- lib/savings_account.rb | 1 - specs/checking_account_spec.rb | 39 +++++++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 2fe4e005..fb9a9363 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -2,7 +2,6 @@ require_relative 'account.rb' module Bank class CheckingAccount < Account - attr_reader :minimum, :fee def initialize (id, balance, opendate = nil) #super sets the instance variables found in the Account initialize method super @@ -21,14 +20,21 @@ def minimum def withdraw_using_check(amount) + check_counter = 0 + check_fee = 0 + + if check_counter >= 4 + check_fee = 2 + end + if amount < 0 puts "You must withdraw a positive amount" - else - if @balance - amount < -10 + else + if @balance - (amount + check_fee) < -10 puts "You do not have enough money in your account for this" - else - @balance -=amount + check_counter +=1 + @balance -=(amount + check_fee) return @balance end end diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 93188fe2..6e772eba 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -2,7 +2,6 @@ module Bank class SavingsAccount < Account - attr_reader :minimum, :fee def initialize (id, balance, opendate = nil) super # @fee = 2 diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 5e15f4eb..07b6943c 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -104,18 +104,51 @@ it "Requires a positive withdrawal amount" do id = 116 balance = 10 - amount = -10 account = Bank::CheckingAccount.new(id, balance) account.balance.must_equal balance end + + + + + + + it "Allows 3 free uses" do - # TODO: Your test code here! + id = 116 + balance = 200 + amount = 10 + + account = Bank::CheckingAccount.new(id, balance) + 3.times do account.withdraw_using_check(amount) end + account.balance.must_equal (balance - (3 * amount)) end + + + + + + + + + + + + + + + + + + + + it "Applies a $2 fee after the third use" do - # TODO: Your test code here! + # account.withdraw_using_check(amount) + # account.balance.must_equal ((balance - (4 * amount)) - 2) end end From 3417c20f869f613972f6f156fb7fdc53f649b8ae Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Fri, 24 Feb 2017 15:22:22 -0800 Subject: [PATCH 28/32] withdraw_using_checks method is a go --- lib/checking_account.rb | 7 ++++--- specs/checking_account_spec.rb | 31 +++++++++---------------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index fb9a9363..065e90eb 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -5,6 +5,7 @@ class CheckingAccount < Account def initialize (id, balance, opendate = nil) #super sets the instance variables found in the Account initialize method super + @check_counter = 0 end @@ -19,11 +20,11 @@ def minimum end + def withdraw_using_check(amount) - check_counter = 0 check_fee = 0 - if check_counter >= 4 + if @check_counter >= 3 check_fee = 2 end @@ -33,7 +34,7 @@ def withdraw_using_check(amount) if @balance - (amount + check_fee) < -10 puts "You do not have enough money in your account for this" else - check_counter +=1 + @check_counter +=1 @balance -=(amount + check_fee) return @balance end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 07b6943c..b5e2ce41 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -111,11 +111,6 @@ - - - - - it "Allows 3 free uses" do id = 116 balance = 200 @@ -127,7 +122,16 @@ end + it "Applies a $2 fee after the third use" do + id = 116 + balance = 200 + amount = 10 + account = Bank::CheckingAccount.new(id, balance) + 4.times do account.withdraw_using_check(amount) end + account.balance.must_equal ((balance - (4 * amount)) - 2) + end + end @@ -135,23 +139,6 @@ - - - - - - - - - - - - it "Applies a $2 fee after the third use" do - # account.withdraw_using_check(amount) - # account.balance.must_equal ((balance - (4 * amount)) - 2) - end - end - describe "#reset_checks" do it "Can be called without error" do # TODO: Your test code here! From 88bacf46d459f0c61dd5c3524ba976946131dbf6 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Fri, 24 Feb 2017 15:38:41 -0800 Subject: [PATCH 29/32] reset checks method working --- lib/checking_account.rb | 24 +++-------------------- specs/checking_account_spec.rb | 35 ++++++++++++++++++++++++++-------- specs/savings_account_spec.rb | 2 +- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 065e90eb..80a844bb 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -42,27 +42,9 @@ def withdraw_using_check(amount) end - - - - - - - - - - - - - - - - - - - # def reset_checks - # - # end + def reset_checks + @check_counter = 0 + end end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index b5e2ce41..f48c7114 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -134,22 +134,41 @@ end + describe "#reset_checks" do + it "Can be called without error" do + id = 116 + balance = 100 + account = Bank::CheckingAccount.new(id, balance) + account.reset_checks + end + end + it "Makes the next three checks free if less than 3 checks had been used" do + id = 116 + balance = 100 + amount = 10 + account = Bank::CheckingAccount.new(id, balance) + account.withdraw_using_check(amount) + account.reset_checks - describe "#reset_checks" do - it "Can be called without error" do - # TODO: Your test code here! + 3.times do account.withdraw_using_check(amount)end + account.balance.must_equal (balance - (4 * amount)) end - it "Makes the next three checks free if less than 3 checks had been used" do - # TODO: Your test code here! - end it "Makes the next three checks free if more than 3 checks had been used" do - # TODO: Your test code here! + id = 116 + balance = 100 + amount = 10 + + account = Bank::CheckingAccount.new(id, balance) + 5.times do account.withdraw_using_check(amount)end + account.reset_checks + account.withdraw_using_check(amount) + # account.balance.must_equal 36 + account.balance.must_equal ((balance - (6 * amount)) - 4) end - end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index eac1253c..fb1fea48 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -113,7 +113,7 @@ - +#WHOOPS NEED TO FINISH THIS!!! it "Requires a positive rate" do # TODO: Your test code here! end From 221f95988e4db9f6f035deab8fd3a31197a05047 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Fri, 24 Feb 2017 15:39:59 -0800 Subject: [PATCH 30/32] all working, no errors. --- specs/savings_account_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index fb1fea48..a6a426a2 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -74,8 +74,6 @@ it "Doesn't modify the balance if the fee would put it below $10" do id = 116 balance = 20 - amount = 9 - fee = 2 account = Bank::SavingsAccount.new(id, balance) account.balance.must_equal balance From 744f595ac8d8ae3522a8ffa806ee9ee32c7143df Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Fri, 24 Feb 2017 15:42:50 -0800 Subject: [PATCH 31/32] adds final forgotten test in savings spec. baseline is finished and error/failure free --- lib/savings_account.rb | 12 +++++++----- specs/savings_account_spec.rb | 14 +++++++++++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 6e772eba..a6b4e59a 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -19,12 +19,14 @@ def minimum end - - def add_interest(rate) - interest = @balance * rate/100 - @balance += interest - return interest + if rate > 0 + interest = @balance * rate/100 + @balance += interest + return interest + else + puts "Rate must be a positive amount" + end end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index a6a426a2..5626147e 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -110,10 +110,18 @@ end - -#WHOOPS NEED TO FINISH THIS!!! it "Requires a positive rate" do - # TODO: Your test code here! + id = 116 + balance = 10000 + rate = -0.25 + + + account = Bank::SavingsAccount.new(id,balance) + + proc{ + account.add_interest(rate) + }.must_output( /.+/) + end end end From 61f67393f1991f8e8fea3b4d009174b6aca4edb7 Mon Sep 17 00:00:00 2001 From: AlisonZ Date: Sun, 26 Feb 2017 23:21:08 -0800 Subject: [PATCH 32/32] submittinh hwk --- lib/account.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/account.rb b/lib/account.rb index 0e22cd6b..633d14bb 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -80,3 +80,4 @@ def show_balance # my_account = Bank::Account.new(16, 1000) # puts my_account.show_balance # puts my_account.withdraw(1200) +