-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathTest.js
38 lines (33 loc) · 1 KB
/
Test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const fs = require('fs');
const TESTS_FOLDER = './LeetcodeProblemsTests/Algorithms/';
const REGEX_PATTERN_HIDDEN_FILES = /(^|\/)\.[^\/\.]/g;
var test_all = async function() {
try {
const problems = await loadProblems();
for(i in problems) {
console.log("Solving: " + problems[i]);
const problem = require(TESTS_FOLDER + problems[i]);
if (typeof(problem.test) !=='undefined') {
problem.test();
console.log("End of the solution for : " + problems[i] + " \n\n");
} else {
console.warn(problem, "The problem " + problems[i] + " doesn't have a test method implemented.");
}
}
} catch (error) {
throw new Error(error);
}
}
var loadProblems = () => {
return new Promise(function (resolve, reject) {
fs.readdir(TESTS_FOLDER, (error, files) => {
if (error) {
reject(error);
} else {
problems = files.filter(item => !(REGEX_PATTERN_HIDDEN_FILES).test(item));
resolve(problems);
}
})
});
}
test_all();