forked from AdaGold/BankAccounts
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Queues -- Tehut Getahun -- Bank Accounts #35
Open
tehut
wants to merge
2
commits into
Ada-C7:master
Choose a base branch
from
tehut: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
2 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 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,73 @@ | ||
require 'csv' | ||
require 'date' | ||
|
||
module Bank | ||
class Account | ||
attr_reader :id, :balance, :date_opened | ||
|
||
def initialize(id = "", balance = "", date_opened = "") | ||
@id = id.to_i | ||
@balance = balance.to_f | ||
@date_opened = date_opened | ||
|
||
raise ArgumentError.new("balance must be >= 0") if @balance < 0 | ||
if @balance < 0 | ||
then | ||
puts "balance must be >= 0" | ||
end | ||
|
||
end | ||
|
||
def self.all | ||
array =[] | ||
CSV.open("support/accounts.csv").each do |line| | ||
array << self.new(line[0], line[1], DateTime.parse(line[2])) | ||
end | ||
return array | ||
end | ||
|
||
def self.find(id) | ||
self.all.each do |account| | ||
if account.id == id then return account | ||
end | ||
end | ||
raise ArgumentError.new("You must select a valid account") | ||
end | ||
|
||
def withdraw(amount, limit = 0) | ||
if amount > 0 | ||
if (@balance - amount) >= limit | ||
@balance -= amount | ||
else | ||
puts "You have insufficient funds" | ||
end | ||
else | ||
puts "You must withraw an amount greater than $0.00 dollars" | ||
raise ArgumentError.new("you must withdraw an amount greater than $0.00") | ||
end | ||
return @balance | ||
end | ||
|
||
def deposit(amount) | ||
if amount >= 0 | ||
@balance += amount | ||
else | ||
puts "You must deposit an amount greater than $0.00 dollars" | ||
raise ArgumentError.new("you must deposit an amount greater than $0.00") | ||
end | ||
return @balance | ||
end | ||
|
||
def reset_checks | ||
@count = 0 | ||
end | ||
|
||
end | ||
end | ||
# | ||
# start_balance = 100.0 | ||
# withdrawal_amount = 91.0 | ||
# account = Bank::Account.new(1337, start_balance) | ||
# | ||
# account.withdraw(withdrawal_amount) | ||
# puts account.balance |
This file contains 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,65 @@ | ||
require 'csv' | ||
require 'date' | ||
|
||
module Bank | ||
class Account | ||
attr_reader :id, :balance, :date_opened | ||
|
||
def initialize(id = "", balance = "", date_opened = "") | ||
@id = id.to_i | ||
@balance = balance.to_i | ||
@date_opened = date_opened | ||
|
||
raise ArgumentError.new("balance must be >= 0") if @balance < 0 | ||
if @balance < 0 | ||
then | ||
puts "balance must be >= 0" | ||
end | ||
|
||
end | ||
|
||
def self.all | ||
array =[] | ||
CSV.open("../support/accounts.csv").each do |line| | ||
array << self.new(line[0], line[1], line[2]) | ||
end | ||
return array | ||
end | ||
|
||
def self.find(id) | ||
self.all.each do |account| | ||
if account.id == id then puts account.id | ||
return account.id | ||
end | ||
end | ||
raise ArgumentError.new("You must select a valid account") | ||
end | ||
|
||
def withdraw(amount) | ||
if amount > 0 | ||
if (@balance - amount) >= 0 | ||
@balance -= amount | ||
else | ||
puts "You have insufficient funds" | ||
end | ||
else | ||
puts "You must withraw an amount greater than $0.00 dollars" | ||
raise ArgumentError.new("you must withdraw an amount greater than $0.00") | ||
end | ||
return @balance | ||
end | ||
|
||
def deposit(amount) | ||
if amount >= 0 | ||
@balance += amount | ||
else | ||
puts "You must deposit an amount greater than $0.00 dollars" | ||
raise ArgumentError.new("you must deposit an amount greater than $0.00") | ||
end | ||
return @balance | ||
|
||
end | ||
end | ||
end | ||
|
||
Bank::Account.find(122) |
This file contains 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,38 @@ | ||
require_relative 'account.rb' | ||
module Bank | ||
class CheckingAccount < Account | ||
attr_reader :count | ||
|
||
def initialize(id = "", balance = 10, date_opened = "" ) | ||
@count = 0 | ||
super(id, balance, date_opened) | ||
if balance < 10 | ||
raise ArgumentError.new("balance must be >= 10") | ||
puts "balance must be >= 10" | ||
end | ||
end | ||
|
||
def withdraw(amount,limit= 10) | ||
total_withdrawl = amount + 1 | ||
super(total_withdrawl, -10) | ||
return @balance | ||
end | ||
|
||
|
||
def withdraw_using_check(amount,limit= -10) | ||
if count <= 3 | ||
withdraw((amount - 1)) | ||
@count += 1 | ||
elsif count >= 4 | ||
withdraw((amount + 1)) | ||
@count += 1 | ||
end | ||
return balance | ||
end | ||
|
||
end | ||
end | ||
opening_balance = 100 | ||
withdrawal_amount = 10 | ||
account = Bank::CheckingAccount.new(12345, opening_balance) | ||
puts account.withdraw_using_check(withdrawal_amount) |
This file contains 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,28 @@ | ||
require_relative 'account.rb' | ||
module Bank | ||
class SavingsAccount < Account | ||
def initialize(id = "", balance = 10, date_opened = "" ) | ||
super(id, balance, date_opened) | ||
|
||
raise ArgumentError.new("balance must be >= 10") if balance < 10 | ||
|
||
|
||
end | ||
|
||
def withdraw(amount) | ||
total_withdrawl = amount + 2 | ||
super(total_withdrawl, 10) | ||
#end | ||
return @balance | ||
end | ||
|
||
|
||
def add_interest(rate) | ||
|
||
if rate > 0 then @balance = balance * (1 + (rate/100)) | ||
else puts "Rate must be greater than 0" | ||
end | ||
return @balance | ||
end | ||
end | ||
end |
This file contains 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
require 'minitest/reporters' | ||
require 'minitest/skip_dsl' | ||
require_relative '../lib/account' | ||
require 'date' | ||
|
||
describe "Wave 1" do | ||
describe "Account#initialize" 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 | ||
|
@@ -136,36 +137,58 @@ | |
end | ||
end | ||
|
||
# TODO: change 'xdescribe' to 'describe' to run these tests | ||
xdescribe "Wave 2" do | ||
describe "Account.all" do | ||
it "Returns an array of all accounts" do | ||
# TODO: Your test code here! | ||
# Useful checks might include: | ||
# - Account.all returns an array | ||
# - Everything in the array is an Account | ||
# - The number of accounts is correct | ||
# - The ID and balance of the first and last | ||
# accounts match what's in the CSV file | ||
# Feel free to split this into multiple tests if needed | ||
|
||
|
||
describe "Account.all" do | ||
it "Returns an array of all accounts" do | ||
Bank::Account.all.must_be_kind_of Array, "Must be an array" | ||
|
||
end | ||
end | ||
|
||
describe "Test that each account has the correct number of items" do | ||
it "Fits the template for an account" do | ||
Bank::Account.all.each do |account| | ||
account.must_be_kind_of Bank::Account, "This should be an account" | ||
end | ||
end | ||
end | ||
|
||
describe "Tests that the number of accounts is correct" do | ||
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. Watch your indentation through here. |
||
it "Account.all should be same length as CSV file" do | ||
file_size = CSV.readlines("support/accounts.csv").size | ||
Bank::Account.all.length.must_equal file_size | ||
end | ||
end | ||
# | ||
describe "Tests that ID/Balance of 1st/nth account match whats in the CSV" do | ||
it "Matches the opening and closing of the .csv file" do | ||
CSV.readlines("support/accounts.csv")[0][0].to_i.must_equal Bank::Account.all[0].id.to_i, "the first item's ids should be the same" | ||
CSV.readlines("support/accounts.csv")[-1][0].to_i.must_equal Bank::Account.all[-1].id.to_i, "the last items's ids should be the same" | ||
|
||
CSV.readlines("support/accounts.csv")[0][1].to_i.must_equal Bank::Account.all[0].balance.to_i, "the first item's balance should be the same" | ||
CSV.readlines("support/accounts.csv")[-1][1].to_i.must_equal Bank::Account.all[-1].balance.to_i, "the last items's balance should be the same" | ||
end | ||
end | ||
|
||
describe "Account.find" do | ||
it "Returns an account that exists" do | ||
# TODO: Your test code here! | ||
Bank::Account.find(1217).must_be_kind_of Bank::Account, "This should be a valid account #{}" | ||
end | ||
|
||
it "Can find the first account from the CSV" do | ||
# TODO: Your test code here! | ||
it "Can find the first acount in the CSV" do | ||
Bank::Account.find(1212).must_be_kind_of Bank::Account, "This should show account #1212" | ||
end | ||
|
||
end | ||
describe "Account.find the last" do | ||
it "Can find the last account from the CSV" do | ||
# TODO: Your test code here! | ||
end | ||
Bank::Account.find(15153).must_be_kind_of Bank::Account, "This should show account #15156" | ||
end | ||
|
||
|
||
it "Raises an error for an account that doesn't exist" do | ||
# TODO: Your test code here! | ||
proc { | ||
Bank::Account.find(5) | ||
}.must_raise ArgumentError | ||
end | ||
end | ||
end |
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.
I like how your design of
Account#withdraw
makes this method andwithdraw_using_check
both very clean. Good work!