Skip to content

Commit

Permalink
improving testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
TeaByte committed Mar 11, 2024
1 parent e3edb61 commit f4f4fb3
Show file tree
Hide file tree
Showing 34 changed files with 151 additions and 213 deletions.
13 changes: 7 additions & 6 deletions courses/strings/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ order: 1

```js
const doubleQuote = "This is a string";
const singleQuote = 'This is also a string';
const singleQuote = "This is also a string";
```

السبب وراء رغبتك في استخدام نوع واحد من علامات الاقتباس على الآخر هو إذا كنت
Expand Down Expand Up @@ -61,7 +61,7 @@ const sampleStr = 'Adam said, "Yazan is learning JavaScript"'.;
| `\\` | backslash | شرطة معكوفة |
| `n\` | newline | سطر جديد |
| `t\` | tab | مسافه |
| `r\` | carriage return | ? |
| `r\` | carriage return | carriage return |
| `b\` | backspace | مسافة إلى الوراء |
| `f\` | form feed | تغذية النموذج |

Expand All @@ -83,8 +83,9 @@ World;
```

<div class="quiz">
قم بإنشاء متغير و إستخدم تسلسلات التخطي لطباعة النص التالي على وحدة التحكم <br>
<code>Ich Bin Yazan</code><br>
<code> am Yazan</code><br>
يجب أن تكون في أسطر مختلفة
قم بإنشاء متغير و إستخدم تسلسلات التخطي لطباعة النص التالي على وحدة التحكم:<br>
<div dir="ltr">
<code>Hello</code><br>
<code>World</code><br>
</div>
</div>
2 changes: 1 addition & 1 deletion courses/variables/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ console.log(myName);
<div class="quiz">
1. قم بطباعة أي شيء على الشاشة واضغط تشغيل لمشاهده النتيجه
<br>
2. اضغط على اختبار
2. اضغط على اختبار لإرسال النتيجة
</div>

يمكنك التعرف على المزيد عن الكائن `console` في مستندات
Expand Down
2 changes: 1 addition & 1 deletion courses/variables/uninitialized-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ console.log(c); // "undefined String!"
</mark>

