-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgrade_function.py
More file actions
68 lines (55 loc) · 1.41 KB
/
grade_function.py
File metadata and controls
68 lines (55 loc) · 1.41 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
from grader import decorators
from grader import utils
import ast
template="""${code}
alist = []
n = int(input())
for i in range(n):
alist.append(int(input()))
print(bubbleSort(alist))
"""
def allowed(code):
if "sorted" in code:
return False
return True
def register_test(description, input, timeline=1, template="${code}"):
@decorators.test
@decorators.set_description(description)
@decorators.input(input)
@decorators.timeout(timeline)
@decorators.template(template)
def check_sort(m):
if not allowed(utils.read_code(m.module_path)):
raise Exception("You can not use python function 'sorted'")
x = m.response
test = x[0]
for i in range(len(x)):
if i == 0:
continue
if x[i] < test:
raise Exception("Ocekivana vrednost '%s', dobijena '%s'" %
(str(sorted(x)), str(m.response)))
register_test(
"Sort next list [54, 26, 93, 17, 77, 31, 44, 55, 20]",
[9, 54, 26, 93, 17, 77, 31, 44, 55, 20],
1,
template
)
register_test(
"Sort next list [1, 2, 3, 4, 5, 6, 7, 8, 9]",
[9, 1, 2, 3, 4, 5, 6, 7, 8, 9],
1,
template
)
register_test(
"Sort next list [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]",
[10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
1,
template
)
register_test(
"Sort next list [58, 23]",
[2, 58, 23],
1,
template
)