Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe 'A vending machine', ->
- beforeEach ->
- @m = new VendingMachine
- it 'returns product count', ->
- expect(@m.getCount('coke')).toEqual(5)
- it 'returns iced tea count', ->
- expect(@m.getCount('iced tea')).toEqual(5)
- it 'accepts money', ->
- @m.addMoney(100)
- expect(@m.getBalance()).toEqual 100
- @m.addMoney(-10)
- expect(@m.getBalance()).toEqual 100
- it 'should sell us stuff', ->
- expect(@m.buy('coke')).toBe(null)
- @m.addMoney 2
- expect(@m.buy('coke')).toEqual 'coke'
- expect(@m.buy('iced tea')).toEqual 'iced tea'
- expect(@m.buy('coke')).toBe(null)
- it 'should not sell crack', ->
- @m.addMoney(1000)
- expect(@m.getBalance()).toEqual 1000
- expect(@m.buy('crack')).toBe(null)
- it 'should decrement the product count after buying', ->
- @m.addMoney(5)
- previous_count = @m.getCount('coke')
- @m.buy('coke')
- new_count = previous_count - 1
- expect(@m.getCount('coke')).toBe(new_count)
- it 'should give change', ->
- @m.addMoney(2)
- @m.buy('coke')
- expect(@m.demandChange()).toEqual 1
- expect(@m.getBalance()).toEqual 0
- it 'should just work', ->
- @m.addMoney(10)
- @m.buy('coke')
- @m.buy('iced tea')
- expect(@m.demandChange()).toEqual 8
- expect(@m.getBalance()).toEqual 0
- expect(@m.buy('coke'))
Add Comment
Please, Sign In to add comment