-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunittestexample.html
More file actions
executable file
·74 lines (71 loc) · 3.11 KB
/
unittestexample.html
File metadata and controls
executable file
·74 lines (71 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<html>
<head>
<title>unittest parsons</title>
<link rel="stylesheet" href="parsons.css"/>
<link href="lib/prettify.css" type="text/css" rel="stylesheet" />
<script src="lib/prettify.js"></script>
<meta charset="utf8"/>
</head>
<body>
<div id="sortableTrash" class="sortable-code"><p>Trash</p></div>
<div id="sortable" class="sortable-code"><p>Solution</p></div>
<div style="clear:both;"></div>
<p>
<a href="#" id="newInstanceLink">New instance</a>
<a href="#" id="feedbackLink">Get feedback</a>
<a href="#" id="previouslyLink">previously</a>
</p>
<div id="unittest"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<script src="lib/underscore-min.js"></script>
<script src="lib/lis.js"></script>
<script src="parsons.js"></script>
<script src="lib/skulpt.js"></script>
<script>
var initial = "def maxindex(arg):\n" +
" ans = 0\n" +
" for i in range(len(arg)):\n" +
" if arg[i] > arg[ans]:\n" +
" ans = i\n" +
" return ans\n";
var unittests = [
{ message: "Calling function <code>maxindex([0, 2, 4])</code>.", code: "maxi = maxindex([0, 2, 4])", variable: "maxi", expected: 2 },
{ message: "Calling function <code>maxindex([7, 2, 4])</code>.", code: "maxi = maxindex([7, 2, 4])", variable: "maxi", expected: 0 },
{ message: "Calling function <code>maxindex([7, 8, 4])</code>.", code: "maxi = maxindex([7, 8, 4])", variable: "maxi", expected: 1 },
];
$(document).ready(function(){
var parson = new ParsonsWidget({
'sortableId': 'sortable',
'trashId': 'sortableTrash',
'unittests': unittests
});
parson.init(initial);
parson.shuffleLines();
$("#newInstanceLink").click(function(event){
event.preventDefault();
parson.shuffleLines();
});
$("#feedbackLink").click(function(event){
event.preventDefault();
var fb = parson.getFeedback();
$("#unittest").html("<h2>Feedback from testing your program:</h2>" + fb.feedback);
if (fb.success) { alert("Good, you solved the assignment!"); }
});
$("#previouslyLink").click(function(event){
event.preventDefault();
var action = parson.whatWeDidPreviously();
if (!action) {
alert("nothing");
} else {
var html = parson.getHtmlFromHash(action.output, "prev");
$("#last").html(html);
//var p2 = new ParsonsWidget({'sortableId': 'sortable2',});
//p2.modified_lines = $.extend(true, [], action.output);
//p2.createHtml();
}
});
});
</script>
</body>
</html>