Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tdd Update #516

Merged
merged 6 commits into from
Jan 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ node_modules/
currentSnippet\.js
*.md.temp.js
.idea
test.sh
test/
test.sh
19 changes: 14 additions & 5 deletions scripts/tdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ if(isTravisCI() && process.env['TRAVIS_EVENT_TYPE'] !== 'cron' && process.env['T
process.exit(0);
}
// Declare paths
const SNIPPETS_PATH = './snippets';
const SNIPPETS_ACTIVE = './snippets';
const SNIPPETS_ARCHIVE = './snippets_archive';
const TEST_PATH = './test';

// Array of snippet names
const snippetFiles = fs.readdirSync(SNIPPETS_PATH, 'utf8').map(fileName => fileName.slice(0, -3));
const snippetFiles = [];

const snippetFilesActive = fs.readdirSync(SNIPPETS_ACTIVE, 'utf8').map(fileName => fileName.slice(0, -3));
const snippetFilesArchive = fs.readdirSync(SNIPPETS_ARCHIVE, 'utf8').map(fileName => fileName.slice(0, -3));

snippetFiles.push(...snippetFilesActive);
snippetFiles.push(...snippetFilesArchive);


// Current Snippet that depend on node_modules
const errSnippets = ['JSONToFile', 'readFileLines', 'UUIDGeneratorNode'];
Expand All @@ -32,10 +40,11 @@ snippetFiles
return fileName;
})
.map(fileName => {
const activeOrArchive = snippetFilesActive.includes(fileName) ? SNIPPETS_ACTIVE : SNIPPETS_ARCHIVE;
// Grab snippetData
const fileData = fs.readFileSync(`${SNIPPETS_PATH}/${fileName}.md`, 'utf8');
const fileData = fs.readFileSync(`${activeOrArchive}/${fileName}.md`, 'utf8');
// Grab snippet Code blocks
const fileCode = fileData.slice(fileData.indexOf('```js'), fileData.lastIndexOf('```') + 3);
const fileCode = fileData.slice(fileData.search(/```\s*js/i), fileData.lastIndexOf('```') + 3);
// Split code based on code markers
const blockMarkers = fileCode
.split('\n')
Expand Down Expand Up @@ -81,4 +90,4 @@ snippetFiles
// return fileName for later use
return fileName;
});

4 changes: 4 additions & 0 deletions test/JSONToDate/JSONToDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = arr => {
const dt = new Date(parseInt(arr.toString().substr(6)));
return `${dt.getDate()}/${dt.getMonth() + 1}/${dt.getFullYear()}`;
};
13 changes: 13 additions & 0 deletions test/JSONToDate/JSONToDate.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const JSONToDate = require('./JSONToDate.js');

test('Testing JSONToDate', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof JSONToDate === 'function', 'JSONToDate is a Function');
//t.deepEqual(JSONToDate(args..), 'Expected');
//t.equal(JSONToDate(args..), 'Expected');
//t.false(JSONToDate(args..), 'Expected');
//t.throws(JSONToDate(args..), 'Expected');
t.end();
});
1 change: 1 addition & 0 deletions test/RGBToHex/RGBToHex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
13 changes: 13 additions & 0 deletions test/RGBToHex/RGBToHex.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const RGBToHex = require('./RGBToHex.js');

test('Testing RGBToHex', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof RGBToHex === 'function', 'RGBToHex is a Function');
//t.deepEqual(RGBToHex(args..), 'Expected');
//t.equal(RGBToHex(args..), 'Expected');
//t.false(RGBToHex(args..), 'Expected');
//t.throws(RGBToHex(args..), 'Expected');
t.end();
});
4 changes: 4 additions & 0 deletions test/UUIDGeneratorBrowser/UUIDGeneratorBrowser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = () =>
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
);
13 changes: 13 additions & 0 deletions test/UUIDGeneratorBrowser/UUIDGeneratorBrowser.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const UUIDGeneratorBrowser = require('./UUIDGeneratorBrowser.js');

test('Testing UUIDGeneratorBrowser', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof UUIDGeneratorBrowser === 'function', 'UUIDGeneratorBrowser is a Function');
//t.deepEqual(UUIDGeneratorBrowser(args..), 'Expected');
//t.equal(UUIDGeneratorBrowser(args..), 'Expected');
//t.false(UUIDGeneratorBrowser(args..), 'Expected');
//t.throws(UUIDGeneratorBrowser(args..), 'Expected');
t.end();
});
10 changes: 10 additions & 0 deletions test/anagrams/anagrams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = str => {
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
return str
.split('')
.reduce(
(acc, letter, i) =>
acc.concat(anagrams(str.slice(0, i) + str.slice(i + 1)).map(val => letter + val)),
[]
);
};
13 changes: 13 additions & 0 deletions test/anagrams/anagrams.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const anagrams = require('./anagrams.js');

