diff --git a/LeetcodeProblemsTests/Algorithms/medium/K_Closest_Points_to_Origin_Test.js b/LeetcodeProblemsTests/Algorithms/medium/K_Closest_Points_to_Origin_Test.js index 13f7345..24a6f0e 100644 --- a/LeetcodeProblemsTests/Algorithms/medium/K_Closest_Points_to_Origin_Test.js +++ b/LeetcodeProblemsTests/Algorithms/medium/K_Closest_Points_to_Origin_Test.js @@ -4,14 +4,14 @@ var kClosest = require("../../../LeetcodeProblems/Algorithms/medium/K_Closest_Po function test1() { var points = [[1,3],[-2,2]]; var output = [[-2,2]]; - assert.strictEqual(kClosest(points,1), output); + assert.deepStrictEqual(kClosest(points,1), output); } function test2() { var points = [[3,3],[5,-1],[-2,4]]; var output = [[-2,4],[3,3]]; - assert.strictEqual(kClosest(points,2), output); + assert.deepStrictEqual(kClosest(points,2).sort, output.sort); } function test() { diff --git a/Test.js b/Test.js index 2bc826d..f96160f 100644 --- a/Test.js +++ b/Test.js @@ -3,57 +3,65 @@ const fs = require("fs"); const TESTS_FOLDERS = [ - // "./LeetcodeProblemsTests/Algorithms/easy/", - "./LeetcodeProblemsTests/Algorithms/medium/" - // "./LeetcodeProblemsTests/Algorithms/hard/" + "./LeetcodeProblemsTests/Algorithms/easy/", + "./LeetcodeProblemsTests/Algorithms/medium/", + "./LeetcodeProblemsTests/Algorithms/hard/" ] const REGEX_PATTERN_HIDDEN_FILES = /(^|\/)\.[^\/\.]/g; var test_all = async function () { try { - console.log("problems"); - const problems = await loadProblemsFiles(); - // console.log(problems); - for (i in problems) { - console.log("Solving: " + problems[i]); - - const tests = require(problems[i]); - console.log("*" * 100); - if (Object.keys(tests).length == 0) { - console.warn("🔴 The problem " + problems[i] + " doesn't have a test method implemented.\n"); - continue; - } - for(testIdx in tests) { - tests[testIdx](); - } - console.log("✅ Tests for " + problems[i] + " run successfully \n"); - } + var problems = []; + for(const i in TESTS_FOLDERS) { + var folder = TESTS_FOLDERS[i]; + var new_problems = await loadProblemsFiles(folder); // await + problems = problems.concat(new_problems); + }; + console.log(problems); + + var solvePromises = problems.map(solve); + + await Promise.all(solvePromises) } catch (error) { console.log(error); throw new Error(error); } }; -var loadProblemsFiles = () => { - return new Promise(function (resolve, reject) { - const problems = []; - - for(i in TESTS_FOLDERS) { - folder = TESTS_FOLDERS[i]; - fs.readdir(folder, (error, files) => { - if (error) { - console.log("........................................................................"); - reject(error); - } else { - console.log(folder); - new_problems = files.filter((item) => !REGEX_PATTERN_HIDDEN_FILES.test(item)); - new_problems = new_problems.map((item) => folder + item); - // console.log(new_problems); - resolve(new_problems); - } - }); +var solve = (problem) => { + try { + console.log("Solving: " + problem); + + const tests = require(problem); + console.log("*" * 100); + if (Object.keys(tests).length == 0) { + console.warn("🔴 The problem " + problem + " doesn't have a test method implemented.\n"); + return; } + for(testIdx in tests) { + tests[testIdx](); + } + console.log("✅ Tests for " + problem + " run successfully \n"); + } catch (error) { + console.log(error); + throw new Error(error); + } +} + +var loadProblemsFiles = (folder) => { + return new Promise(function (resolve, reject) { + fs.readdir(folder, (error, files) => { + if (error) { + reject(error); + } else { + console.log(folder); + new_problems = files.filter((item) => !REGEX_PATTERN_HIDDEN_FILES.test(item)); + new_problems = new_problems.map((item) => folder + item); + + resolve(new_problems); + } + }); }); };