22/* eslint-disable no-undef */
33const fs = require ( "fs" ) ;
44
5+ const PROBLEMS_FOLDERS = [
6+ "./LeetcodeProblems/Algorithms/easy/" ,
7+ "./LeetcodeProblems/Algorithms/medium/" ,
8+ "./LeetcodeProblems/Algorithms/hard/"
9+ ] ;
10+
511const TESTS_FOLDERS = [
612 "./LeetcodeProblemsTests/Algorithms/easy/" ,
713 "./LeetcodeProblemsTests/Algorithms/medium/" ,
814 "./LeetcodeProblemsTests/Algorithms/hard/"
9- ]
15+ ] ;
1016
1117const REGEX_PATTERN_HIDDEN_FILES = / ( ^ | \/ ) \. [ ^ \/ \. ] / g;
1218
13- var test_all = async function ( ) {
19+ const get_all_tests = async function ( paths ) {
20+ let problems = [ ] ;
21+ for ( const i in paths ) {
22+ const folder = paths [ i ] ;
23+ const new_problems = await loadProblemsFiles ( folder ) ; // await
24+ problems = problems . concat ( new_problems ) ;
25+ }
26+ return problems ;
27+ } ;
28+
29+ const test_all = async function ( ) {
1430 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 ) ;
2231
32+ const problems = await get_all_tests ( TESTS_FOLDERS ) ;
33+ console . log ( problems ) ;
2334 var solvePromises = problems . map ( solve ) ;
2435
25- await Promise . all ( solvePromises )
36+ await Promise . all ( solvePromises ) ;
2637 } catch ( error ) {
2738 console . log ( error ) ;
2839 throw new Error ( error ) ;
2940 }
3041} ;
3142
32- var solve = ( problem ) => {
43+ const solve = ( problem ) => {
3344 try {
3445 console . log ( "Solving: " + problem ) ;
3546
@@ -47,9 +58,9 @@ var solve = (problem) => {
4758 console . log ( error ) ;
4859 throw new Error ( error ) ;
4960 }
50- }
61+ } ;
5162
52- var loadProblemsFiles = ( folder ) => {
63+ const loadProblemsFiles = ( folder ) => {
5364 return new Promise ( function ( resolve , reject ) {
5465 fs . readdir ( folder , ( error , files ) => {
5566 if ( error ) {
@@ -65,10 +76,40 @@ var loadProblemsFiles = (folder) => {
6576 } ) ;
6677} ;
6778
79+ const get_missing_tests = async function ( ) {
80+ const tests = await get_all_tests ( TESTS_FOLDERS ) ;
81+ const problems = await get_all_tests ( PROBLEMS_FOLDERS ) ;
82+
83+ const hasTestStatus = problems . reduce ( ( status , problemPath ) => {
84+ const baseIndex = PROBLEMS_FOLDERS . findIndex ( ( basePath ) =>
85+ problemPath . startsWith ( basePath )
86+ ) ;
87+
88+ let testPath = problemPath
89+ . replace ( PROBLEMS_FOLDERS [ baseIndex ] , TESTS_FOLDERS [ baseIndex ] )
90+ . replace ( / \. j s $ / , "_Test.js" ) ;
91+
92+ status . push ( {
93+ problem : problemPath ,
94+ hasTest : tests . includes ( testPath )
95+ } ) ;
96+
97+ return status ;
98+ } , [ ] ) ;
99+ const missingTests = hasTestStatus . filter ( ( stat ) => ! stat . hasTest ) ;
100+ console . log ( "Total Problems:" , problems . length ) ;
101+ console . log ( "Missing Tests:" , missingTests . length ) ;
102+
103+ if ( missingTests . length ) {
104+ console . table ( missingTests ) ;
105+ }
106+ } ;
107+
68108if ( process . argv . length > 2 ) {
69109 const path = process . argv . pop ( ) ;
70110 solve ( path ) ;
71111} else {
72112 test_all ( ) ;
113+ get_missing_tests ( ) ;
73114}
74115
0 commit comments