Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
77d4577
Create module and class
jjjousun Feb 21, 2017
d93f491
Passed Wave 1 tests
jjjousun Feb 22, 2017
1da6eed
Ran tests
jjjousun Feb 22, 2017
3a9f3e9
Wrote spec for checking Account.all is Class Array
jjjousun Feb 22, 2017
02c2f15
Created .all Class Method
jjjousun Feb 23, 2017
6c36961
Fixed spec for .all
jjjousun Feb 23, 2017
bd22de8
Wrote spec for everything in array is an Account
jjjousun Feb 23, 2017
d98b20d
Actually changed nothing yet again, just accidently committed
jjjousun Feb 23, 2017
d44f8db
Wrote specs for .all method to check proper length
jjjousun Feb 23, 2017
0e39b17
Wrote spec for checking ID and balance, accounts and CSV
jjjousun Feb 23, 2017
b74dbf5
Wrote spec to test that .find returns an existing account
jjjousun Feb 23, 2017
e4b46ce
Made .find method
jjjousun Feb 23, 2017
ae18448
Added and fixed ArgumentError in case id argument isn't valid
jjjousun Feb 23, 2017
a57f69f
Test spec for an account that doesn't exist for .find
jjjousun Feb 23, 2017
dba4900
Wrote specs for intialize test, withdraw with fee test
jjjousun Feb 24, 2017
38f660d
Modified methods for initialize and withdraw
jjjousun Feb 24, 2017
9616fe9
Changed something maybe
jjjousun Feb 24, 2017
607e170
Wrote test for returning unchanged balance if would be below 0
jjjousun Feb 24, 2017
ae9e2d7
Wrote spec for interest method checks
jjjousun Feb 24, 2017
9124448
Updated code for add interest method so that it returns the right thing
jjjousun Feb 24, 2017
1bd838a
Created Checking Account Class with inheritance from Bank::Account; a…
jjjousun Feb 24, 2017
3e8e4bf
Uncommented first test spec to check if new instance is the right class
jjjousun Feb 24, 2017
40d18be
Specs for withdraw method
jjjousun Feb 24, 2017
832d533
Fixed withdraw method to make sure FEE doesn't make it negative
jjjousun Feb 24, 2017
8875c11
Finished spec for withdrawing using checks, the special fee
jjjousun Feb 25, 2017
33522c8
Fixed method for withdraw using checks, logic was off by 1 when going…
jjjousun Feb 25, 2017
1bd1551
Finish spec tests for reset checks method
jjjousun Feb 25, 2017
b8c0726
Updated some errant blank lines in account, account specs, savings, s…
jjjousun Feb 25, 2017
4708b37
Created spec_helper
jjjousun Mar 1, 2017
06c0f6c
Deleted all the requires
jjjousun Mar 1, 2017
f05528e
Deleted all the requires
jjjousun Mar 1, 2017
db6bb79
Deleted all the requires
jjjousun Mar 1, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions lib/account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# bank account that allows new accounts, deposit and withdrawals
# jou-jou sun
# last edit 2/21/17
require 'csv'

module Bank
class Account
attr_reader :id, :balance

def initialize(id, balance)
@id = id
@balance = balance
if @balance < 0
raise ArgumentError.new "The starting balance must be positive"
end
end

def withdraw(withdrawal_amount)
if withdrawal_amount < 0
raise ArgumentError.new "Withdrawal must be positive"
end
if withdrawal_amount > @balance
print "Account will be in negative with this withdrawal"
return @balance
else
@balance -= withdrawal_amount
return @balance
end
end

def deposit(deposit)
if deposit < 0
raise ArgumentError.new "Deposit must be positive"
end
@balance += deposit
return @balance
end


def self.all
accounts_array = []

each_account = CSV.open("/Users/jou-jousun/ada/projects/BankAccounts/support/accounts.csv")

each_account.each do |account|
accounts_array << Account.new(account[0].to_i, account[1].to_i)
end
return accounts_array
#get info from CSV
#create new instances of Accounts
#push each new Account instances into an accounts_array
#return the array
end

