The Practical Test Pyramid (Fowler)
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
// diagonal starting from top left | |
function primary(matrix) { | |
const items = [] | |
for (let i = 0; i < matrix.length; i++) { | |
items.push(matrix[i][i]) | |
} | |
return items | |
} | |
// diagonal starting from top right |
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
function getLongestArray(...arrays) { | |
let longestIndex = 0 | |
let longestLength = arrays[0].length | |
if (arrays.length === 1) { | |
return arrays[0] | |
} | |
for (let i = 1; i < arrays.length; i++) { | |
if (arrays[i].length > longestLength) { | |
longestIndex = i | |
longestLength = arrays[i].length |
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 isJSON = subject => { | |
if (typeof subject !== 'string') { | |
return false; | |
} | |
try { | |
JSON.parse(subject); | |
return true; | |
} catch (error) { | |
return false; | |
} |
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
// SWITCH | |
function getFriendlySwitch(k) { | |
switch(k) { | |
case "0": | |
return "value1"; | |
case "1": | |
return "value2"; | |
case "2": | |
return "value3"; | |
case "3": |
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
curl --header "Content-Type: application/json" \ | |
--request POST \ | |
--data '{"clientId":"'"$CLIENT_ID"'","clientSecret":"'"$CLIENT_SECRET"'"}' \ | |
http://localhost:8888/auth | |
# usage: | |
# cat curl-test.sh | CLIENT_ID=lksdjflkjsdf CLIENT_SECRET=aoksdjflkjasdf bash |
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
/* todo: write your tests using truth table syntax | |
test('xor',` | |
[ | |
[0, 0, 0], | |
[0, 1, 1],.. etc | |
] | |
a b result | |
0 0 0 | |
0 1 1 |
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
current_file_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | |
# usage: put this in the same file as a script that wants to use the current files |
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
kill-process-by-port() { | |
local port_num="$1" | |
local process_id=$(lsof -i :$port_num | awk 'END{print $2}') | |
if [ -z "$process_id" ] ; then | |
echo "Nothing running on port $port_num" | |
else | |
kill -9 "$process_id" | |
echo "process running on port $port_num killed." | |
fi | |
} |
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 backoff = (ms: number) => | |
new Promise(resolve => setTimeout(_ => resolve(), ms)) |