-
Notifications
You must be signed in to change notification settings - Fork 1
/
challenge.py
executable file
·71 lines (52 loc) · 1.71 KB
/
challenge.py
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
#!/usr/bin/python
import sys
sys.path.append("challenges")
class Challenge:
"""The generic challenge class. All classes should heritage from this one"""
def name(self):
"""name of challenge"""
pass
def desc(self):
"""Description of challenge should return a string"""
pass
def example(self):
"""Give an example of the challenge problem and an example solution (if applicable)"""
pass
def challenge(self):
"""the actual challenge given to the nerd"""
def passed(self,answer):
"""Boolean function to check if the answer given to the challenge is correct or wrong."""
pass
def validAnswer(self):
"""Used in example, and for testing purposes"""
pass
def timeLimit(self):
""" Gives the time limit for the challenge. 0 => infinite """
pass
"""server for the challenge"""
challengeServer = "pompel.komsys.org:1337"
challengeDir = "challenges"
def test(challenge):
""" Testing method for challenge objects :) It will test all methods, including challenge, passed and validanswer"""
o = challenge #shorter name :)
print "Testing started"
try:
(n,d,e,c,p,a,t) = (o.name(), o.desc(), o.example(), o.challenge(), o.passed(o.validAnswer()), o.validAnswer(), o.timeLimit())
#for t in (n,d,e,c): if not isinstance(t, 'str'): raise Exception("%s is not returning a string")
print ("""
Name: %s
Desc: %s
example: %s
challenge: %s
Time limit: %s
passed?: %s (answer: %s)
""" % (n,d,e,c,t,p,a))
if not p:
raise Exception("Did not pass the evaluation: Answer: %s " % (a))
print ("Passed :)")
return True
except Exception as en:
print ("Did not pass... %s " %(en) )
return False
if __name__ == "__main__":
print("Dont run me, use me!")