test('Testing anagrams', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof anagrams === 'function', 'anagrams is a Function');
//t.deepEqual(anagrams(args..), 'Expected');
//t.equal(anagrams(args..), 'Expected');
//t.false(anagrams(args..), 'Expected');
//t.throws(anagrams(args..), 'Expected');
t.end();
});
2 changes: 2 additions & 0 deletions test/arrayToHtmlList/arrayToHtmlList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module.exports = (arr, listID) =>
arr.map(item => (document.querySelector('#' + listID).innerHTML += `<li>${item}</li>`));
13 changes: 13 additions & 0 deletions test/arrayToHtmlList/arrayToHtmlList.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const arrayToHtmlList = require('./arrayToHtmlList.js');

test('Testing arrayToHtmlList', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof arrayToHtmlList === 'function', 'arrayToHtmlList is a Function');
//t.deepEqual(arrayToHtmlList(args..), 'Expected');
//t.equal(arrayToHtmlList(args..), 'Expected');
//t.false(arrayToHtmlList(args..), 'Expected');
//t.throws(arrayToHtmlList(args..), 'Expected');
t.end();
});
1 change: 1 addition & 0 deletions test/average/average.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = (...nums) => [...nums].reduce((acc, val) => acc + val, 0) / nums.length;
14 changes: 14 additions & 0 deletions test/average/average.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const test = require('tape');
const average = require('./average.js');

test('Testing average', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof average === 'function', 'average is a Function');
t.equal(average(9, 1), 5, 'The average of 1 & 9 is 5');
//t.deepEqual(average(args..), 'Expected');
//t.equal(average(args..), 'Expected');
//t.false(average(args..), 'Expected');
//t.throws(average(args..), 'Expected');
t.end();
});
7 changes: 7 additions & 0 deletions test/binarySearch/binarySearch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = (arr, val, start = 0, end = arr.length - 1) => {
if (start > end) return -1;
const mid = Math.floor((start + end) / 2);
if (arr[mid] > val) return binarySearch(arr, val, start, mid - 1);
if (arr[mid] < val) return binarySearch(arr, val, mid + 1, end);
return mid;
}
13 changes: 13 additions & 0 deletions test/binarySearch/binarySearch.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const binarySearch = require('./binarySearch.js');

test('Testing binarySearch', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof binarySearch === 'function', 'binarySearch is a Function');
//t.deepEqual(binarySearch(args..), 'Expected');
//t.equal(binarySearch(args..), 'Expected');
//t.false(binarySearch(args..), 'Expected');
//t.throws(binarySearch(args..), 'Expected');
t.end();
});
3 changes: 3 additions & 0 deletions test/bottomVisible/bottomVisible.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = () =>
document.documentElement.clientHeight + window.scrollY >=
(document.documentElement.scrollHeight || document.documentElement.clientHeight);
13 changes: 13 additions & 0 deletions test/bottomVisible/bottomVisible.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const bottomVisible = require('./bottomVisible.js');

test('Testing bottomVisible', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof bottomVisible === 'function', 'bottomVisible is a Function');
//t.deepEqual(bottomVisible(args..), 'Expected');
//t.equal(bottomVisible(args..), 'Expected');
//t.false(bottomVisible(args..), 'Expected');
//t.throws(bottomVisible(args..), 'Expected');
t.end();
});
1 change: 1 addition & 0 deletions test/byteSize/byteSize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = str => new Blob([str]).size;
13 changes: 13 additions & 0 deletions test/byteSize/byteSize.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const byteSize = require('./byteSize.js');

test('Testing byteSize', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof byteSize === 'function', 'byteSize is a Function');
//t.deepEqual(byteSize(args..), 'Expected');
//t.equal(byteSize(args..), 'Expected');
//t.false(byteSize(args..), 'Expected');
//t.throws(byteSize(args..), 'Expected');
t.end();
});
1 change: 1 addition & 0 deletions test/call/call.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = (key, ...args) => context => context[key](...args);
13 changes: 13 additions & 0 deletions test/call/call.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const call = require('./call.js');

test('Testing call', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof call === 'function', 'call is a Function');
//t.deepEqual(call(args..), 'Expected');
//t.equal(call(args..), 'Expected');
//t.false(call(args..), 'Expected');
//t.throws(call(args..), 'Expected');
t.end();
});
2 changes: 2 additions & 0 deletions test/capitalize/capitalize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module.exports = ([first, ...rest], lowerRest = false) =>
first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join(''));
13 changes: 13 additions & 0 deletions test/capitalize/capitalize.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const capitalize = require('./capitalize.js');

