sh1k4ku commited on
Commit
eb9425b
Β·
verified Β·
1 Parent(s): 4023b62

Upload assignment2.html with huggingface_hub

Browse files
Files changed (1) hide show
  1. assignment2.html +23 -23
assignment2.html CHANGED
@@ -133,11 +133,11 @@
133
  <!-- ============ Q4 ============ -->
134
  <h2>Q4 &nbsp;Fault-Based Testing: Plant a Bug and Catch It <span class="pts">[3 pts] Β· playground</span></h2>
135
  <p>(a) Introduce <b>exactly one</b> single-line bug into <code>binary_search</code> so that <b>all three Q3 tests still pass</b> (the bug is invisible to the Q3 suite).
136
- (b) Give <b>one</b> extra test case that <b>distinguishes</b> the mutant from the original (original passes, mutant fails).</p>
137
- <p class="muted">Use the playground: edit the function to your mutant, enter your distinguishing test, and press <b>Run check</b>. It reports whether your mutant still passes the Q3 suite and whether your test separates the two.</p>
138
 
139
- <p style="margin-top:14px"><b>(a) Describe your one-line mutation</b> (form <code>from &rarr; to</code>):</p>
140
- <input class="txt" id="q4mutation" style="width:100%" placeholder="e.g. top = mid - 1 -> top = mid - 2">
141
 
142
  <div class="pg">
143
  <div class="pg-head">
@@ -302,7 +302,7 @@ const q4run = document.getElementById("q4run");
302
  const q4out = document.getElementById("q4out");
303
  const q4target = document.getElementById("q4target");
304
  const q4key = document.getElementById("q4key");
305
- let lastQ4 = { original_output:"", mutant_output:"" };
306
 
