Skip to content

Commit

Permalink
✴ Refactor code in DoTest.ts to improve readability and maintainability
Browse files Browse the repository at this point in the history
  • Loading branch information
m7medVision committed Jan 12, 2024
1 parent 11f8f24 commit bb78ae4
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions islands/DoTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,39 @@ function checkText(text1: string, text2: string): boolean {
*/
function doTest(testCase: any, code: string, output: string): boolean {
const { code: codeTest, output: outputTest } = testCase;
const codeRegex = codeTest.regex;
const outputRegex = outputTest.regex;
const codesCheck = codeTest.code;
const outputCheck = outputTest.output;
if (!testRegex(codeRegex, code)) {
console.log(codeRegex, code);
console.log("Code is not correct 1");
return false;
}
if (!testRegex(outputRegex, output)) {
console.log(outputRegex, output);
console.log("Output is not correct 1");
return false;
}

let isCodeCorrect = false;
for (const codeCheck of codesCheck) {
if (checkText(codeCheck, code)) {
isCodeCorrect = true;
break;
if (codeTest)
{
const codeRegex = codeTest.regex;
const codesCheck = codeTest.code;
if (!testRegex(codeRegex, code)) {
return false;
}

let isCodeCorrect = false;
for (const codeCheck of codesCheck) {
if (checkText(codeCheck, code)) {
isCodeCorrect = true;
break;
}
}

if (!isCodeCorrect) {
return false;
}
}

if (!isCodeCorrect) {
console.log(codesCheck, code);
console.log("Code is not correct 2");
return false;
if (outputTest) {
const outputRegex = outputTest.regex;
const outputCheck = outputTest.output;

if (!testRegex(outputRegex, output)) {
return false;
}
if (!checkText(outputCheck, output)) {
return false;
}
}
if (!checkText(outputCheck, output)) {
console.log(outputCheck, output);
console.log("Output is not correct 2");
return false;
if (!codeTest && !outputTest) {
return true;
}
return true;
}
Expand Down

0 comments on commit bb78ae4

Please sign in to comment.