Skip to content

Commit

Permalink
Make testcases for all lessons #10
Browse files Browse the repository at this point in the history
  • Loading branch information
m7medVision committed Feb 26, 2024
1 parent e9cf75f commit eb15964
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion courses/loops/iterate-using-while-loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ console.log(ourArray);
`ourArray`.

<div class="quiz">
نعتذر عن عدم وجود اختبار لهذا الدرس حالياً. نحن نعمل بجد لإعداد اختبارات لجميع الدروس وسنقوم بتوفيرها في أقرب وقت ممكن.
قم بطباعة الأرقام من 1 إلى 5 باستخدام حلقة <code>while</code>.
</div>
2 changes: 1 addition & 1 deletion courses/objects/testing-objects-for-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ checkForProperty({ top: "hat", bottom: "pants" }, "middle"); // false
يُرجع استدعاء الدالة `checkForProperty` الأول `true`، بينما يُرجع الثاني `false`.

<div class="quiz">
نعتذر عن عدم وجود اختبار لهذا الدرس حالياً. نحن نعمل بجد لإعداد اختبارات لجميع الدروس وسنقوم بتوفيرها في أقرب وقت ممكن.
قم بكتابة سطر برمجي يقوم بالتحقق من وجود خاصية `speed` على الكائن `fighter` و من ثم طباعة النتيجة في الكونسول.
</div>
9 changes: 9 additions & 0 deletions precodes/objects/testing-objects-for-properties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fighter = {
name: 'Mig 29',
country: 'Egypt',
speed: 2.25,
speedUnit: 'Mach',
maxAltitude: 65000,
maxAltitudeUnit: 'ft',
operator: 'Egyptian Air Force',
}
37 changes: 37 additions & 0 deletions testcases/loops/iterate-using-while-loops.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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
} catch (error) {
return `${error}`;
}
}
if (code.includes("while")) {
const output = handleCodeRun(code);
console.log(output);
if (JSON.stringify(output) === JSON.stringify([ '1', '2', '3', '4', '5' ])) {
isPass = true;
} else {
isPass = false;
msg = "الرجاء التأكد من استخدام الحلقة الصحيحة للتكرار.";
}
} else {
isPass = false;
msg = "الرجاء التأكد من استخدام الحلقة الصحيحة للتكرار.";
}
8 changes: 8 additions & 0 deletions testcases/objects/testing-objects-for-properties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// the code must contain this line console.log(fighter.hasOwnProperty("speed"))
const regex = /console.log\((\w+)\.hasOwnProperty\("(\w+)"\)\)/;
if (regex.test(code)) {
isPass = true;
} else {
isPass = false;
msg = "قم بالتأكد من استخدام الدالة hasOwnProperty() للتأكد من وجود الخاصية في الكائن المعطى."
}

0 comments on commit eb15964

Please sign in to comment.