diff options
author | prathamesh | 2013-05-06 11:56:16 +0530 |
---|---|---|
committer | prathamesh | 2013-05-08 12:21:37 +0530 |
commit | 6667efae7acb86f60b0ebd4dabb959bed759bc16 (patch) | |
tree | a0d7a22670e91427e82cd6037c8bd29155d38b51 /testapp/exam/xmlrpc_clients.py | |
parent | 8b6ac259503323bc3d8333382d3769e5d10f162a (diff) | |
download | online_test-6667efae7acb86f60b0ebd4dabb959bed759bc16.tar.gz online_test-6667efae7acb86f60b0ebd4dabb959bed759bc16.tar.bz2 online_test-6667efae7acb86f60b0ebd4dabb959bed759bc16.zip |
Function to check C-C++ code
Added a function which compiles C and C++ code submitted by the student.
1) If compilation is successful, then the submitted code is tested using
test-cases.
2) To test the function written by the student, a C++ file calls the
function and passes the argument to the function. Then the function
checks for the expected return value.
3) If the return value is as expected, then a different set of arguments
are passed, and the output is checked.
4) If for all set of arguments the output is as expected then the student
code is graded correct else the error is displayed to the student.
Changed the way the code is graded.
Previously, the algorithm checked the student code for all test-cases.
If all the test-cases were satisfied, the last-line
of the program was reached and printed "All Correct". So at
any point if a test-case fails, the last line is not reached as
the program was terminate. When the string "All Correct" was
found in the output, the code was graded as RIGHT else WRONG.
This is not a proper way for code checking, as the student code *may*
contain a print statement with the string('All Correct'), and thus
can get program RIGHT even though it is WRONG.
So now the student code is tested as follows:
1) The code checks for all test-cases.
2) If all test-cases are satisfied then it returns 0.
3) If any one of the test-case fails, the program is terminated and will return 1.
4) Now depending on the return status(0 or 1), it will grade the code.
a) if 0 then RIGHT
b) if 1 then WRONG
This ensures, no manipulation from student side.
Diffstat (limited to 'testapp/exam/xmlrpc_clients.py')
-rw-r--r-- | testapp/exam/xmlrpc_clients.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/testapp/exam/xmlrpc_clients.py b/testapp/exam/xmlrpc_clients.py index 817e37d..b846212 100644 --- a/testapp/exam/xmlrpc_clients.py +++ b/testapp/exam/xmlrpc_clients.py @@ -9,19 +9,24 @@ from settings import SERVER_PORTS, SERVER_POOL_PORT class ConnectionError(Exception): pass -################################################################################ +############################################################################### # `CodeServerProxy` class. -################################################################################ +############################################################################### + + class CodeServerProxy(object): """A class that manages accesing the farm of Python servers and making calls to them such that no one XMLRPC server is overloaded. """ def __init__(self): - pool_url = 'http://localhost:%d'%(SERVER_POOL_PORT) + pool_url = 'http://localhost:%d' % (SERVER_POOL_PORT) self.pool_server = ServerProxy(pool_url) self.methods = {"python": 'run_python_code', - "bash": 'run_bash_code'} - + "bash": 'run_bash_code', + "C": "run_c_code", + "C++": "run_cplus_code", + } + def run_code(self, answer, test_code, user_dir, language): """Tests given code (`answer`) with the `test_code` supplied. If the optional `in_dir` keyword argument is supplied it changes the directory @@ -68,11 +73,10 @@ class CodeServerProxy(object): else: done = True if not done: - raise ConnectionError("Couldn't connect to a server!") - proxy = ServerProxy('http://localhost:%d'%port) + raise ConnectionError("Couldn't connect to a server!") + proxy = ServerProxy('http://localhost:%d' % port) return proxy # views.py calls this Python server which forwards the request to one # of the running servers. code_server = CodeServerProxy() - |