Skip to content

Commit c5cfb17

Browse files
RubinderSshaariqch
authored andcommitted
Added tests (shaariqch#24)
1 parent a254077 commit c5cfb17

File tree

20 files changed

+435
-114
lines changed

20 files changed

+435
-114
lines changed

.github/workflows/js_tests.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: JavaScript_Tests
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
strategy:
11+
matrix:
12+
node-version: [8.x, 10.x, 12.x]
13+
14+
steps:
15+
- uses: actions/checkout@v1
16+
- name: Use Node.js ${{ matrix.node-version }}
17+
uses: actions/setup-node@v1
18+
with:
19+
node-version: ${{ matrix.node-version }}
20+
- name: npm install, build, and test
21+
run: |
22+
node tests/run_tests.js
23+
env:
24+
CI: true

easy/largest_product_by_3_integers/largest_product_by_3_integers.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,4 @@ function largestProductBy3Integers(arr) {
3131
return a * b * c;
3232
}
3333

34-
/* Test */
35-
console.log(largestProductBy3Integers([-10, -10, 5, 2])); // 500
36-
console.log(largestProductBy3Integers([5, 8, 9, 0])); // 360
34+
module.exports = largestProductBy3Integers;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"title": "largest_product_by_3_integers",
3+
"tests": [
4+
{
5+
"desc": 1,
6+
"args": [[-10, -10, 5, 2]],
7+
"exp": 500
8+
},
9+
{
10+
"desc": 2,
11+
"args": [[5, 8, 9, 0]],
12+
"exp": 360
13+
}
14+
]
15+
}

easy/matrix_spiral/matrix_spiral.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,4 @@ function displayMatrixSpiral(mat) {
4343
console.log(spiral.join('\n'));
4444
}
4545

46-
/* Test */
47-
const mat = [
48-
[1, 2, 3, 4, 5],
49-
[6, 7, 8, 9, 10],
50-
[11, 12, 13, 14, 15],
51-
[16, 17, 18, 19, 20],
52-
];
53-
54-
displayMatrixSpiral(mat);
46+
module.exports = matrixSpiral;

easy/matrix_spiral/test.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"title": "matrix_spiral",
3+
"tests": [
4+
{
5+
"desc": 1,
6+
"args": [[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]],
7+
"exp": [1, 2, 3, 4, 5, 10, 15, 20, 19, 18, 17, 16, 11, 6, 7, 8, 9, 14, 13, 12]
8+
},
9+
{
10+
"desc": 2,
11+
"args": [[[1]]],
12+
"exp": [1]
13+
},
14+
{
15+
"desc": 3,
16+
"args": [[[]]],
17+
"exp": []
18+
}
19+
]
20+
}

hard/largest_sum_adjacent_numbers/largest_sum_adjacent_numbers.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,4 @@ function largestSumOfNonAdjacentNumbers(arr) {
1313
return Math.max(inc, exc);
1414
}
1515

16-
/* Test */
17-
console.log(largestSumOfNonAdjacentNumbers([1, 4, 10, 50, 80, 38])); // 92
18-
console.log(largestSumOfNonAdjacentNumbers([1, 2])); // 2
19-
console.log(largestSumOfNonAdjacentNumbers([2, 1])); // 2
16+
module.exports = largestSumOfNonAdjacentNumbers;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"title": "largest_sum_adjacent_numbers",
3+
"tests": [
4+
{
5+
"desc": 1,
6+
"args": [[1, 4, 10, 50, 80, 38]],
7+
"exp": 92
8+
},
9+
{
10+
"desc": 2,
11+
"args": [[1, 2]],
12+
"exp": 2
13+
},
14+
{
15+
"desc": 3,
16+
"args": [[2, 1]],
17+
"exp": 2
18+
}
19+
]
20+
}

hard/longest_increasing_subsequence/longest_increasing_subsequence.js

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,36 +47,4 @@ function longest_increasing_subsequence_Array(arr) {
4747
return lis.reduce((acc, val) => (acc.length >= val.length ? acc : val));
4848
}
4949

50-
/* Test */
51-
const tests = [
52-
{
53-
desc: '1',
54-
args: [[0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]],
55-
res: 6,
56-
},
57-
{
58-
desc: '2',
59-
args: [[1, 2, 3, 4, 5]],
60-
res: 5,
61-
},
62-
{
63-
desc: '3',
64-
args: [[1, 2, 0, 4, 5]],
65-
res: 4,
66-
},
67-
{
68-
desc: '4',
69-
args: [[1, 2, 0, -4, 5]],
70-
res: 3,
71-
},
72-
];
73-
74-
tests.forEach((test) => {
75-
const receivedResult = longest_increasing_subsequence_Length(...test.args);
76-
if (test.res === receivedResult) {
77-
console.log(`Pass: ${test.desc} | ${test.args.join(', ')} => ${test.res}`);
78-
} else {
79-
console.log(`\nFail: ${test.desc}`);
80-
console.log(`expected: ${test.res} | received: ${receivedResult}\n`);
81-
}
82-
});
50+
module.exports = longest_increasing_subsequence_Length;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"title": "longest_increasing_subsequence",
3+
"tests": [
4+
{
5+
"desc": 1,
6+
"args": [[0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]],
7+
"exp": 6
8+
},
9+
{
10+
"desc": 2,
11+
"args": [[1, 2, 3, 4, 5]],
12+
"exp": 5
13+
},
14+
{
15+
"desc": 3,
16+
"args": [[1, 2, 0, 4, 5]],
17+
"exp": 4
18+
},
19+
{
20+
"desc": 4,
21+
"args": [[1, 2, 0, -4, 5]],
22+
"exp": 3
23+
}
24+
]
25+
}

hard/longest_increasing_subsequence/tests.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)