<div class="quiz">
قم بتعريف أي متغير ثم غير قيمته إلى كلمه <code>عربي</code>.
قم بتعريف متغير غير المهيء ثم غير قيمته إلى كلمه <code>عربي</code>.
</div>
5 changes: 0 additions & 5 deletions testcases/EXAM_TEST_TEMPLATE.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* Executes the provided code and captures the output of console.log.
* @param {string} code - The code to be executed.
* @returns {string} - The captured output of console.log.
*/
function handleCodeRun(code) {
try {
const capturedOutput = [];
Expand Down
3 changes: 1 addition & 2 deletions testcases/arrays/intro.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const regex = /(let|const|var)\s*\w*\s*=\s*\[(("|`|')\w*\3(,|)(\s*|)(,|)(\s*|))*\]/g;

if (regex.test(code)) {
isPass = true;
msg = 'Good job!';
}
else {
isPass = false;
msg = "تحقق من الشروط المطلوبة"
}
6 changes: 3 additions & 3 deletions testcases/arrays/manipulate-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ function handleCodeRun(code) {
return `${error}`;
}
}

code += "\nconsole.log(myArray);";
const out = handleCodeRun(code);

if (out === '["b","c","d","Ali",35]') {
isPass = true;
msg = "Pass!";
} else {
isPass = false;
msg = "Fail!";
msg = "Fail!";
}
5 changes: 2 additions & 3 deletions testcases/arrays/multidimensional-index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const regex = /console.log\(\s*arr\[3\]\[1\]\s*\)/
const regex = /console.log\(\s*arr\[3\]\[1\]\s*\)/

if (regex.test(code)) {
isPass = true
msg = "مبروك، الجواب صحيح"
} else {
isPass = false
msg = "الجواب خاطئ"
}
7 changes: 3 additions & 4 deletions testcases/comments.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const regex = /(?<!\\)\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\/|(?<!\\)\/\/[^\n]*(?:\n|$)/

if (regex.test(code)) {
isPass = true,
msg = ""
isPass = true
} else {
isPass = false;
msg = "لا يوجد تعليقات في الكود"
msg = "لا يوجد تعليقات في الكود"
}
23 changes: 11 additions & 12 deletions testcases/compound-operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,22 @@ function handleCodeRun(code) {
return `${error}`;
}
}

code += "\nconsole.log(myVar);";

try {
const output = handleCodeRun(code);
console.log("output",output);
if (output !== "15") {
isPass = false;
msg = "قيمة myVar غير صحيحة";
}
const output = handleCodeRun(code);
console.log("output", output);
if (output !== "15") {
msg = "قيمة myVar غير صحيحة";
}
} catch (error) {
isPass = false;
msg = error;
msg = error;
}

const regex = /myVar\s*\+\=\s*10/;
if (!regex.test(code)) {
isPass = false;
msg = "لم يتم إضافة 10 إلى قيمة myVar";
msg = "لم يتم إضافة 10 إلى قيمة myVar";
} else {
isPass = true;
msg = "اجابة صحيحة";
isPass = true;
}
3 changes: 1 addition & 2 deletions testcases/functions/global-scope.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
isPass = true;
msg = "Passes all the test cases";
isPass = true;
4 changes: 2 additions & 2 deletions testcases/functions/intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ function handleCodeRun(code) {
return `${error}`;
}
}

code += "\nconsole.log(area(5, 75));"
const output = handleCodeRun(code);
console.log(output);

if (output) {
if (output.includes("375")) {
isPass = true;
msg = "مبروك الحل صحيح"
} else {
isPass = false;
msg = "هناك خطاء ما تأكد من شروط الاختبار"
}
}
3 changes: 1 addition & 2 deletions testcases/intro.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
isPass = true;
msg = "";
isPass = true;
5 changes: 2 additions & 3 deletions testcases/loops/count-backwards-with-a-for-loop.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// for (let i = ___; i > ___; i -= ___) {
// console.log(i);
// }
if (code.include('for (let i = 10; i > 0; i -= 2) {')) { // TODO: convert to regex
if (code.includes('for (let i = 10; i > 0; i -= 2) {')) { // TODO: convert to regex
isPass = true;
} else {
isPass = false;
feedback = 'The code is not a for loop that counts backwards.';
msg = 'تحقق الرجاء من استخدام الحلقة الصحيحة للتكرار.';
}
5 changes: 2 additions & 3 deletions testcases/loops/iterate-using-for-loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ function handleCodeRun(code) {
return `${error}`;
}
}

if (code.includes("for")) {
let output = handleCodeRun(code+"\nconsole.log(oddNumbers);")
let output = handleCodeRun(code + "\nconsole.log(oddNumbers);")
output = output[output.length - 1];
if (output == JSON.stringify([1, 3, 5, 7, 9])) {
isPass = true;
} else {
isPass = false;
msg = "تأكد من النتائج";
}
} else {
isPass = false;
msg = "الرجاء التأكد من استخدام الحلقة الصحيحة للتكرار.";
}
7 changes: 3 additions & 4 deletions testcases/loops/iterate-using-while-loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ function handleCodeRun(code) {
return `${error}`;
}
}

if (code.includes("while")) {
const output = handleCodeRun(code);
const output = handleCodeRun(code);
console.log(output);
if (JSON.stringify(output) === JSON.stringify([ '1', '2', '3', '4', '5' ])) {
if (JSON.stringify(output) === JSON.stringify(['1', '2', '3', '4', '5'])) {
isPass = true;
} else {
isPass = false;
msg = "الرجاء التأكد من استخدام الحلقة الصحيحة للتكرار.";
}
} else {
isPass = false;
msg = "الرجاء التأكد من استخدام الحلقة الصحيحة للتكرار.";
}
62 changes: 31 additions & 31 deletions testcases/numbers/decimals.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
function handleCodeRun(code) {
try {
const capturedOutput = [];
const originalConsoleLog = console.log;
console.log = (...args) => {
capturedOutput.push(
args.map((arg) => {
if (typeof arg === "object" && arg !== null) {
return JSON.stringify(arg);
}
return arg.toString();
}).join(" "),
);
originalConsoleLog(...args);
};
if (code) {
eval(code);
}
console.log = originalConsoleLog;
return capturedOutput.join("\n");
} catch (error) {
return `${error}`;
try {
const capturedOutput = [];
const originalConsoleLog = console.log;
console.log = (...args) => {
capturedOutput.push(
args.map((arg) => {
if (typeof arg === "object" && arg !== null) {
return JSON.stringify(arg);
}
return arg.toString();
}).join(" "),
);
originalConsoleLog(...args);
};
if (code) {
eval(code);
}
console.log = originalConsoleLog;
return capturedOutput.join("\n");
} catch (error) {
return `${error}`;
}
}

const regexMyDec = /\bmyDecimal\b = 3\.14/;
const product_pattern = /product = myDecimal \* 4/;
const print_pattern = /console\.log\(product\)/;

if (regexMyDec.test(code) && product_pattern.test(code) && print_pattern.test(code)) {
const output = handleCodeRun(code);
if (output === "12.56") {
isPass = true;
msg = "اجابة صحيحة";
} else {
isPass = false;
msg = "قيمة myDecimal غير صحيحة";
}
const output = handleCodeRun(code);
if (output === "12.56") {
isPass = true;
msg = "اجابة صحيحة";
} else {
msg = "قيمة myDecimal غير صحيحة";
}
} else {
isPass = false;
msg = "لم يتم إنشاء متغير myDecimal وحساب قيمة المتغير product وطباعة قيمة المتغير product";
msg = "لم يتم إنشاء متغير myDecimal وحساب قيمة المتغير product وطباعة قيمة المتغير product";
}
5 changes: 2 additions & 3 deletions testcases/numbers/intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ function handleCodeRun(code) {
return `${error}`;
}
}

const output = handleCodeRun(code);

if (output != "50") {
isPass = false;
msg = "هناك خطاء في الكود";
} else {
const regexWidth = /(let|const|var)(\s*)width(\s*)?=(\s*)?10(;)?/g
Expand All @@ -33,10 +34,8 @@ if (output != "50") {
const regex = [regexWidth, regexLength, regexArea]
const results = regex.map((reg) => reg.test(code))
if (results.includes(false)) {
isPass = false;
msg = "هناك خطاء في الكود";
} else {
isPass = true;
msg = "احسنت";
}
}
10 changes: 2 additions & 8 deletions testcases/objects/accessing-nested-objects.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* Executes the provided code and captures the output of console.log.
* @param {string} code - The code to be executed.
* @returns {string} - The captured output of console.log.
*/
function handleCodeRun(code) {
try {
const capturedOutput = [];
Expand All @@ -27,15 +22,14 @@ function handleCodeRun(code) {
return `${error}`;
}
}

const output = handleCodeRun(code)
if (output == "1500") {
if (code.includes("console.log(1500)" || 'console.log("1500")' || "console.log('1500')")) {
isPass = false;
msg = "لا تحتال علينا, حاول مرة أخرى";
} else {
isPass = true;
}
} else {
isPass = false;
msg = "حاول مرة أخرى";
msg = "حاول مرة أخرى";
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// the code must contain console.log(fighter[Country])
const codeRegex = /console.log\(fighter\[Country\]\)/;

if (codeRegex.test(code)) {
isPass = true;
} else {
isPass = false;
msg = "مالك ما عارف تحل؟؟؟؟"
msg = "تاكد من الشروط";
}
7 changes: 1 addition & 6 deletions testcases/objects/accessing-object-properties.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* Executes the provided code and captures the output of console.log.
* @param {string} code - The code to be executed.
* @returns {string} - The captured output of console.log.
*/
function handleCodeRun(code) {
try {
const capturedOutput = [];
Expand All @@ -27,11 +22,11 @@ function handleCodeRun(code) {
return `${error}`;
}
}

const output = handleCodeRun(code);
// TODO: make the quiz uncheatable by checking the the code logic
if (output == "19812") {
isPass = true;
} else {
isPass = false;
msg = "الناتج خطاء"
}
2 changes: 0 additions & 2 deletions testcases/objects/delete-properties-from-object.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// if code contain `delete fighter.operator` then isPass = true
if (code.includes("delete") && code.includes("operator") && code.includes("fighter")) {
isPass = true;
} else {
isPass = false;
msg = "الله يبارك فيك ركز شوية وحاول مره ثانية"
}
Loading

0 comments on commit f4f4fb3

Please sign in to comment.