Skip to content

Commit a8f1b15

Browse files
author
Philip Guo
committed
awkward intermediate state
1 parent 6a3aa91 commit a8f1b15

2 files changed

Lines changed: 65 additions & 23 deletions

File tree

edu-python-questions.js

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -235,35 +235,71 @@ function finishQuestionsInit(questionsDat) {
235235
"json");
236236
}
237237

238-
return;
238+
});
239239

240-
enterGradingMode();
241-
$("#submittedCodeRO").val($("#actualCodeInput").val());
240+
}
242241

243-
// iterate through all pairs of test and expect code:
244-
for (var i = 0; i < tests.length; i++) {
245-
$("#gradeMatrix tbody").append("<tr></tr>");
246242

247-
var submittedCode = concatSolnTestCode($("#actualCodeInput").val(), tests[i]);
248-
var expectCode = expects[i];
243+
// should be called after ALL elements in testsTraces and expectsTraces
244+
// have been populated by their respective AJAX POST calls
245+
function readyToGradeSubmission() {
246+
enterGradingMode();
247+
$("#submittedCodeRO").val($("#actualCodeInput").val());
249248

250-
$("#gradeMatrix tr:last").append("<td><pre>" + tests[i] + "</pre></td>");
251-
$("#gradeMatrix tr:last").append("<td><pre>" + expectCode + "</pre></td>");
252-
if (i % 2) {
253-
$("#gradeMatrix tr:last").append('<td><img style="vertical-align: middle; margin-right: 4px;" src="red-sad-face.jpg"/> <span><a href="#">Debug me</a></span></td>');
254-
}
255-
else {
256-
$("#gradeMatrix tr:last").append('<td><img style="vertical-align: middle;" src="yellow-happy-face.png"/></td>');
257-
}
249+
for (var i = 0; i < tests.length; i++) {
250+
$("#gradeMatrix tbody").append("<tr></tr>");
251+
252+
var testResults = testsTraces[i];
253+
var expectResults = expectsTraces[i];
254+
assert(testResults && expectResults);
255+
256+
257+
// Procedure for grading testResults vs. expectResults:
258+
// - The final line in expectResults should be a 'return' from
259+
// '<module>' that contains only ONE global variable. THAT'S
260+
// the variable that we're gonna compare against testResults.
261+
262+
var testLastEntry = testResults[testResults.length - 1];
263+
var expectLastEntry = expectResults[expectResults.length - 1];
258264

265+
assert(expectLastEntry.event == 'return');
266+
assert(expectLastEntry.func_name == '<module>');
267+
268+
// find the SOLE global variable in expectLastEntry and use that as
269+
// the point of comparison against testLastEntry
270+
var expectGlobals = [];
271+
for (g in expectLastEntry.globals) {
272+
expectGlobals.push(g);
273+
}
274+
assert(expectGlobals.length == 1);
275+
var varToCompare = expectGlobals[0];
276+
277+
var resultIsCorrect = false;
278+
279+
if (testLastEntry.event == 'return') {
280+
var testVal = testLastEntry.globals[varToCompare];
281+
var expectVal = expectLastEntry.globals[varToCompare];
282+
console.log(testVal);
283+
console.log(expectVal);
284+
if (equalsModuloID(testVal, expectVal)) {
285+
resultIsCorrect = true;
286+
}
287+
}
288+
else {
289+
// something else happened, and there's no match!
290+
assert(testLastEntry.exception_msg);
291+
console.log(testLastEntry.exception_msg);
259292
}
260-
});
261293

262-
}
294+
$("#gradeMatrix tr:last").append("<td><pre>in</pre></td>");
295+
$("#gradeMatrix tr:last").append("<td><pre>out</pre></td>");
263296

264-
// should be called after ALL elements in testsTraces and expectsTraces
265-
// have been populated by their respective AJAX POST calls
266-
function readyToGradeSubmission() {
267-
console.log('readyToGradeSubmission');
268-
}
297+
if (resultIsCorrect) {
298+
$("#gradeMatrix tr:last").append('<td><img style="vertical-align: middle;" src="yellow-happy-face.png"/></td>');
299+
}
300+
else {
301+
$("#gradeMatrix tr:last").append('<td><img style="vertical-align: middle; margin-right: 4px;" src="red-sad-face.jpg"/> <span><a href="#">Debug me</a></span></td>');
302+
}
269303

304+
}
305+
}

questions/inplace-reverse.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ Skeleton:
1616

1717
def reverse(lst):
1818
# write your solution code here
19+
N = len(lst) - 1
20+
for i in range(N/2):
21+
tmp = lst[i]
22+
lst[i] = lst[N-i]
23+
lst[N-i] = tmp
24+
1925

2026
Test:
2127
input = ['a', 'b', 'c', 'd', 'e']

0 commit comments

Comments
 (0)