|
1 |
| -/* eslint-disable no-useless-escape */ |
2 |
| -/* eslint-disable no-undef */ |
3 |
| -const fs = require("fs"); |
4 |
| - |
5 |
| -const TESTS_FOLDERS = [ |
6 |
| - "./LeetcodeProblemsTests/Algorithms/easy/", |
7 |
| - "./LeetcodeProblemsTests/Algorithms/medium/", |
8 |
| - "./LeetcodeProblemsTests/Algorithms/hard/" |
9 |
| -] |
10 |
| - |
11 |
| -const REGEX_PATTERN_HIDDEN_FILES = /(^|\/)\.[^\/\.]/g; |
12 |
| - |
13 |
| -var test_all = async function () { |
14 |
| - try { |
15 |
| - var problems = []; |
16 |
| - for(const i in TESTS_FOLDERS) { |
17 |
| - var folder = TESTS_FOLDERS[i]; |
18 |
| - var new_problems = await loadProblemsFiles(folder); // await |
19 |
| - problems = problems.concat(new_problems); |
20 |
| - }; |
21 |
| - console.log(problems); |
22 |
| - |
23 |
| - var solvePromises = problems.map(solve); |
24 |
| - |
25 |
| - await Promise.all(solvePromises) |
26 |
| - } catch (error) { |
27 |
| - console.log(error); |
28 |
| - throw new Error(error); |
29 |
| - } |
30 |
| -}; |
31 |
| - |
32 |
| -var solve = (problem) => { |
33 |
| - try { |
34 |
| - console.log("Solving: " + problem); |
35 |
| - |
36 |
| - const tests = require(problem); |
37 |
| - console.log("*" * 100); |
38 |
| - if (Object.keys(tests).length == 0) { |
39 |
| - console.warn("🔴 The problem " + problem + " doesn't have a test method implemented.\n"); |
40 |
| - return; |
41 |
| - } |
42 |
| - for(testIdx in tests) { |
43 |
| - tests[testIdx](); |
44 |
| - } |
45 |
| - console.log("✅ Tests for " + problem + " run successfully \n"); |
46 |
| - } catch (error) { |
47 |
| - console.log(error); |
48 |
| - throw new Error(error); |
49 |
| - } |
50 |
| -} |
51 |
| - |
52 |
| -var loadProblemsFiles = (folder) => { |
53 |
| - return new Promise(function (resolve, reject) { |
54 |
| - fs.readdir(folder, (error, files) => { |
55 |
| - if (error) { |
56 |
| - reject(error); |
57 |
| - } else { |
58 |
| - console.log(folder); |
59 |
| - new_problems = files.filter((item) => !REGEX_PATTERN_HIDDEN_FILES.test(item)); |
60 |
| - new_problems = new_problems.map((item) => folder + item); |
61 |
| - |
62 |
| - resolve(new_problems); |
63 |
| - } |
64 |
| - }); |
65 |
| - }); |
66 |
| -}; |
67 |
| - |
68 |
| -test_all(); |
0 commit comments