Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import expect from 'expect';
- import deepfreeze from 'deepfreeze';
- const addCounter = (list) => {
- return [...list, 0];
- };
- const removeCounter = (list, index) => {
- return [
- ...list.slice(0, index),
- ...list.slice(index + 1)
- ];
- };
- const incrementCounter = (list, index) => {
- return [
- ...list.slice(0, index),
- list[index] + 1,
- ...list.slice(index + 1)
- ];
- };
- const testAddCounter = () => {
- const listBefore = [];
- const listAfter = [0];
- deepfreeze(listBefore);
- expect(
- addCounter(listBefore)
- ).toEqual(listAfter);
- };
- const testRemoveCounter = () => {
- const listBefore = [0, 10, 20];
- const listAfter = [0, 20];
- deepfreeze(listBefore);
- expect(
- removeCounter(listBefore, 1)
- ).toEqual(listAfter);
- };
- const testIncrementCounter = () => {
- const listBefore = [0, 10, 20];
- const listAfter = [0, 11, 20];
- deepfreeze(listBefore);
- expect(
- incrementCounter(listBefore, 1)
- ).toEqual(listAfter);
- };
- testAddCounter();
- testRemoveCounter();
- testIncrementCounter();
- console.log('All Tests Passed.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement