summaryrefslogtreecommitdiff
path: root/yaksh/evaluator_tests/test_c_cpp_evaluation.py
diff options
context:
space:
mode:
authorankitjavalkar2016-03-22 12:02:47 +0530
committerankitjavalkar2016-05-05 19:00:33 +0530
commit597c23866be3ecfdf94c40693b060fe9ebbf6446 (patch)
treebebb0c8e7aed24fb16e07070f7648305acfad755 /yaksh/evaluator_tests/test_c_cpp_evaluation.py
parent0520bf284f9b34782fa90b433d714c887049f339 (diff)
downloadonline_test-597c23866be3ecfdf94c40693b060fe9ebbf6446.tar.gz
online_test-597c23866be3ecfdf94c40693b060fe9ebbf6446.tar.bz2
online_test-597c23866be3ecfdf94c40693b060fe9ebbf6446.zip
Refactor C/CPP code evaluator and add test cases
Diffstat (limited to 'yaksh/evaluator_tests/test_c_cpp_evaluation.py')
-rw-r--r--yaksh/evaluator_tests/test_c_cpp_evaluation.py69
1 files changed, 18 insertions, 51 deletions
diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py
index d01cc9c..c5f8775 100644
--- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py
+++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py
@@ -5,71 +5,38 @@ from yaksh.settings import SERVER_TIMEOUT
class CEvaluationTestCases(unittest.TestCase):
def setUp(self):
- self.language = "C"
- self.ref_code_path = "c_cpp_files/main.cpp"
+ self.test_case_data = ["c_cpp_files/main.cpp"]
self.in_dir = "/tmp"
- self.test_case_data = []
self.timeout_msg = ("Code took more than {0} seconds to run. "
"You probably have an infinite loop in your code.").format(SERVER_TIMEOUT)
- self.test = None
def test_correct_answer(self):
user_answer = "int add(int a, int b)\n{return a+b;}"
- get_class = CppCodeEvaluator(self.test_case_data, self.test, self.language, user_answer, self.ref_code_path, self.in_dir)
- result = get_class.evaluate()
-
- self.assertTrue(result.get("success"))
- self.assertEqual(result.get("error"), "Correct answer")
+ get_class = CppCodeEvaluator(self.in_dir)
+ kwargs = {'user_answer': user_answer,
+ 'test_case_data': self.test_case_data
+ }
+ result = get_class.evaluate(**kwargs)
+ self.assertTrue(result.get('success'))
+ self.assertEqual(result.get('error'), "Correct answer")
def test_compilation_error(self):
user_answer = "int add(int a, int b)\n{return a+b}"
- get_class = CppCodeEvaluator(self.test_case_data, self.test, self.language, user_answer, self.ref_code_path, self.in_dir)
- result = get_class.evaluate()
-
- self.assertFalse(result.get("success"))
- self.assertTrue("Compilation Error" in result.get("error"))
-
- def test_infinite_loop(self):
- user_answer = "int add(int a, int b)\n{while(1>0){}}"
- get_class = CppCodeEvaluator(self.test_case_data, self.test, self.language, user_answer, self.ref_code_path, self.in_dir)
- result = get_class.evaluate()
-
- self.assertFalse(result.get("success"))
- self.assertEquals(result.get("error"), self.timeout_msg)
-
-
-###############################################################################
-class CppEvaluationTestCases(unittest.TestCase):
- def setUp(self):
- self.language = "CPP"
- self.ref_code_path = "c_cpp_files/main.cpp"
- self.in_dir = "/tmp"
- self.test_case_data = []
- self.timeout_msg = ("Code took more than {0} seconds to run. "
- "You probably have an infinite loop in your code.").format(SERVER_TIMEOUT)
- self.test = None
-
- def test_correct_answer(self):
- user_answer = "int add(int a, int b)\n{return a+b;}"
- get_class = CppCodeEvaluator(self.test_case_data, self.test, self.language, user_answer, self.ref_code_path, self.in_dir)
- result = get_class.evaluate()
-
- self.assertTrue(result.get("success"))
- self.assertEqual(result.get("error"), "Correct answer")
-
- def test_compilation_error(self):
- user_answer = "int add(int a, int b)\n{return a+b}"
- get_class = CppCodeEvaluator(self.test_case_data, self.test, self.language, user_answer, self.ref_code_path, self.in_dir)
- result = get_class.evaluate()
-
+ get_class = CppCodeEvaluator(self.in_dir)
+ kwargs = {'user_answer': user_answer,
+ 'test_case_data': self.test_case_data
+ }
+ result = get_class.evaluate(**kwargs)
self.assertFalse(result.get("success"))
self.assertTrue("Compilation Error" in result.get("error"))
def test_infinite_loop(self):
user_answer = "int add(int a, int b)\n{while(1>0){}}"
- get_class = CppCodeEvaluator(self.test_case_data, self.test, self.language, user_answer, self.ref_code_path, self.in_dir)
- result = get_class.evaluate()
-
+ get_class = CppCodeEvaluator(self.in_dir)
+ kwargs = {'user_answer': user_answer,
+ 'test_case_data': self.test_case_data
+ }
+ result = get_class.evaluate(**kwargs)
self.assertFalse(result.get("success"))
self.assertEquals(result.get("error"), self.timeout_msg)