-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
❇: Added basic quiz infrastructure (no production impact)
- Loading branch information
1 parent
292fe2f
commit 854a4fa
Showing
5 changed files
with
106 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
{ | ||
"intro": [ | ||
{ | ||
"regex": ".*" | ||
"output": { | ||
"regex": ".*", | ||
"output": "Hi" | ||
}, | ||
"code": { | ||
"regex": ".*", | ||
"code": [ | ||
"console.log('Hi');", | ||
"console.log('Hi')", | ||
"console.log(\"Hi\");", | ||
"console.log(\"Hi\")" | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
function testRegex(regex: string, text: string): boolean { | ||
const re = new RegExp(regex); | ||
return re.test(text); | ||
} | ||
function checkText(text1: string, text2: string): boolean { | ||
return text1 === text2; | ||
} | ||
/* | ||
{ | ||
"output": { | ||
"regex": ".*", | ||
"output": "Hi" | ||
}, | ||
"code": { | ||
"regex": ".*", | ||
"code": ["console.log('Hi');"] | ||
} | ||
} | ||
*/ | ||
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 (!isCodeCorrect) { | ||
console.log(codesCheck, code); | ||
console.log("Code is not correct 2"); | ||
return false; | ||
} | ||
if (!checkText(outputCheck, output)) { | ||
console.log(outputCheck, output); | ||
console.log("Output is not correct 2"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
export function doTests(testCases: any[], code: string, output: string): boolean { | ||
for (const testCase of testCases) { | ||
if (!doTest(testCase, code, output)) { | ||
// console.log(testCase); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
export function getTestCase(slug: string): { regex?: string | undefined; output?: string | undefined; }[] | undefined { | ||
|
||
return [ | ||
{ | ||
regex: '.*', | ||
|
||
}, | ||
{ | ||
output: '200', | ||
} | ||
] | ||
export function getTestCase(slug: string): any[] { | ||
const testCases = JSON.parse(Deno.readTextFileSync(`./courses/testcases.json`)); | ||
try { | ||
return testCases[slug]; | ||
} | ||
catch { | ||
return []; | ||
} | ||
} |