Spaces:
Running
Running
Upload assignment2.html with huggingface_hub
Browse files- assignment2.html +44 -15
assignment2.html
CHANGED
|
@@ -50,6 +50,7 @@
|
|
| 50 |
.opt-head input { width:16px; height:16px; accent-color:var(--accent); cursor:pointer; }
|
| 51 |
.opt-body { margin-top:8px; overflow:auto; }
|
| 52 |
.opt-body img { max-width:100%; background:#fff; border-radius:6px; }
|
|
|
|
| 53 |
|
| 54 |
/* fill-in blanks */
|
| 55 |
input.blank {
|
|
@@ -105,14 +106,24 @@
|
|
| 105 |
|
| 106 |
<!-- ============ Q1 ============ -->
|
| 107 |
<h2>Q1 Extended Entry Decision Table <span class="pts">[6 pts] · single choice</span></h2>
|
| 108 |
-
<p>Test the UNSW Lecture-Theatre Booking system with Decision-Table testing. The system
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
<table class="spec">
|
| 110 |
-
<tr><th>
|
| 111 |
-
<tr><td>
|
| 112 |
-
<tr><td>
|
| 113 |
-
<tr><td>
|
| 114 |
-
<tr><td>equipment</td><td>1=Standard, 2=AV, 3=ComputerLab, 4=Hybrid</td></tr>
|
| 115 |
-
<tr><td>staff_role</td><td>1=Academic, 2=Admin, 3=Guest</td></tr>
|
| 116 |
</table>
|
| 117 |
|
| 118 |
<h3>Program description</h3>
|
|
@@ -122,10 +133,10 @@
|
|
| 122 |
<li><b>B. Exam-week nest.</b> In exam weeks 11–12, only academic staff may book; everyone else is rejected. Even academics cannot request a Large theatre — those halls are blocked out for exams.</li>
|
| 123 |
<li><b>C. Large-room.</b> Any request for a Large lecture theatre must clear three hurdles, otherwise rejected: (1) Evening slot (large rooms close after 17:00); (2) Computer-Lab equipment (there are no large computer labs); (3) Guest requester (guests may not reserve large rooms).</li>
|
| 124 |
<li><b>D. Equipment-specific.</b> A Small room plus Hybrid kit is rejected.</li>
|
| 125 |
-
<li><b>E. Guest + ComputerLab.</b>
|
| 126 |
<li><b>F. Admin + Small.</b> An admin requesting a Small room is wait-listed if either the slot is in the evening, or it is exam week.</li>
|
| 127 |
<li><b>G. First-matching-theatre book.</b> If none of the above rules block the request, the system books the first room that matches the requested size, contains the requested equipment, and (for evening bookings) allows evening use.</li>
|
| 128 |
-
<li><b>H. Fallback.</b> If no room can be booked after all checks, the request is put on a general wait-list. <span class="muted">(Rule H is outside the scope of this decision table.)</span></li>
|
| 129 |
</ol>
|
| 130 |
<p class="muted">Assume that whenever a valid request is not blocked by Rules A–F, at least one matching theatre is always available.</p>
|
| 131 |
|
|
@@ -138,7 +149,7 @@
|
|
| 138 |
|
| 139 |
<!-- ============ Q2 ============ -->
|
| 140 |
<h2>Q2 Control-Flow Graph <span class="pts">[3 pts] · single choice</span></h2>
|
| 141 |
-
<p>
|
| 142 |
<div id="q2opts"></div>
|
| 143 |
|
| 144 |
<!-- ============ Q3 ============ -->
|
|
@@ -149,8 +160,9 @@
|
|
| 149 |
|
| 150 |
<!-- ============ Q4 ============ -->
|
| 151 |
<h2>Q4 Fault-Based Testing: Plant a Bug and Catch It <span class="pts">[3 pts] · playground</span></h2>
|
|
|
|
| 152 |
<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).
|
| 153 |
-
(b)
|
| 154 |
<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>
|
| 155 |
|
| 156 |
<p style="margin-top:14px"><b>(a) Describe your one-line change</b> (form <code>from → to</code>):</p>
|
|
@@ -170,6 +182,13 @@
|
|
| 170 |
<div><label>key</label>
|
| 171 |
<input class="txt" id="q4key" placeholder="3" style="width:90px"></div>
|
| 172 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
<pre id="q4out"><span class="meta">(edit the function, fill the test, then Run check)</span></pre>
|
| 174 |
</div>
|
| 175 |
|
|
@@ -251,9 +270,15 @@ buildChoice(document.getElementById("q1opts"), "q1",
|
|
| 251 |
[1,2,3,4,5,6].map(n=>({val:String(n), label:"Option "+n, body:dtTable(Q1[n])})),
|
| 252 |
v => { answers.q1 = v; saveSession(); });
|
| 253 |
|
| 254 |
-
// ============ Q2: four CFG images ============
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
buildChoice(document.getElementById("q2opts"), "q2",
|
| 256 |
-
[1,2,3,4].map(n=>({val:String(n), label:"Option "+n, body:
|
| 257 |
v => { answers.q2 = v; saveSession(); });
|
| 258 |
|
| 259 |
// ============ Q3: fill-in trace with 12 blanks ============
|
|
@@ -432,8 +457,8 @@ function buildJSON(){
|
|
| 432 |
change: document.getElementById("q4change").value.trim(),
|
| 433 |
variant_code: editor.getValue(),
|
| 434 |
test: { target: q4target.value.trim(), key: q4key.value.trim() },
|
| 435 |
-
original_output: lastQ4.original_output,
|
| 436 |
-
variant_output: lastQ4.variant_output
|
| 437 |
},
|
| 438 |
q5: answers.q5 || ""
|
| 439 |
}
|
|
@@ -470,6 +495,8 @@ function saveSession(){
|
|
| 470 |
change: document.getElementById("q4change").value,
|
| 471 |
code: editor.getValue(),
|
| 472 |
target: q4target.value, key: q4key.value,
|
|
|
|
|
|
|
| 473 |
original_output: lastQ4.original_output, variant_output: lastQ4.variant_output
|
| 474 |
}
|
| 475 |
};
|
|
@@ -494,6 +521,8 @@ function loadSession(){
|
|
| 494 |
document.getElementById("q4change").value = d.q4.change || "";
|
| 495 |
if (d.q4.code) editor.setValue(d.q4.code);
|
| 496 |
q4target.value = d.q4.target || ""; q4key.value = d.q4.key || "";
|
|
|
|
|
|
|
| 497 |
lastQ4 = { original_output: d.q4.original_output || "", variant_output: d.q4.variant_output || "" };
|
| 498 |
}
|
| 499 |
// banner
|
|
|
|
| 50 |
.opt-head input { width:16px; height:16px; accent-color:var(--accent); cursor:pointer; }
|
| 51 |
.opt-body { margin-top:8px; overflow:auto; }
|
| 52 |
.opt-body img { max-width:100%; background:#fff; border-radius:6px; }
|
| 53 |
+
.opt-body svg { display:block; width:100%; height:auto; background:#fff; border-radius:6px; }
|
| 54 |
|
| 55 |
/* fill-in blanks */
|
| 56 |
input.blank {
|
|
|
|
| 106 |
|
| 107 |
<!-- ============ Q1 ============ -->
|
| 108 |
<h2>Q1 Extended Entry Decision Table <span class="pts">[6 pts] · single choice</span></h2>
|
| 109 |
+
<p>Test the UNSW Lecture-Theatre Booking system with Decision-Table testing. The system evaluates multi-valued conditions across several inputs to decide whether a booking is Booked, Wait-listed, or Rejected. Rules are checked one by one and the <b>first matching rule</b> applies.</p>
|
| 110 |
+
|
| 111 |
+
<h3>Input specification</h3>
|
| 112 |
+
<table class="spec">
|
| 113 |
+
<tr><th>Input</th><th>Domain values</th><th>In your submission</th></tr>
|
| 114 |
+
<tr><td>room_size</td><td>Small, Medium, Large</td><td>1=Small, 2=Medium, 3=Large</td></tr>
|
| 115 |
+
<tr><td>time_slot</td><td>Morning, Afternoon, Evening</td><td>1=Morning, 2=Afternoon, 3=Evening</td></tr>
|
| 116 |
+
<tr><td>week</td><td>1 to 12</td><td>Numeric as is</td></tr>
|
| 117 |
+
<tr><td>equipment</td><td>Standard, AV, ComputerLab, Hybrid</td><td>1=Standard, 2=AV, 3=ComputerLab, 4=Hybrid</td></tr>
|
| 118 |
+
<tr><td>staff_role</td><td>Academic, Admin, Guest</td><td>1=Academic, 2=Admin, 3=Guest</td></tr>
|
| 119 |
+
</table>
|
| 120 |
+
|
| 121 |
+
<h3>Output codes</h3>
|
| 122 |
<table class="spec">
|
| 123 |
+
<tr><th>Code</th><th>Status</th><th>Typical reason</th></tr>
|
| 124 |
+
<tr><td>0</td><td>Booked</td><td>Request satisfies all constraints; first available room assigned</td></tr>
|
| 125 |
+
<tr><td>1</td><td>Wait-list</td><td>Request valid but cannot be immediately fulfilled</td></tr>
|
| 126 |
+
<tr><td>2</td><td>Rejected</td><td>Request violates system rules or contains invalid input</td></tr>
|
|
|
|
|
|
|
| 127 |
</table>
|
| 128 |
|
| 129 |
<h3>Program description</h3>
|
|
|
|
| 133 |
<li><b>B. Exam-week nest.</b> In exam weeks 11–12, only academic staff may book; everyone else is rejected. Even academics cannot request a Large theatre — those halls are blocked out for exams.</li>
|
| 134 |
<li><b>C. Large-room.</b> Any request for a Large lecture theatre must clear three hurdles, otherwise rejected: (1) Evening slot (large rooms close after 17:00); (2) Computer-Lab equipment (there are no large computer labs); (3) Guest requester (guests may not reserve large rooms).</li>
|
| 135 |
<li><b>D. Equipment-specific.</b> A Small room plus Hybrid kit is rejected.</li>
|
| 136 |
+
<li><b>E. Guest + ComputerLab.</b> A guest wanting a computer lab is never accepted outright during teaching weeks 1–10: early weeks 1–4 wait-list, mid-semester 5–8 wait-list, late weeks 9–10 wait-list.</li>
|
| 137 |
<li><b>F. Admin + Small.</b> An admin requesting a Small room is wait-listed if either the slot is in the evening, or it is exam week.</li>
|
| 138 |
<li><b>G. First-matching-theatre book.</b> If none of the above rules block the request, the system books the first room that matches the requested size, contains the requested equipment, and (for evening bookings) allows evening use.</li>
|
| 139 |
+
<li><b>H. Fallback.</b> If no room can be booked after all checks, the request is put on a general wait-list with the reason “No matching theatre currently available”. <span class="muted">(Rule H is outside the scope of this decision table.)</span></li>
|
| 140 |
</ol>
|
| 141 |
<p class="muted">Assume that whenever a valid request is not blocked by Rules A–F, at least one matching theatre is always available.</p>
|
| 142 |
|
|
|
|
| 149 |
|
| 150 |
<!-- ============ Q2 ============ -->
|
| 151 |
<h2>Q2 Control-Flow Graph <span class="pts">[3 pts] · single choice</span></h2>
|
| 152 |
+
<p>Draw the control-flow graph for <code>binary_search</code>. Below are four candidate CFGs, written as complete DOT graphs and rendered. Exactly one is correct — select it.</p>
|
| 153 |
<div id="q2opts"></div>
|
| 154 |
|
| 155 |
<!-- ============ Q3 ============ -->
|
|
|
|
| 160 |
|
| 161 |
<!-- ============ Q4 ============ -->
|
| 162 |
<h2>Q4 Fault-Based Testing: Plant a Bug and Catch It <span class="pts">[3 pts] · playground</span></h2>
|
| 163 |
+
<p class="muted">The Q3 suite reaches loop-boundary coverage, but coverage does not guarantee fault detection. This question asks you to demonstrate that gap on the <code>binary_search</code> function above.</p>
|
| 164 |
<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).
|
| 165 |
+
(b) Provide <b>one</b> extra test case — with <code>target</code>, <code>key</code>, the <b>original output</b>, and the <b>variant output</b> — that <b>distinguishes</b> the variant from the original (original passes it, variant fails).</p>
|
| 166 |
<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>
|
| 167 |
|
| 168 |
<p style="margin-top:14px"><b>(a) Describe your one-line change</b> (form <code>from → to</code>):</p>
|
|
|
|
| 182 |
<div><label>key</label>
|
| 183 |
<input class="txt" id="q4key" placeholder="3" style="width:90px"></div>
|
| 184 |
</div>
|
| 185 |
+
<div class="pg-row">
|
| 186 |
+
<div><label>original output</label>
|
| 187 |
+
<input class="txt" id="q4origout" placeholder="(found=True, location=1)" style="width:220px"></div>
|
| 188 |
+
<div><label>variant output</label>
|
| 189 |
+
<input class="txt" id="q4varout" placeholder="(found=False, location=0)" style="width:220px"></div>
|
| 190 |
+
<div style="font-size:11px;color:var(--muted);max-width:230px">Fill these in yourself. Run check also prints the actual outputs so you can confirm.</div>
|
| 191 |
+
</div>
|
| 192 |
<pre id="q4out"><span class="meta">(edit the function, fill the test, then Run check)</span></pre>
|
| 193 |
</div>
|
| 194 |
|
|
|
|
| 270 |
[1,2,3,4,5,6].map(n=>({val:String(n), label:"Option "+n, body:dtTable(Q1[n])})),
|
| 271 |
v => { answers.q1 = v; saveSession(); });
|
| 272 |
|
| 273 |
+
// ============ Q2: four CFG images (inline SVG — no extra request, no decode) ============
|
| 274 |
+
const Q2_SVG = [
|
| 275 |
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 680 700" font-family="Helvetica,Arial,sans-serif"><rect width="680" height="700" fill="#fff"/><defs><marker id="arr" markerWidth="9" markerHeight="9" refX="7.5" refY="3" orient="auto" markerUnits="userSpaceOnUse"><path d="M0,0 L8,3 L0,6 Z" fill="#222"/></marker></defs><path d="M340.0,76.0 L340.0,94.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M316.7,138.7 L274.0,172.8" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="291.5" y="145.0" width="13" height="14" fill="#fff" opacity="0.9"/><text x="297.5" y="157.0" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M365.1,138.1 L413.6,173.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="381.0" y="144.8" width="13" height="14" fill="#fff" opacity="0.9"/><text x="387.0" y="156.8" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M272.1,211.6 L316.8,251.4" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M415.7,211.5 L365.2,251.8" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M340.0,298.0 L340.0,326.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="334.0" y="301.6" width="13" height="14" fill="#fff" opacity="0.9"/><text x="340.0" y="313.6" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M340.0,370.0 L340.0,398.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M304.1,439.6 L209.7,480.6" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="255.7" y="449.0" width="13" height="14" fill="#fff" opacity="0.9"/><text x="261.7" y="461.0" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M353.9,446.0 L374.2,478.2" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="357.0" y="451.5" width="13" height="14" fill="#fff" opacity="0.9"/><text x="363.0" y="463.5" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M372.0,521.2 L335.7,569.2" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="349.7" y="533.8" width="13" height="14" fill="#fff" opacity="0.9"/><text x="355.7" y="545.8" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M406.6,520.4 L451.6,569.9" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="420.9" y="533.6" width="13" height="14" fill="#fff" opacity="0.9"/><text x="426.9" y="545.6" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M371.6,290.7 Q668.0,466.0 337.8,640.1" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="505.3" y="456.7" width="13" height="14" fill="#fff" opacity="0.9"/><text x="511.3" y="468.7" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M183.2,521.6 L281.8,638.5" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M313.8,611.8 L306.3,638.1" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M435.3,604.3 L345.8,641.2" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><ellipse cx="340" cy="42" rx="99.5" ry="34" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="38" text-anchor="middle" font-size="13">size; bott=0; top=size-1;</text><text x="340" y="54" text-anchor="middle" font-size="13">location=0; found=False</text><polygon points="340,94 422.8,120 340,146 257.2,120" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="124" text-anchor="middle" font-size="13">target[0]==key ?</text><ellipse cx="250" cy="192" rx="49.0" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="250" y="196" text-anchor="middle" font-size="13">found=True</text><ellipse cx="440" cy="192" rx="52.3" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="440" y="196" text-anchor="middle" font-size="13">found=False</text><polygon points="340,246 452.5,272 340,298 227.5,272" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="276" text-anchor="middle" font-size="13">bott<=top and not found ?</text><ellipse cx="340" cy="348" rx="115.0" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="352" text-anchor="middle" font-size="13">mid=int(round((top+bott)/2.0))</text><polygon points="340,398 429.4,424 340,450 250.6,424" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="428" text-anchor="middle" font-size="13">target[mid]==key ?</text><ellipse cx="165" cy="500" rx="95.19999999999999" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="165" y="504" text-anchor="middle" font-size="13">found=True; location=mid</text><polygon points="388,474 474.1,500 388,526 301.9,500" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="388" y="504" text-anchor="middle" font-size="13">target[mid]<key ?</text><ellipse cx="320" cy="590" rx="49.0" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="320" y="594" text-anchor="middle" font-size="13">bott=mid+1</text><ellipse cx="470" cy="590" rx="45.7" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="470" y="594" text-anchor="middle" font-size="13">top=mid-1</text><ellipse cx="300" cy="660" rx="88.6" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="300" y="664" text-anchor="middle" font-size="13">return found, location</text></svg>`,
|
| 276 |
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 680 700" font-family="Helvetica,Arial,sans-serif"><rect width="680" height="700" fill="#fff"/><defs><marker id="arr" markerWidth="9" markerHeight="9" refX="7.5" refY="3" orient="auto" markerUnits="userSpaceOnUse"><path d="M0,0 L8,3 L0,6 Z" fill="#222"/></marker></defs><path d="M340.0,76.0 L340.0,94.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M316.7,138.7 L274.0,172.8" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="291.5" y="145.0" width="13" height="14" fill="#fff" opacity="0.9"/><text x="297.5" y="157.0" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M365.1,138.1 L413.6,173.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="381.0" y="144.8" width="13" height="14" fill="#fff" opacity="0.9"/><text x="387.0" y="156.8" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M272.1,211.6 L316.8,251.4" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M415.7,211.5 L365.2,251.8" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M340.0,298.0 L340.0,326.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="334.0" y="301.6" width="13" height="14" fill="#fff" opacity="0.9"/><text x="340.0" y="313.6" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M340.0,370.0 L340.0,398.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M304.1,439.6 L209.7,480.6" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="255.7" y="449.0" width="13" height="14" fill="#fff" opacity="0.9"/><text x="261.7" y="461.0" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M353.9,446.0 L374.2,478.2" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="357.0" y="451.5" width="13" height="14" fill="#fff" opacity="0.9"/><text x="363.0" y="463.5" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M372.0,521.2 L335.7,569.2" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="349.7" y="533.8" width="13" height="14" fill="#fff" opacity="0.9"/><text x="355.7" y="545.8" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M406.6,520.4 L451.6,569.9" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="420.9" y="533.6" width="13" height="14" fill="#fff" opacity="0.9"/><text x="426.9" y="545.6" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M371.6,290.7 Q668.0,466.0 337.8,640.1" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="505.3" y="456.7" width="13" height="14" fill="#fff" opacity="0.9"/><text x="511.3" y="468.7" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M147.5,478.4 Q52.0,360.0 291.6,286.8" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M350.5,572.8 Q600.0,432.0 370.7,290.9" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M485.7,569.3 Q636.0,372.0 385.7,287.4" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><ellipse cx="340" cy="42" rx="99.5" ry="34" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="38" text-anchor="middle" font-size="13">size; bott=0; top=size-1;</text><text x="340" y="54" text-anchor="middle" font-size="13">location=0; found=False</text><polygon points="340,94 422.8,120 340,146 257.2,120" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="124" text-anchor="middle" font-size="13">target[0]==key ?</text><ellipse cx="250" cy="192" rx="49.0" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="250" y="196" text-anchor="middle" font-size="13">found=True</text><ellipse cx="440" cy="192" rx="52.3" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="440" y="196" text-anchor="middle" font-size="13">found=False</text><polygon points="340,246 452.5,272 340,298 227.5,272" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="276" text-anchor="middle" font-size="13">bott<=top and not found ?</text><ellipse cx="340" cy="348" rx="115.0" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="352" text-anchor="middle" font-size="13">mid=int(round((top+bott)/2.0))</text><polygon points="340,398 429.4,424 340,450 250.6,424" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="428" text-anchor="middle" font-size="13">target[mid]==key ?</text><ellipse cx="165" cy="500" rx="95.19999999999999" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="165" y="504" text-anchor="middle" font-size="13">found=True; location=mid</text><polygon points="388,474 474.1,500 388,526 301.9,500" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="388" y="504" text-anchor="middle" font-size="13">target[mid]<key ?</text><ellipse cx="320" cy="590" rx="49.0" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="320" y="594" text-anchor="middle" font-size="13">bott=mid+1</text><ellipse cx="470" cy="590" rx="45.7" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="470" y="594" text-anchor="middle" font-size="13">top=mid-1</text><ellipse cx="300" cy="660" rx="88.6" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="300" y="664" text-anchor="middle" font-size="13">return found, location</text></svg>`,
|
| 277 |
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 680 700" font-family="Helvetica,Arial,sans-serif"><rect width="680" height="700" fill="#fff"/><defs><marker id="arr" markerWidth="9" markerHeight="9" refX="7.5" refY="3" orient="auto" markerUnits="userSpaceOnUse"><path d="M0,0 L8,3 L0,6 Z" fill="#222"/></marker></defs><path d="M340.0,76.0 L340.0,94.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M316.7,138.7 L274.0,172.8" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="291.5" y="145.0" width="13" height="14" fill="#fff" opacity="0.9"/><text x="297.5" y="157.0" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M365.1,138.1 L413.6,173.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="381.0" y="144.8" width="13" height="14" fill="#fff" opacity="0.9"/><text x="387.0" y="156.8" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M272.1,211.6 L316.8,251.4" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M415.7,211.5 L365.2,251.8" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M340.0,298.0 L340.0,326.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="334.0" y="301.6" width="13" height="14" fill="#fff" opacity="0.9"/><text x="340.0" y="313.6" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M340.0,370.0 L340.0,398.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M304.1,439.6 L209.7,480.6" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="255.7" y="449.0" width="13" height="14" fill="#fff" opacity="0.9"/><text x="261.7" y="461.0" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M353.9,446.0 L374.2,478.2" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="357.0" y="451.5" width="13" height="14" fill="#fff" opacity="0.9"/><text x="363.0" y="463.5" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M372.0,521.2 L335.7,569.2" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="349.7" y="533.8" width="13" height="14" fill="#fff" opacity="0.9"/><text x="355.7" y="545.8" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M406.6,520.4 L451.6,569.9" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="420.9" y="533.6" width="13" height="14" fill="#fff" opacity="0.9"/><text x="426.9" y="545.6" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M371.6,290.7 Q668.0,466.0 337.8,640.1" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="505.3" y="456.7" width="13" height="14" fill="#fff" opacity="0.9"/><text x="511.3" y="468.7" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M260.2,500.0 L301.9,500.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M350.5,572.8 Q600.0,432.0 370.7,290.9" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M485.7,569.3 Q636.0,372.0 385.7,287.4" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><ellipse cx="340" cy="42" rx="99.5" ry="34" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="38" text-anchor="middle" font-size="13">size; bott=0; top=size-1;</text><text x="340" y="54" text-anchor="middle" font-size="13">location=0; found=False</text><polygon points="340,94 422.8,120 340,146 257.2,120" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="124" text-anchor="middle" font-size="13">target[0]==key ?</text><ellipse cx="250" cy="192" rx="49.0" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="250" y="196" text-anchor="middle" font-size="13">found=True</text><ellipse cx="440" cy="192" rx="52.3" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="440" y="196" text-anchor="middle" font-size="13">found=False</text><polygon points="340,246 452.5,272 340,298 227.5,272" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="276" text-anchor="middle" font-size="13">bott<=top and not found ?</text><ellipse cx="340" cy="348" rx="115.0" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="352" text-anchor="middle" font-size="13">mid=int(round((top+bott)/2.0))</text><polygon points="340,398 429.4,424 340,450 250.6,424" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="428" text-anchor="middle" font-size="13">target[mid]==key ?</text><ellipse cx="165" cy="500" rx="95.19999999999999" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="165" y="504" text-anchor="middle" font-size="13">found=True; location=mid</text><polygon points="388,474 474.1,500 388,526 301.9,500" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="388" y="504" text-anchor="middle" font-size="13">target[mid]<key ?</text><ellipse cx="320" cy="590" rx="49.0" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="320" y="594" text-anchor="middle" font-size="13">bott=mid+1</text><ellipse cx="470" cy="590" rx="45.7" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="470" y="594" text-anchor="middle" font-size="13">top=mid-1</text><ellipse cx="300" cy="660" rx="88.6" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="300" y="664" text-anchor="middle" font-size="13">return found, location</text></svg>`,
|
| 278 |
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 680 700" font-family="Helvetica,Arial,sans-serif"><rect width="680" height="700" fill="#fff"/><defs><marker id="arr" markerWidth="9" markerHeight="9" refX="7.5" refY="3" orient="auto" markerUnits="userSpaceOnUse"><path d="M0,0 L8,3 L0,6 Z" fill="#222"/></marker></defs><path d="M340.0,76.0 L340.0,94.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M316.7,138.7 L274.0,172.8" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="291.5" y="145.0" width="13" height="14" fill="#fff" opacity="0.9"/><text x="297.5" y="157.0" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M365.1,138.1 L413.6,173.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="381.0" y="144.8" width="13" height="14" fill="#fff" opacity="0.9"/><text x="387.0" y="156.8" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M272.1,211.6 L316.8,251.4" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M415.7,211.5 L365.2,251.8" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M340.0,298.0 L340.0,326.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="334.0" y="301.6" width="13" height="14" fill="#fff" opacity="0.9"/><text x="340.0" y="313.6" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M340.0,370.0 L340.0,398.0" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M304.1,439.6 L209.7,480.6" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="255.7" y="449.0" width="13" height="14" fill="#fff" opacity="0.9"/><text x="261.7" y="461.0" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M353.9,446.0 L374.2,478.2" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="357.0" y="451.5" width="13" height="14" fill="#fff" opacity="0.9"/><text x="363.0" y="463.5" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M372.0,521.2 L335.7,569.2" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="349.7" y="533.8" width="13" height="14" fill="#fff" opacity="0.9"/><text x="355.7" y="545.8" text-anchor="middle" font-size="12" font-style="italic" fill="#333">T</text><path d="M406.6,520.4 L451.6,569.9" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="420.9" y="533.6" width="13" height="14" fill="#fff" opacity="0.9"/><text x="426.9" y="545.6" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M371.6,290.7 Q668.0,466.0 337.8,640.1" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><rect x="505.3" y="456.7" width="13" height="14" fill="#fff" opacity="0.9"/><text x="511.3" y="468.7" text-anchor="middle" font-size="12" font-style="italic" fill="#333">F</text><path d="M183.2,521.6 L281.8,638.5" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M350.5,572.8 Q600.0,432.0 370.7,290.9" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><path d="M485.7,569.3 Q636.0,372.0 385.7,287.4" fill="none" stroke="#222" stroke-width="1.2" marker-end="url(#arr)"/><ellipse cx="340" cy="42" rx="99.5" ry="34" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="38" text-anchor="middle" font-size="13">size; bott=0; top=size-1;</text><text x="340" y="54" text-anchor="middle" font-size="13">location=0; found=False</text><polygon points="340,94 422.8,120 340,146 257.2,120" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="124" text-anchor="middle" font-size="13">target[0]==key ?</text><ellipse cx="250" cy="192" rx="49.0" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="250" y="196" text-anchor="middle" font-size="13">found=True</text><ellipse cx="440" cy="192" rx="52.3" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="440" y="196" text-anchor="middle" font-size="13">found=False</text><polygon points="340,246 452.5,272 340,298 227.5,272" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="276" text-anchor="middle" font-size="13">bott<=top and not found ?</text><ellipse cx="340" cy="348" rx="115.0" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="352" text-anchor="middle" font-size="13">mid=int(round((top+bott)/2.0))</text><polygon points="340,398 429.4,424 340,450 250.6,424" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="340" y="428" text-anchor="middle" font-size="13">target[mid]==key ?</text><ellipse cx="165" cy="500" rx="95.19999999999999" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="165" y="504" text-anchor="middle" font-size="13">found=True; location=mid</text><polygon points="388,474 474.1,500 388,526 301.9,500" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="388" y="504" text-anchor="middle" font-size="13">target[mid]<key ?</text><ellipse cx="320" cy="590" rx="49.0" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="320" y="594" text-anchor="middle" font-size="13">bott=mid+1</text><ellipse cx="470" cy="590" rx="45.7" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="470" y="594" text-anchor="middle" font-size="13">top=mid-1</text><ellipse cx="300" cy="660" rx="88.6" ry="22" fill="#fff" stroke="#222" stroke-width="1.3"/><text x="300" y="664" text-anchor="middle" font-size="13">return found, location</text></svg>`
|
| 279 |
+
];
|
| 280 |
buildChoice(document.getElementById("q2opts"), "q2",
|
| 281 |
+
[1,2,3,4].map(n=>({val:String(n), label:"Option "+n, body:Q2_SVG[n-1]})),
|
| 282 |
v => { answers.q2 = v; saveSession(); });
|
| 283 |
|
| 284 |
// ============ Q3: fill-in trace with 12 blanks ============
|
|
|
|
| 457 |
change: document.getElementById("q4change").value.trim(),
|
| 458 |
variant_code: editor.getValue(),
|
| 459 |
test: { target: q4target.value.trim(), key: q4key.value.trim() },
|
| 460 |
+
original_output: document.getElementById("q4origout").value.trim() || lastQ4.original_output,
|
| 461 |
+
variant_output: document.getElementById("q4varout").value.trim() || lastQ4.variant_output
|
| 462 |
},
|
| 463 |
q5: answers.q5 || ""
|
| 464 |
}
|
|
|
|
| 495 |
change: document.getElementById("q4change").value,
|
| 496 |
code: editor.getValue(),
|
| 497 |
target: q4target.value, key: q4key.value,
|
| 498 |
+
origout: document.getElementById("q4origout").value,
|
| 499 |
+
varout: document.getElementById("q4varout").value,
|
| 500 |
original_output: lastQ4.original_output, variant_output: lastQ4.variant_output
|
| 501 |
}
|
| 502 |
};
|
|
|
|
| 521 |
document.getElementById("q4change").value = d.q4.change || "";
|
| 522 |
if (d.q4.code) editor.setValue(d.q4.code);
|
| 523 |
q4target.value = d.q4.target || ""; q4key.value = d.q4.key || "";
|
| 524 |
+
document.getElementById("q4origout").value = d.q4.origout || "";
|
| 525 |
+
document.getElementById("q4varout").value = d.q4.varout || "";
|
| 526 |
lastQ4 = { original_output: d.q4.original_output || "", variant_output: d.q4.variant_output || "" };
|
| 527 |
}
|
| 528 |
// banner
|