#.find(id) when you input id, it will return the Account (instance) with that id
def self.find(id) #could use Class variable here instead of loading Accounts array each time
Account.all.each do |account|
if account.id == id
return account
end
end
raise ArgumentError.new "Account doesn't exist"
end
end #end of class
end #end of module
43 changes: 43 additions & 0 deletions lib/checking_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module Bank
CH_FEE = 1.00
OVR_FEE = 2.00

class CheckingAccount < Bank::Account
attr_reader :count

def initialize(id, balance)
super(id, balance)
@count = 0
end

def withdraw(withdraw_amount)
if @balance - withdraw_amount - CH_FEE < 0
print "Balance cannot be less than $0"
return @balance
else
@balance -= withdraw_amount + CH_FEE
end
end#end of withdraw def

def withdraw_using_check(amount)
if amount < 0
print "Withdrawal must be positive"
end
if @balance - amount < -10.0
print "Overdraft limit of -$10.00 is reached"
return @balance
elsif @count < 3
@count += 1
@balance -= amount
elsif @count >= 3
@count += 1
@balance -= amount + 2.00
end#end of if loop
end#end of withdraw_using_check method

def reset_checks
@count = 0
end

end#end of Class
end#end of Module
39 changes: 39 additions & 0 deletions lib/savings_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Bank
SV_FEE = 2.00

class SavingsAccount < Bank::Account

def initialize(id, balance)
super(id, balance)
if @balance < 10.0
raise ArgumentError.new "The starting balance must over $10.00"
end#end of if
end#end of def

def withdraw(withdraw_amount)
# "Outputs a warning if the balance would go below $10"
# "Doesn't modify the balance if it would go below $10"
# "Doesn't modify the balance if the fee would put it below $10"

if @balance - withdraw_amount < 10.0
print "Balance cannot be less than $10"
return @balance
elsif @balance - withdraw_amount - SV_FEE < 10.0
return @balance
else
@balance -= withdraw_amount + SV_FEE
end
end#end of withdraw def

def add_interest(rate)
if rate < 0
raise ArgumentError.new "The interest rate must be positive"
else
interest = balance * rate/100
@balance = @balance + interest
return interest
end#end of if/else
end#end of interest def

end#end of Class
end#end of module
40 changes: 32 additions & 8 deletions specs/account_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require 'minitest/autorun'
require 'minitest/reporters'
require 'minitest/skip_dsl'
require_relative '../lib/account'
require_relative 'spec_helper'
require_relative '../lib/savings_account'

describe "Wave 1" do
describe "Account#initialize" do
Expand Down Expand Up @@ -67,7 +65,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
Expand Down Expand Up @@ -134,38 +132,64 @@
}.must_raise ArgumentError
end
end
end
end #end of Wave 1

# 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
@accounts.class.must_equal Array
# - Everything in the array is an Account
(@accounts.each { |i| return i }).must_be_instance_of Bank::Account
# - The number of accounts is correct
@accounts.length.must_equal 12
# - The ID and balance of the first and last
# accounts match what's in the CSV file
@accounts[0].id.must_equal 1212
@accounts[0].balance.must_equal 1235667
@accounts[11].id.must_equal 15156
@accounts[11].balance.must_equal 4356772
# Feel free to split this into multiple tests if needed
end
end

describe "Account.find" do

before do
@accounts = Bank::Account.all
end

it "Returns an account that exists" do
# TODO: Your test code here!
account = Bank::Account.find(@accounts[0].id)
account.must_be_instance_of Bank::Account
end

it "Can find the first account from the CSV" do
# TODO: Your test code here!
account = Bank::Account.find(1212)
account.id.must_equal @accounts[0].id
end

it "Can find the last account from the CSV" do
# TODO: Your test code here!
account = Bank::Account.find(15156)
account.id.must_equal @accounts[-1].id
end

it "Raises an error for an account that doesn't exist" do
# TODO: Your test code here!
proc {
Bank::Account.find(111111)
}.must_raise ArgumentError
end
end
end
end
Loading