انتقل إلى المحتوى
أمين أبوزيد
BEG-057

التحقق من الكود المولَّد بالذكاء الاصطناعي

  • 5 درس
  • 59 دقيقة قراءة
  • 2.5 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • قراءة الكود المولَّد وتتبّعه
  • اختباره
  • كود يبدو صحيحاً لكنه خاطئ
  • التراخيص والنزاهة الأكاديمية

تعلّم أولًا

59 دقيقة قراءة · 2.5 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Read and trace AI-generated code line by line and explain what it does before using it.
  2. Write tests that check generated code against the requirement, including boundaries and invalid input.
  3. Spot plausible-but-wrong code: off-by-one errors, missing edge cases, wrong complexity, invented library calls.
  4. Explain licensing and academic-integrity rules for AI-generated code and disclose AI use where required.

الدروس

  1. 01الكود المولَّد مسودة وليس إجابة12 د قراءة
  2. 02قراءة كود لم تكتبه وتتبّعه12 د قراءة
  3. 03اختبار الكود المولَّد وفق المتطلب11 د قراءة
  4. 04التراخيص والنزاهة والإفصاح12 د قراءة
  5. 05عرض عملي: اكتشاف خطأ خفي في بحث ثنائي مولَّد باستخدام الاختبارات12 د قراءة

المختبر والتمارين

Lab

BEG-057-LAB1 · Trust but verify

Outcomes: 1–4 · Time: ~2.5 h

  1. Ask an assistant for three methods from earlier labs: a search, a hash map operation, and a Library borrowing rule.
  2. For each, write the tests first from the requirement (normal, boundary, invalid input); do not paste the generated code yet.
  3. Paste the code, run the tests, and fix every failure. Document at least one defect found (what, how the test caught it, the fix).
  4. Explain the final code in your own words in comments or the README, and add a disclosure line stating the AI use.

Acceptance: tests written before the code is pasted; at least one defect found and documented; final code explained in your own words in comments or the README.

Exercises (assessment: given generated code with hidden defects, find them with tests; score = defects caught and explained)

IDOutcomeTask
BEG-057-EX011Trace this generated code with [3, 4] and write what it returns and what it should: int sum(int[] a){int s=0; for(int i=0;i<a.length-1;i++) s+=a[i]; return s;}
BEG-057-EX022Write four tests, from the requirement only, for int indexOf(int[] sorted, int target) returning -1 when absent.
BEG-057-EX033Name the problem: a generated method calls String.isNullOrEmpty(s).
BEG-057-EX043A generated "find duplicates" method uses List.contains inside a loop. State its complexity and a better approach.
BEG-057-EX052A teammate writes expected values by running the generated code and copying its output. Explain the risk.
BEG-057-EX064Write a two-sentence disclosure for code you drafted with an assistant, and list two things you must never paste into a public assistant.
أظهر الحلول
  • EX01 Returns 3 (loop stops one early, skips the last item); it should return 7. The bound should be i < a.length.
  • EX02 For example: [] with 5 gives -1; [5] with 5 gives 0; [1,3,5,7] with 7 gives 3; [1,3,5,7] with 4 gives -1.
  • EX03 An invented method: String has no static isNullOrEmpty. Use s == null || s.isEmpty() (or isBlank if blank counts).
  • EX04 O(n²) because contains is O(n). Use a HashSet: O(n) time, O(n) space.
  • EX05 The test then copies any bug into the expectations and cannot fail; expected values must come from the requirement.
  • EX06 For example: "Binary search was first drafted with an AI assistant. I wrote the tests from the requirement, found and fixed a boundary bug, and can explain every line." Never paste secrets or credentials, customer or personal data, or private code (check your policy).

الاختبار

Outcomes: O1 read and trace · O2 test against the requirement · O3 spot plausible-but-wrong code · O4 licensing, integrity, disclosure.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1Before using generated code you should:O1
  2. 2A trace table records:O1
  3. 3Who is responsible for AI-generated code you submit?O1
  4. 4Tests for generated code should be written from the:O2
  5. 5Writing the tests before pasting the code helps because:O2
  6. 6Which input set is best for a search method?O2
  7. 7for (int i = 1; i < a.length; i++) used to visit every item is an example of a(n):O3
  8. 8A call to a method that does not exist in the library is called:O3
  9. 9A generated loop calls list.contains on every item. The risk is:O3
  10. 10Honest disclosure of AI use includes:O4

الجزء العملي

Assessment: given generated code with hidden defects, find them with tests and explain each (score = defects caught and explained), plus lab BEG-057-LAB1 and exercises BEG-057-EX01 to EX06. Pass: at least half of the hidden defects caught and explained, tests written before the code, and at least 8 of 10 quiz answers correct.

أخطاء شائعة

Writing tests that copy the generated code's behavior instead of the requirement; accepting code you cannot explain; ignoring the complexity of the generated solution.

التقييم

Given generated code with hidden defects, find them with tests; score = defects caught and explained.

الصلة بالمسار الوظيفي

Reviewing AI-written code is part of every pull request today; JNR-055 applies this to a team workflow.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.