Skip to content

Commit b1859d9

Browse files
committed
Add tests
1 parent b74ceaf commit b1859d9

File tree

5 files changed

+827
-0
lines changed

5 files changed

+827
-0
lines changed

filter/core.spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var assert = require('assert'),
2+
core = require('./core');
3+
4+
describe('Filter', function() {
5+
describe('#onlyEven()', function () {
6+
it('returns only those numbers that are even', function () {
7+
var array = [10,15,20,25,30,35];
8+
assert.deepEqual([10,20,30], core.onlyEven(array));
9+
});
10+
});
11+
12+
describe('#onlyOneWord()', function () {
13+
it('returns only those strings with a single word (no spaces)', function () {
14+
var array = ['return', 'phrases', 'with one word'];
15+
assert.deepEqual(['return', 'phrases'], core.onlyOneWord(array));
16+
});
17+
});
18+
19+
describe('#positiveRowsOnly()', function () {
20+
it('return only the rows in the matrix that have all positive integers', function () {
21+
var matrix = [[1, 10,-100],
22+
[2,-20, 200],
23+
[3, 30, 300]];
24+
var result = [[3, 30, 300]];
25+
assert.deepEqual(result, core.positiveRowsOnly(matrix));
26+
});
27+
});
28+
29+
describe('#allSameVowels()', function () {
30+
it('return only those words where all the vowels are the same', function () {
31+
var array = ['racecar', 'amalgam', 'oligopoly', 'zoom'];
32+
assert.deepEqual(['amalgam', 'zoom'], core.allSameVowels(array));
33+
});
34+
});
35+
});

map/core.spec.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var assert = require('assert'),
2+
core = require('./core');
3+
4+
describe('Map', function() {
5+
describe('#multiplyBy10()', function () {
6+
it('multiplies all elements in an array by 10', function () {
7+
var array = [45, 1, -10, 11, 250];
8+
assert.deepEqual([450, 10, -100, 110, 2500], core.multiplyBy10(array));
9+
});
10+
});
11+
12+
describe('#shiftRight()', function () {
13+
it('shifts items in an array to the right by one', function () {
14+
var array = [{ name: '' }, 10, "left-side"];
15+
assert.deepEqual(["left-side", { name: '' }, 10], core.shiftRight(array));
16+
});
17+
});
18+
19+
describe('#onlyVowels()', function () {
20+
it('removes any non-vowel character from words in an array', function () {
21+
var array = ['average', 'exceptional', 'amazing'];
22+
assert.deepEqual(['aeae', 'eeioa', 'aai'], core.onlyVowels(array));
23+
});
24+
});
25+
26+
describe('#doubleMatrix()', function () {
27+
it('doubles the numbers in the matrix, maintaining the same structure', function () {
28+
var matrix = [[1,2,3],
29+
[4,5,6],
30+
[7,8,9]];
31+
var result = [[2,4,6],
32+
[8,10,12],
33+
[14,16,18]];
34+
assert.deepEqual(result, core.doubleMatrix(matrix));
35+
});
36+
});
37+
});

reduce/core.spec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var assert = require('assert'),
2+
core = require('./core');
3+
4+
describe('Reduce', function() {
5+
describe('#sum()', function () {
6+
it('sum all the numbers in the array', function () {
7+
var array = [10,15,20,25,30,35];
8+
assert.equal(135, core.sum(array));
9+
});
10+
});
11+
12+
describe('#productAll()', function () {
13+
it('return the product of all items in the matrix', function () {
14+
var matrix = [[1, 2, 3],
15+
[4, 5],
16+
[6]];
17+
assert.equal(720, core.productAll(matrix));
18+
});
19+
});
20+
21+
describe('#objectify()', function () {
22+
it('turns an array of arrays into an object', function () {
23+
var matrix = [['Thundercats', '80s'],
24+
['The Powerpuff Girls', '90s'],
25+
['Sealab 2021', '00s']];
26+
var result = { 'Thundercats': '80s',
27+
'The Powerpuff Girls': '90s',
28+
'Sealab 2021': '00s' };
29+
assert.deepEqual(result, core.objectify(matrix));
30+
});
31+
});
32+
33+
describe('#luckyNumbers()', function () {
34+
it('return a fortune like sentence with lucky numbers', function () {
35+
var array = [30, 48, 11, 5, 32];
36+
var result = 'Your lucky numbers are: 30, 48, 11, 5, and 32';
37+
assert.equal(result, core.luckyNumbers(array));
38+
});
39+
});
40+
});

0 commit comments

Comments
 (0)