Created
July 14, 2017 06:07
-
-
Save ryanivandsouza/ad6c1353a3813f410b861b1739beb424 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/xinuvus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<script src="https://wzrd.in/standalone/expect@latest"></script> | |
<script src="https://wzrd.in/standalone/deep-freeze@latest"></script> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
const addCounter = (list) => { | |
return [...list, 0]; | |
} | |
const testAddCounter = () => { | |
const listBefore = [] | |
const listAfter = [0] | |
deepFreeze(listBefore) | |
expect ( | |
addCounter(listBefore) | |
).toEqual(listAfter) | |
} | |
const removeCounter = (list, index) => { | |
return [...list.slice(0, index), | |
...list.slice(index + 1)] | |
} | |
const testRemoveCounter = () => { | |
const listBefore = [0, 1, 2, 3] | |
const listAfter = [0, 2, 3] | |
deepFreeze(listBefore) | |
expect( | |
removeCounter(listBefore, 1) | |
).toEqual(listAfter) | |
} | |
const incrementCounter = (list, index) => { | |
return [...list.slice(0, index), | |
list[index] + 1, | |
...list.slice(index + 1)] | |
} | |
const testIncrementCounter = () => { | |
const listBefore = [0, 1, 2, 3] | |
const listAfter = [0, 2, 2, 3] | |
deepFreeze(listBefore) | |
expect( | |
incrementCounter(listBefore, 1) | |
).toEqual(listAfter) | |
} | |
testAddCounter() | |
testRemoveCounter() | |
testIncrementCounter() | |
console.log('All tests passed!') | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const addCounter = (list) => { | |
return [...list, 0]; | |
} | |
const testAddCounter = () => { | |
const listBefore = [] | |
const listAfter = [0] | |
deepFreeze(listBefore) | |
expect ( | |
addCounter(listBefore) | |
).toEqual(listAfter) | |
} | |
const removeCounter = (list, index) => { | |
return [...list.slice(0, index), | |
...list.slice(index + 1)] | |
} | |
const testRemoveCounter = () => { | |
const listBefore = [0, 1, 2, 3] | |
const listAfter = [0, 2, 3] | |
deepFreeze(listBefore) | |
expect( | |
removeCounter(listBefore, 1) | |
).toEqual(listAfter) | |
} | |
const incrementCounter = (list, index) => { | |
return [...list.slice(0, index), | |
list[index] + 1, | |
...list.slice(index + 1)] | |
} | |
const testIncrementCounter = () => { | |
const listBefore = [0, 1, 2, 3] | |
const listAfter = [0, 2, 2, 3] | |
deepFreeze(listBefore) | |
expect( | |
incrementCounter(listBefore, 1) | |
).toEqual(listAfter) | |
} | |
testAddCounter() | |
testRemoveCounter() | |
testIncrementCounter() | |
console.log('All tests passed!')</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const addCounter = (list) => { | |
return [...list, 0]; | |
} | |
const testAddCounter = () => { | |
const listBefore = [] | |
const listAfter = [0] | |
deepFreeze(listBefore) | |
expect ( | |
addCounter(listBefore) | |
).toEqual(listAfter) | |
} | |
const removeCounter = (list, index) => { | |
return [...list.slice(0, index), | |
...list.slice(index + 1)] | |
} | |
const testRemoveCounter = () => { | |
const listBefore = [0, 1, 2, 3] | |
const listAfter = [0, 2, 3] | |
deepFreeze(listBefore) | |
expect( | |
removeCounter(listBefore, 1) | |
).toEqual(listAfter) | |
} | |
const incrementCounter = (list, index) => { | |
return [...list.slice(0, index), | |
list[index] + 1, | |
...list.slice(index + 1)] | |
} | |
const testIncrementCounter = () => { | |
const listBefore = [0, 1, 2, 3] | |
const listAfter = [0, 2, 2, 3] | |
deepFreeze(listBefore) | |
expect( | |
incrementCounter(listBefore, 1) | |
).toEqual(listAfter) | |
} | |
testAddCounter() | |
testRemoveCounter() | |
testIncrementCounter() | |
console.log('All tests passed!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment