bank-account_spec.lua

localBankAccount=require('bank-account')describe('bank-ccount',function()it('should have a balance of zero after opening a new account',function()localaccount=BankAccount:new()assert.equal(0,account:balance())end)it('should allow deposits',function()localaccount=BankAccount:new()account:deposit(45)assert.equal(45,account:balance())end)it('should allow multiple deposits',function()localaccount=BankAccount:new()account:deposit(10)account:deposit(25)assert.equal(35,account:balance())end)it('should require deposits to be positive',function()localaccount=BankAccount:new()assert.has.errors(function()account:deposit(0)end)assert.has.errors(function()account:deposit(-1)end)end)it('should allow withdrawals',function()localaccount=BankAccount:new()account:deposit(20)account:withdraw(10)assert.equal(10,account:balance())end)it('should allow multiple withdrawals',function()localaccount=BankAccount:new()account:deposit(100)account:withdraw(10)account:withdraw(25)assert.equal(65,account:balance())end)it('should require withdrawals to be positive',function()localaccount=BankAccount:new()account:deposit(100)assert.has.errors(function()account:withdraw(0)end)assert.has.errors(function()account:withdraw(-1)end)end)it('should not allow accounts to be overdrawn',function()localaccount=BankAccount:new()assert.has.errors(function()account:withdraw(1)end)end)it('should allow multiple independent accounts to be created',function()localaccount1=BankAccount:new()localaccount2=BankAccount:new()account1:deposit(100)account2:deposit(42)assert.are.equal(100,account1:balance())assert.are.equal(42,account2:balance())end)it('should allow accounts to be closed',function()localaccount=BankAccount:new()account:close()end)it('should now allow deposits to a closed account',function()localaccount=BankAccount:new()account:close()assert.has.errors(function()account:deposit(1)end)end)it('should not allow withdrawals from a closed account',function()localaccount=BankAccount:new()account:deposit(10)account:close()assert.has.errors(function()account:withdraw(1)end)end)end)