Skip to content

Add function to count and find problems with missing tests #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 54 additions & 13 deletions Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,45 @@
/* eslint-disable no-undef */
const fs = require("fs");

const PROBLEMS_FOLDERS = [
"./LeetcodeProblems/Algorithms/easy/",
"./LeetcodeProblems/Algorithms/medium/",
"./LeetcodeProblems/Algorithms/hard/"
];

const TESTS_FOLDERS = [
"./LeetcodeProblemsTests/Algorithms/easy/",
"./LeetcodeProblemsTests/Algorithms/medium/",
"./LeetcodeProblemsTests/Algorithms/hard/"
]
];

const REGEX_PATTERN_HIDDEN_FILES = /(^|\/)\.[^\/\.]/g;

var test_all = async function () {
const get_all_tests = async function (paths) {
let problems = [];
for(const i in paths) {
const folder = paths[i];
const new_problems = await loadProblemsFiles(folder); // await
problems = problems.concat(new_problems);
}
return problems;
};

const test_all = async function () {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename the following functions?

  • test_all -> runAllTests
  • solve -> solveProblem

Also, let's use camelCase everywhere. I noticed we have a mix. A linter rule could solve this too (not need to do it here).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated all variables and functions in this file to be camelCase
I also added the eslint rule to make it visible and noticed there are a lot of issues

I can create another PR to solve all of those linter issues

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it! that'd be amazing.

try {
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);

const problems = await get_all_tests(TESTS_FOLDERS);
console.log(problems);
var solvePromises = problems.map(solve);

await Promise.all(solvePromises)
await Promise.all(solvePromises);
} catch (error) {
console.log(error);
throw new Error(error);
}
};

var solve = (problem) => {
const solve = (problem) => {
try {
console.log("Solving: " + problem);

Expand All @@ -47,9 +58,9 @@ var solve = (problem) => {
console.log(error);
throw new Error(error);
}
}
};

var loadProblemsFiles = (folder) => {
const loadProblemsFiles = (folder) => {
return new Promise(function (resolve, reject) {
fs.readdir(folder, (error, files) => {
if (error) {
Expand All @@ -65,10 +76,40 @@ var loadProblemsFiles = (folder) => {
});
};

const get_missing_tests = async function () {
const tests = await get_all_tests(TESTS_FOLDERS);
const problems = await get_all_tests(PROBLEMS_FOLDERS);

const hasTestStatus = problems.reduce((status, problemPath) => {
const baseIndex = PROBLEMS_FOLDERS.findIndex((basePath) =>
problemPath.startsWith(basePath)
);

let testPath = problemPath
.replace(PROBLEMS_FOLDERS[baseIndex], TESTS_FOLDERS[baseIndex])
.replace(/\.js$/, "_Test.js");

status.push({
problem: problemPath,
hasTest: tests.includes(testPath)
});

return status;
}, []);
const missingTests = hasTestStatus.filter((stat) => !stat.hasTest);
console.log("Total Problems:", problems.length);
console.log("Missing Tests:", missingTests.length);

if(missingTests.length) {
console.table(missingTests);
}
};

if (process.argv.length > 2) {
const path = process.argv.pop();
solve(path);
} else {
test_all();
get_missing_tests();
}