local BankAccount = require('bank-account') describe('bank-ccount', function() it('should have a balance of zero after opening a new account', function() local account = BankAccount:new() assert.equal(0, account:balance()) end) it('should allow deposits', function() local account = BankAccount:new() account:deposit(45) assert.equal(45, account:balance()) end) it('should allow multiple deposits', function() local account = BankAccount:new() account:deposit(10) account:deposit(25) assert.equal(35, account:balance()) end) it('should require deposits to be positive', function() local account = BankAccount:new() assert.has.errors(function() account:deposit(0) end) assert.has.errors(function() account:deposit(-1) end) end) it('should allow withdrawals', function() local account = BankAccount:new() account:deposit(20) account:withdraw(10) assert.equal(10, account:balance()) end) it('should allow multiple withdrawals', function() local account = 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() local account = 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() local account = BankAccount:new() assert.has.errors(function() account:withdraw(1) end) end) it('should allow multiple independent accounts to be created', function() local account1 = BankAccount:new() local account2 = 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() local account = BankAccount:new() account:close() end) it('should now allow deposits to a closed account', function() local account = BankAccount:new() account:close() assert.has.errors(function() account:deposit(1) end) end) it('should not allow withdrawals from a closed account', function() local account = BankAccount:new() account:deposit(10) account:close() assert.has.errors(function() account:withdraw(1) end) end) end)