307
  const editor = CodeMirror.fromTextArea(document.getElementById("q4code"), {
308
  mode:"python", theme:"material-darker", lineNumbers:true, indentUnit:4, tabSize:4,
@@ -370,23 +370,23 @@ async function runQ4(){
370
  pyodide.globals.set("__TGT", q4target.value || "");
371
  pyodide.globals.set("__KEY", q4key.value || "");
372
  const rep = JSON.parse(pyodide.runPython(HARNESS));
373
- if (rep.error){ q4append(rep.error+"\n","err"); lastQ4={original_output:"",mutant_output:""}; return; }
374
- q4append("Q3 suite on your mutant (must all pass / match):\n","meta");
375
  for (const r of rep.rows){
376
  const tag = r.same ? " PASS " : " FAIL ";
377
  q4append(tag, r.same?"ok":"err");
378
- q4append(`target=${r.target}, key=${r.key} original=${r.orig} mutant=${r.mut}\n`, "meta");
379
  }
380
- if (rep.allpass) q4append("(a) βœ“ Mutant is invisible to the Q3 suite β€” all three match.\n","ok");
381
- else q4append("(a) βœ— Mutant changes a Q3 result β€” the Q3 suite would catch it. Pick a bug on an unexercised path.\n","warn");
382
  q4append("\n");
383
- if (!rep.dist){ q4append("(b) Fill target + key above to test your distinguishing case.\n","meta"); lastQ4={original_output:"",mutant_output:""}; }
384
- else if (rep.dist.error){ q4append("(b) "+rep.dist.error+"\n","err"); lastQ4={original_output:"",mutant_output:""}; }
385
  else {
386
- lastQ4 = { original_output: rep.dist.orig, mutant_output: rep.dist.mut };
387
  q4append(`(b) Distinguishing test target=${rep.dist.target}, key=${rep.dist.key}\n`,"meta");
388
- q4append(` original = ${rep.dist.orig}\n mutant = ${rep.dist.mut}\n`,"meta");
389
- if (rep.dist.differs) q4append(" βœ“ This test distinguishes the mutant from the original.\n","ok");
390
  else q4append(" βœ— Same output on both β€” this test does NOT distinguish them yet.\n","warn");
391
  }
392
  } catch(e){ q4append("Runtime error: "+e+"\n","err"); }
@@ -412,11 +412,11 @@ function buildJSON(){
412
  q2: answers.q2 || "",
413
  q3: q3,
414
  q4: {
415
- mutation: document.getElementById("q4mutation").value.trim(),
416
- mutant_code: editor.getValue(),
417
  test: { target: q4target.value.trim(), key: q4key.value.trim() },
418
  original_output: lastQ4.original_output,
419
- mutant_output: lastQ4.mutant_output
420
  },
421
  q5: answers.q5 || ""
422
  }
@@ -450,10 +450,10 @@ function saveSession(){
450
  q1: answers.q1, q2: answers.q2, q5: answers.q5,
451
  q3: answers.q3,
452
  q4: {
453
- mutation: document.getElementById("q4mutation").value,
454
  code: editor.getValue(),
455
  target: q4target.value, key: q4key.value,
456
- original_output: lastQ4.original_output, mutant_output: lastQ4.mutant_output
457
  }
458
  };
459
  localStorage.setItem(SESSION_KEY, JSON.stringify(d));
@@ -474,10 +474,10 @@ function loadSession(){
474
  if (d.q3){ answers.q3 = Object.assign({}, d.q3);
475
  document.querySelectorAll("input.blank").forEach(inp => { const v = d.q3[inp.dataset.n]; if (v != null) inp.value = v; }); }
476
  if (d.q4){
477
- document.getElementById("q4mutation").value = d.q4.mutation || "";
478
  if (d.q4.code) editor.setValue(d.q4.code);
479
  q4target.value = d.q4.target || ""; q4key.value = d.q4.key || "";
480
- lastQ4 = { original_output: d.q4.original_output || "", mutant_output: d.q4.mutant_output || "" };
481
  }
482
  // banner
483
  let ago = "earlier";
@@ -495,7 +495,7 @@ function loadSession(){
495
  }
496
  function clearSession(){ localStorage.removeItem(SESSION_KEY); location.reload(); }
497
  // save on the free-text fields too
498
- ["studentId","q4mutation"].forEach(id => document.getElementById(id).addEventListener("input", saveSession));
499
  [q4target, q4key].forEach(el => el.addEventListener("input", saveSession));
500
  document.getElementById("clearBtn").onclick = clearSession;
501
  // restore once everything above is defined
 
133
  <!-- ============ Q4 ============ -->
134
  <h2>Q4 &nbsp;Fault-Based Testing: Plant a Bug and Catch It <span class="pts">[3 pts] Β· playground</span></h2>
135
  <p>(a) Introduce <b>exactly one</b> single-line bug into <code>binary_search</code> so that <b>all three Q3 tests still pass</b> (the bug is invisible to the Q3 suite).
136
+ (b) Give <b>one</b> extra test case that <b>distinguishes</b> the variant from the original (original passes, variant fails).</p>
137
+ <p class="muted">Use the playground: edit the function to your variant, enter your distinguishing test, and press <b>Run check</b>. It reports whether your variant still passes the Q3 suite and whether your test separates the two.</p>
138
 
139
+ <p style="margin-top:14px"><b>(a) Describe your one-line change</b> (form <code>from &rarr; to</code>):</p>
140
+ <input class="txt" id="q4change" style="width:100%" placeholder="e.g. top = mid - 1 -> top = mid - 2">
141
 
142
  <div class="pg">
143
  <div class="pg-head">
 
302
  const q4out = document.getElementById("q4out");
303
  const q4target = document.getElementById("q4target");
304
  const q4key = document.getElementById("q4key");
305
+ let lastQ4 = { original_output:"", variant_output:"" };
306
 
307
  const editor = CodeMirror.fromTextArea(document.getElementById("q4code"), {
308
  mode:"python", theme:"material-darker", lineNumbers:true, indentUnit:4, tabSize:4,
 
370
  pyodide.globals.set("__TGT", q4target.value || "");
371
  pyodide.globals.set("__KEY", q4key.value || "");
372
  const rep = JSON.parse(pyodide.runPython(HARNESS));
373
+ if (rep.error){ q4append(rep.error+"\n","err"); lastQ4={original_output:"",variant_output:""}; return; }
374
+ q4append("Q3 suite on your variant (must all pass / match):\n","meta");
375
  for (const r of rep.rows){
376
  const tag = r.same ? " PASS " : " FAIL ";
377
  q4append(tag, r.same?"ok":"err");
378
+ q4append(`target=${r.target}, key=${r.key} original=${r.orig} variant=${r.mut}\n`, "meta");
379
  }
380
+ if (rep.allpass) q4append("(a) βœ“ Variant is invisible to the Q3 suite β€” all three match.\n","ok");
381
+ else q4append("(a) βœ— Variant changes a Q3 result β€” the Q3 suite would catch it. Pick a bug on an unexercised path.\n","warn");
382
  q4append("\n");
383
+ if (!rep.dist){ q4append("(b) Fill target + key above to test your distinguishing case.\n","meta"); lastQ4={original_output:"",variant_output:""}; }
384
+ else if (rep.dist.error){ q4append("(b) "+rep.dist.error+"\n","err"); lastQ4={original_output:"",variant_output:""}; }
385
  else {
386
+ lastQ4 = { original_output: rep.dist.orig, variant_output: rep.dist.mut };
387
  q4append(`(b) Distinguishing test target=${rep.dist.target}, key=${rep.dist.key}\n`,"meta");
388
+ q4append(` original = ${rep.dist.orig}\n variant = ${rep.dist.mut}\n`,"meta");
389
+ if (rep.dist.differs) q4append(" βœ“ This test distinguishes the variant from the original.\n","ok");
390
  else q4append(" βœ— Same output on both β€” this test does NOT distinguish them yet.\n","warn");
391
  }
392
  } catch(e){ q4append("Runtime error: "+e+"\n","err"); }
 
412
  q2: answers.q2 || "",
413
  q3: q3,
414
  q4: {
415
+ change: document.getElementById("q4change").value.trim(),
416
+ variant_code: editor.getValue(),
417
  test: { target: q4target.value.trim(), key: q4key.value.trim() },
418
  original_output: lastQ4.original_output,
419
+ variant_output: lastQ4.variant_output
420
  },
421
  q5: answers.q5 || ""
422
  }
 
450
  q1: answers.q1, q2: answers.q2, q5: answers.q5,
451
  q3: answers.q3,
452
  q4: {
453
+ change: document.getElementById("q4change").value,
454
  code: editor.getValue(),
455
  target: q4target.value, key: q4key.value,
456
+ original_output: lastQ4.original_output, variant_output: lastQ4.variant_output
457
  }
458
  };
459
  localStorage.setItem(SESSION_KEY, JSON.stringify(d));
 
474
  if (d.q3){ answers.q3 = Object.assign({}, d.q3);
475
  document.querySelectorAll("input.blank").forEach(inp => { const v = d.q3[inp.dataset.n]; if (v != null) inp.value = v; }); }
476
  if (d.q4){
477
+ document.getElementById("q4change").value = d.q4.change || "";
478
  if (d.q4.code) editor.setValue(d.q4.code);
479
  q4target.value = d.q4.target || ""; q4key.value = d.q4.key || "";
480
+ lastQ4 = { original_output: d.q4.original_output || "", variant_output: d.q4.variant_output || "" };
481
  }
482
  // banner
483
  let ago = "earlier";
 
495
  }
496
  function clearSession(){ localStorage.removeItem(SESSION_KEY); location.reload(); }
497
  // save on the free-text fields too
498
+ ["studentId","q4change"].forEach(id => document.getElementById(id).addEventListener("input", saveSession));
499
  [q4target, q4key].forEach(el => el.addEventListener("input", saveSession));
500
  document.getElementById("clearBtn").onclick = clearSession;
501
  // restore once everything above is defined