Guest User

Untitled

a guest
Jan 27th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. describe 'A vending machine', ->
  2.  
  3. beforeEach ->
  4. @m = new VendingMachine
  5.  
  6. it 'returns product count', ->
  7. expect(@m.getCount('coke')).toEqual(5)
  8.  
  9. it 'returns iced tea count', ->
  10. expect(@m.getCount('iced tea')).toEqual(5)
  11.  
  12. it 'accepts money', ->
  13. @m.addMoney(100)
  14. expect(@m.getBalance()).toEqual 100
  15.  
  16. @m.addMoney(-10)
  17. expect(@m.getBalance()).toEqual 100
  18.  
  19. it 'should sell us stuff', ->
  20. expect(@m.buy('coke')).toBe(null)
  21.  
  22. @m.addMoney 2
  23. expect(@m.buy('coke')).toEqual 'coke'
  24.  
  25. expect(@m.buy('iced tea')).toEqual 'iced tea'
  26.  
  27. expect(@m.buy('coke')).toBe(null)
  28.  
  29. it 'should not sell crack', ->
  30. @m.addMoney(1000)
  31. expect(@m.getBalance()).toEqual 1000
  32. expect(@m.buy('crack')).toBe(null)
  33.  
  34.  
  35. it 'should decrement the product count after buying', ->
  36. @m.addMoney(5)
  37. previous_count = @m.getCount('coke')
  38. @m.buy('coke')
  39. new_count = previous_count - 1
  40. expect(@m.getCount('coke')).toBe(new_count)
  41.  
  42. it 'should give change', ->
  43. @m.addMoney(2)
  44. @m.buy('coke')
  45. expect(@m.demandChange()).toEqual 1
  46. expect(@m.getBalance()).toEqual 0
  47.  
  48. it 'should just work', ->
  49. @m.addMoney(10)
  50. @m.buy('coke')
  51. @m.buy('iced tea')
  52. expect(@m.demandChange()).toEqual 8
  53. expect(@m.getBalance()).toEqual 0
  54. expect(@m.buy('coke'))
Add Comment
Please, Sign In to add comment