Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import expect from 'expect';
  2. import deepfreeze from 'deepfreeze';
  3.  
  4. const addCounter = (list) => {
  5. return [...list, 0];
  6. };
  7.  
  8. const removeCounter = (list, index) => {
  9. return [
  10. ...list.slice(0, index),
  11. ...list.slice(index + 1)
  12. ];
  13. };
  14.  
  15. const incrementCounter = (list, index) => {
  16. return [
  17. ...list.slice(0, index),
  18. list[index] + 1,
  19. ...list.slice(index + 1)
  20. ];
  21. };
  22.  
  23. const testAddCounter = () => {
  24. const listBefore = [];
  25. const listAfter = [0];
  26.  
  27. deepfreeze(listBefore);
  28.  
  29. expect(
  30. addCounter(listBefore)
  31. ).toEqual(listAfter);
  32. };
  33.  
  34. const testRemoveCounter = () => {
  35. const listBefore = [0, 10, 20];
  36. const listAfter = [0, 20];
  37.  
  38. deepfreeze(listBefore);
  39.  
  40. expect(
  41. removeCounter(listBefore, 1)
  42. ).toEqual(listAfter);
  43. };
  44.  
  45. const testIncrementCounter = () => {
  46. const listBefore = [0, 10, 20];
  47. const listAfter = [0, 11, 20];
  48.  
  49. deepfreeze(listBefore);
  50.  
  51. expect(
  52. incrementCounter(listBefore, 1)
  53. ).toEqual(listAfter);
  54. };
  55.  
  56. testAddCounter();
  57. testRemoveCounter();
  58. testIncrementCounter();
  59. console.log('All Tests Passed.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement