forked from AdaGold/BankAccounts
-
Notifications
You must be signed in to change notification settings - Fork 38
Queues - Sofia Kim - BankAccounts #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Sofia15
wants to merge
5
commits into
Ada-C7:master
Choose a base branch
from
Sofia15:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| require 'csv' | ||
|
|
||
|
|
||
| # CSV.read("./support/accounts.csv").each do |line| | ||
| # #print line | ||
| # print line[0] | ||
| # end | ||
|
|
||
| csv = [] | ||
| CSV.read("./support/accounts.csv").each do |data| | ||
| print data | ||
| #csv << data[0] | ||
| end | ||
|
|
||
| # print csv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| require 'csv' | ||
|
|
||
| module Bank | ||
| class Account | ||
| attr_reader :id, :balance, :openDate | ||
| def initialize(id, balance, openDate = '1999-03-27 11:30:09 -0800') | ||
| raise ArgumentError.new("balance must be >= 0") if balance < 0 | ||
| @id = id | ||
| @balance = balance | ||
| @openDate = openDate | ||
| end | ||
|
|
||
| def self.all | ||
| all_accounts = [] #array of classes | ||
| #iterate /new accounts objects | ||
| CSV.open("./support/accounts.csv").each do |line| | ||
|
|
||
| # all_accounts << Bank::Account.new(line[0].to_i,line[1].to_i,line[2]) | ||
| all_accounts << self.new(line[0].to_i,line[1].to_i,line[2]) | ||
| end | ||
| return all_accounts | ||
| end | ||
|
|
||
| def self.find(id) #looking all_account finding matches with id | ||
| self.all.each do |account| #account - a class | ||
| if account.id == id | ||
| return account | ||
| end | ||
| end | ||
| raise ArgumentError.new("id must be account id") #No clause on this one because if the "each" loop ends, without returning an account, then there are no id numbers that match ahe accounts. So, if the "each" loop ends, then the ArgumentError triggers because there are no ids. | ||
| end | ||
|
|
||
|
|
||
| def withdraw(amount) | ||
| raise ArgumentError.new("amount must be > 0") if amount < 0 #the clause at the end of this ArgumentError triggers the error when the "if" statement is true. If the "if" clause is not true, it skips. | ||
| @balance -= amount | ||
| if @balance < 0 | ||
| puts "You can't withdraw!" | ||
| @balance += amount | ||
| end | ||
| return @balance | ||
| end | ||
|
|
||
| def deposit(amount) | ||
| raise ArgumentError.new("amount must be > 0") if amount < 0 | ||
| @balance += amount | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
| #new_account = Bank::Account.new(1234, 2000) | ||
| #new_account = Bank::Account.all | ||
| # puts Bank::Account.all | ||
| #puts Bank::Account.find(1212).id | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| require File.expand_path('../account.rb', __FILE__) | ||
|
|
||
| module Bank | ||
| class CheckingAccount < Bank::Account | ||
| attr_accessor :number_of_checks | ||
| #attr_reader :free_chashout | ||
| def initialize(id, balance, openDate = '1999-03-27 11:30:09 -0800') | ||
| super(id, balance, openDate = '1999-03-27 11:30:09 -0800') | ||
| # @last_check_date #maybe =nil? | ||
| @number_of_checks = 0 | ||
| @free_chashout = true | ||
| end | ||
|
|
||
| def withdraw(amount) | ||
| super(amount) | ||
| if @balance == 0 | ||
| puts "You can't have negative balance in your account" | ||
| @balance += amount | ||
| else | ||
| return @balance -= 1 | ||
| end | ||
| end | ||
|
|
||
| def withdraw_using_check(check_amount) | ||
| if check_amount > 0 | ||
| if @number_of_checks >= 3 | ||
| @balance -= check_amount + 2 | ||
| else | ||
| @balance -= check_amount | ||
| end | ||
| if @balance < -10 | ||
| puts "Overdraft is only allowed upto $10" | ||
| @balance += check_amount | ||
| else | ||
| @number_of_checks +=1 | ||
| end | ||
| else | ||
| puts "Positive withdrawal amount is needed" | ||
| end | ||
| return @balance | ||
| end | ||
|
|
||
| def reset_checks | ||
| @number_of_checks = 0 | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # checkingaccount = CheckingAccount.new(1212, 1000) | ||
| # # puts checkingaccount.withdraw_using_check(110) | ||
| # p checkingaccount.withdraw_using_check(200) | ||
| # p checkingaccount.withdraw_using_check(200) | ||
| # p checkingaccount.withdraw_using_check(200) | ||
| # p checkingaccount.withdraw_using_check(200) | ||
| # p checkingaccount.number_of_checks | ||
| # p checkingaccount.reset_checks | ||
| # p checkingaccount.number_of_checks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| require File.expand_path('../account.rb', __FILE__) | ||
|
|
||
| module Bank | ||
| class SavingsAccount < Bank::Account | ||
| #attr_accessor | ||
| def initialize(id, balance, openDate = '1999-03-27 11:30:09 -0800') | ||
| super(id, balance, openDate = '1999-03-27 11:30:09 -0800') | ||
| #@interest_rate | ||
| raise ArgumentError.new("initial balance must be > 10") if @balance < 10 | ||
| #@balance > 10 | ||
| end | ||
|
|
||
| def withdraw(amount) | ||
| super(amount) | ||
| @balance -= 2 | ||
| if @balance < 10 | ||
| print "Your balance has to be more than 10" | ||
| @balance += amount + 2 | ||
| end | ||
| return @balance | ||
| end | ||
|
|
||
| def add_interest(rate) | ||
| if rate < 0 | ||
| print "The rate has to be positive" #no puts | ||
| else | ||
| interest = @balance * (rate/100.0) | ||
| @balance += interest | ||
| return interest #float | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| #savingsaccount = SavingsAccount.new(1212, 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| require 'minitest/autorun' | ||
| require 'minitest/reporters' | ||
| require 'minitest/skip_dsl' | ||
| Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new | ||
| require_relative '../lib/account' | ||
|
|
||
| describe "Wave 1" do | ||
|
|
@@ -67,7 +68,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 | ||
|
|
@@ -137,35 +138,62 @@ | |
| 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 | ||
| # - 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 | ||
| #new_account = Bank::Account.all #- Account.all returns an array | ||
| @accounts.must_be_kind_of Array | ||
| @accounts.each do |account| | ||
| account.must_be_instance_of Bank::Account #Account class | ||
| end | ||
| end | ||
| it "The number of accounts is correct" do | ||
| #new_account = Bank::Account.all | ||
| @accounts.length.must_equal 12 #(12) | ||
| #creating test need must xxx | ||
| end | ||
| end | ||
|
|
||
| describe "Account.find" do | ||
| it "Returns an account that exists" do | ||
| # TODO: Your test code here! | ||
| acct_id_1212 = Bank::Account.find(1212) | ||
| acct_id_1212.must_be_instance_of Bank::Account #Account class | ||
| end | ||
|
|
||
| it "Can find the first account from the CSV" do | ||
| # TODO: Your test code here! | ||
| acct_id_1212 = Bank::Account.find(1212) | ||
| acct_id_1212.must_be_instance_of Bank::Account #Account class | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In addition to checking that what you got back from |
||
|
|
||
| end | ||
|
|
||
| it "Can find the last account from the CSV" do | ||
| # TODO: Your test code here! | ||
| last_acct = Bank::Account.find(15156) | ||
| last_acct.must_be_instance_of Bank::Account | ||
| last_acct.balance.must_equal 4356772 | ||
| end | ||
|
|
||
| it "Raises an error for an account that doesn't exist" do | ||
| # TODO: Your test code here! | ||
| proc { | ||
| Bank::Account.find(4000) | ||
| }.must_raise ArgumentError | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
| # Useful checks might include: | ||
| # - Account.all returns an array | ||
| # - Everything in the array is an Account | ||
| # - The number of accounts is correct | ||
| #======================= | ||
| # - The ID and balance of the first and last | ||
| # accounts match what's in the CSV file | ||
| # Feel free to split this into multiple tests if needed | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work on
Account.allandAccount.find, I feel like this implementation is about as clean as it gets.