@@ -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+ }
0 commit comments