From f7d87b65543b6ea6ef397816af0f6f73cb9d3282 Mon Sep 17 00:00:00 2001
From: Mohammed <88824957+m7medVision@users.noreply.github.com>
Date: Thu, 7 Mar 2024 13:07:15 +0400
Subject: [PATCH] Make testcases for all lessons #10 working!!!
---
courses/objects/accessing-nested-objects.md | 2 +-
precodes/objects/accessing-nested-objects.js | 14 +++++++
testcases/objects/accessing-nested-objects.js | 41 +++++++++++++++++++
.../objects/manipulating-complex-objects.js | 2 +-
4 files changed, 57 insertions(+), 2 deletions(-)
create mode 100644 precodes/objects/accessing-nested-objects.js
create mode 100644 testcases/objects/accessing-nested-objects.js
diff --git a/courses/objects/accessing-nested-objects.md b/courses/objects/accessing-nested-objects.md
index b219ebd..e94b077 100644
--- a/courses/objects/accessing-nested-objects.md
+++ b/courses/objects/accessing-nested-objects.md
@@ -30,5 +30,5 @@ console.log(ourStorage.desk.drawer);
`OurStorage.desk.drawer` هو سلسلة `stapler`.
-نعتذر عن عدم وجود اختبار لهذا الدرس حالياً. نحن نعمل بجد لإعداد اختبارات لجميع الدروس وسنقوم بتوفيرها في أقرب وقت ممكن.
+قم بكتابة الكود الذي يقوم بطباعة السرعة القصوى للطائرة فقط!!!
diff --git a/precodes/objects/accessing-nested-objects.js b/precodes/objects/accessing-nested-objects.js
new file mode 100644
index 0000000..05305e0
--- /dev/null
+++ b/precodes/objects/accessing-nested-objects.js
@@ -0,0 +1,14 @@
+const fighter = {
+ name: 'Mig 29',
+ country: 'Egypt',
+ speed: {
+ maxSpeed: 1500,
+ maxSpeedUnit: 'km/h',
+ minSpeed: 400,
+ minSpeedUnit: 'km/h',
+ },
+ maxAltitude: 65000,
+ maxAltitudeUnit: 'ft',
+ operator: 'Egyptian Air Force',
+ weapons: ['Missiles', 'Bombs', 'Guns'],
+}
\ No newline at end of file
diff --git a/testcases/objects/accessing-nested-objects.js b/testcases/objects/accessing-nested-objects.js
new file mode 100644
index 0000000..7991589
--- /dev/null
+++ b/testcases/objects/accessing-nested-objects.js
@@ -0,0 +1,41 @@
+/**
+ * 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 = [];
+ 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 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 = "حاول مرة أخرى";
+}
\ No newline at end of file
diff --git a/testcases/objects/manipulating-complex-objects.js b/testcases/objects/manipulating-complex-objects.js
index dd5436b..9469fab 100644
--- a/testcases/objects/manipulating-complex-objects.js
+++ b/testcases/objects/manipulating-complex-objects.js
@@ -41,4 +41,4 @@ if (!code.includes('october-73')) {
msg = "هل قمت بتعديل القيمة الصحيحة؟";
}
-}
+}
\ No newline at end of file