test('Testing capitalize', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof capitalize === 'function', 'capitalize is a Function');
//t.deepEqual(capitalize(args..), 'Expected');
//t.equal(capitalize(args..), 'Expected');
//t.false(capitalize(args..), 'Expected');
//t.throws(capitalize(args..), 'Expected');
t.end();
});
1 change: 1 addition & 0 deletions test/capitalizeEveryWord/capitalizeEveryWord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = str => str.replace(/\b[a-z]/g, char => char.toUpperCase());
13 changes: 13 additions & 0 deletions test/capitalizeEveryWord/capitalizeEveryWord.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const capitalizeEveryWord = require('./capitalizeEveryWord.js');

test('Testing capitalizeEveryWord', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof capitalizeEveryWord === 'function', 'capitalizeEveryWord is a Function');
//t.deepEqual(capitalizeEveryWord(args..), 'Expected');
//t.equal(capitalizeEveryWord(args..), 'Expected');
//t.false(capitalizeEveryWord(args..), 'Expected');
//t.throws(capitalizeEveryWord(args..), 'Expected');
t.end();
});
5 changes: 5 additions & 0 deletions test/chainAsync/chainAsync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = fns => {
let curr = 0;
const next = () => fns[curr++](next);
next();
};
13 changes: 13 additions & 0 deletions test/chainAsync/chainAsync.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const chainAsync = require('./chainAsync.js');

test('Testing chainAsync', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof chainAsync === 'function', 'chainAsync is a Function');
//t.deepEqual(chainAsync(args..), 'Expected');
//t.equal(chainAsync(args..), 'Expected');
//t.false(chainAsync(args..), 'Expected');
//t.throws(chainAsync(args..), 'Expected');
t.end();
});
4 changes: 4 additions & 0 deletions test/chunk/chunk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = (arr, size) =>
Array.from({ length: Math.ceil(arr.length / size) }, (v, i) =>
arr.slice(i * size, i * size + size)
);
13 changes: 13 additions & 0 deletions test/chunk/chunk.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const chunk = require('./chunk.js');

test('Testing chunk', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof chunk === 'function', 'chunk is a Function');
//t.deepEqual(chunk(args..), 'Expected');
//t.equal(chunk(args..), 'Expected');
//t.false(chunk(args..), 'Expected');
//t.throws(chunk(args..), 'Expected');
t.end();
});
1 change: 1 addition & 0 deletions test/clampNumber/clampNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
13 changes: 13 additions & 0 deletions test/clampNumber/clampNumber.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const clampNumber = require('./clampNumber.js');

test('Testing clampNumber', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof clampNumber === 'function', 'clampNumber is a Function');
//t.deepEqual(clampNumber(args..), 'Expected');
//t.equal(clampNumber(args..), 'Expected');
//t.false(clampNumber(args..), 'Expected');
//t.throws(clampNumber(args..), 'Expected');
t.end();
});
10 changes: 10 additions & 0 deletions test/cleanObj/cleanObj.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = (obj, keysToKeep = [], childIndicator) => {
Object.keys(obj).forEach(key => {
if (key === childIndicator) {
cleanObj(obj[key], keysToKeep, childIndicator);
} else if (!keysToKeep.includes(key)) {
delete obj[key];
}
});
return obj;
};
13 changes: 13 additions & 0 deletions test/cleanObj/cleanObj.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const cleanObj = require('./cleanObj.js');

test('Testing cleanObj', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof cleanObj === 'function', 'cleanObj is a Function');
//t.deepEqual(cleanObj(args..), 'Expected');
//t.equal(cleanObj(args..), 'Expected');
//t.false(cleanObj(args..), 'Expected');
//t.throws(cleanObj(args..), 'Expected');
t.end();
});
1 change: 1 addition & 0 deletions test/cloneRegExp/cloneRegExp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = regExp => new RegExp(regExp.source, regExp.flags);
13 changes: 13 additions & 0 deletions test/cloneRegExp/cloneRegExp.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('tape');
const cloneRegExp = require('./cloneRegExp.js');

test('Testing cloneRegExp', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof cloneRegExp === 'function', 'cloneRegExp is a Function');
//t.deepEqual(cloneRegExp(args..), 'Expected');
//t.equal(cloneRegExp(args..), 'Expected');
//t.false(cloneRegExp(args..), 'Expected');
//t.throws(cloneRegExp(args..), 'Expected');
t.end();
});