@@ -27,9 +27,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2727$ ( document ) . ready ( function ( ) {
2828 eduPythonCommonInit ( ) ; // must call this first!
2929
30+ $ ( "#actualCodeInput" ) . tabby ( ) ; // recognize TAB and SHIFT-TAB
31+ $ ( "#testCodeInput" ) . tabby ( ) ; // recognize TAB and SHIFT-TAB
32+
3033 $ ( "#pyOutputPane" ) . hide ( ) ;
3134
3235 // for demo purposes ...
36+ var reverseScript =
37+ "def reverse(lst):\n\
38+ N = len(lst) - 1\n\
39+ for i in range(N/2):\n\
40+ tmp = lst[i]\n\
41+ lst[i] = lst[N-i]\n\
42+ lst[N-i] = tmp\n" ;
43+
44+ var testCode =
45+ "input = ['a', 'b', 'c', 'd', 'e']\n\
46+ reverse(input)\n" ;
47+
48+ $ ( "#actualCodeInput" ) . val ( reverseScript ) ;
49+ $ ( "#testCodeInput" ) . val ( testCode ) ;
50+
51+ $ ( "#showHintHref" ) . click ( function ( ) {
52+ $ ( "#HintStatement" ) . html ( "<b>Hint</b>: Think about swapping pairs of elements." ) ;
53+ return false ; // don't reload the page
54+ } ) ;
55+
56+ $ ( "#showSolutionHref" ) . click ( function ( ) {
57+ $ ( "#SolutionStatement" ) . html ( "<b>Solution</b>: Swap the first and last elements, then the second and second-to-last elements, etc." ) ;
58+ return false ; // don't reload the page
59+ } ) ;
3360
3461
3562 $ ( "#executeBtn" ) . attr ( 'disabled' , false ) ;
@@ -38,18 +65,24 @@ $(document).ready(function() {
3865 $ ( '#executeBtn' ) . attr ( 'disabled' , true ) ;
3966 $ ( "#pyOutputPane" ) . hide ( ) ;
4067
68+ // concatenate the values from #actualCodeInput and #testCodeInput,
69+ // separated by a comment
70+ var submittedCode = $ ( "#actualCodeInput" ) . val ( ) +
71+ "\n# Everything below here is test code\n" +
72+ $ ( "#testCodeInput" ) . val ( ) ;
73+
4174 $ . post ( "cgi-bin/web_exec.py" ,
42- { user_script : $ ( "#pyInput" ) . val ( ) } ,
75+ { user_script : submittedCode } ,
4376 function ( traceData ) {
44- renderPyCodeOutput ( $ ( "#pyInput" ) . val ( ) ) ;
77+ renderPyCodeOutput ( submittedCode ) ;
4578 processTrace ( traceData ) ;
4679
47- $ ( "#pyInputPane" ) . hide ( ) ;
48- $ ( "#pyOutputPane" ) . show ( ) ;
49- appMode = 'visualize' ;
80+ $ ( "#pyInputPane" ) . hide ( ) ;
81+ $ ( "#pyOutputPane" ) . show ( ) ;
82+ appMode = 'visualize' ;
5083
51- $ ( '#executeBtn' ) . html ( "Visualize execution" ) ;
52- $ ( '#executeBtn' ) . attr ( 'disabled' , false ) ;
84+ $ ( '#executeBtn' ) . html ( "Visualize execution" ) ;
85+ $ ( '#executeBtn' ) . attr ( 'disabled' , false ) ;
5386 } ,
5487 "json" ) ;
5588 } ) ;
0 commit comments