summaryrefslogtreecommitdiff
path: root/yaksh/evaluator_tests/test_java_evaluation.py
diff options
context:
space:
mode:
authormaheshgudi2016-08-03 15:16:08 +0530
committermaheshgudi2016-08-03 15:16:08 +0530
commit40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb (patch)
tree7885b674d2deb064137f1f501ed1707bfd54daf8 /yaksh/evaluator_tests/test_java_evaluation.py
parent1b71abc9437d721a41f017db406f312755f5a4c4 (diff)
parent2b03aeb36fa333ea1644a248c742cf0c1df12a5f (diff)
downloadonline_test-40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb.tar.gz
online_test-40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb.tar.bz2
online_test-40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb.zip
rebase changes with stdio evaluator
Diffstat (limited to 'yaksh/evaluator_tests/test_java_evaluation.py')
-rw-r--r--yaksh/evaluator_tests/test_java_evaluation.py46
1 files changed, 41 insertions, 5 deletions
diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py
index c98a938..74ac677 100644
--- a/yaksh/evaluator_tests/test_java_evaluation.py
+++ b/yaksh/evaluator_tests/test_java_evaluation.py
@@ -12,11 +12,12 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase):
self.test_case_data = [
{"test_case": "java_files/main_square.java"}
]
- self.in_dir = "/tmp"
+ self.in_dir = os.getcwd()
evaluator.SERVER_TIMEOUT = 9
self.timeout_msg = ("Code took more than {0} seconds to run. "
"You probably have an infinite loop in"
" your code.").format(evaluator.SERVER_TIMEOUT)
+ self.file_paths = None
def tearDown(self):
evaluator.SERVER_TIMEOUT = 2
@@ -25,7 +26,8 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase):
user_answer = "class Test {\n\tint square_num(int a) {\n\treturn a*a;\n\t}\n}"
get_class = JavaCodeEvaluator(self.in_dir)
kwargs = {'user_answer': user_answer,
- 'test_case_data': self.test_case_data
+ 'test_case_data': self.test_case_data,
+ 'file_paths': self.file_paths
}
result = get_class.evaluate(**kwargs)
self.assertEquals(result.get('error'), "Correct answer")
@@ -35,7 +37,8 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase):
user_answer = "class Test {\n\tint square_num(int a) {\n\treturn a;\n\t}\n}"
get_class = JavaCodeEvaluator(self.in_dir)
kwargs = {'user_answer': user_answer,
- 'test_case_data': self.test_case_data
+ 'test_case_data': self.test_case_data,
+ 'file_paths': self.file_paths
}
result = get_class.evaluate(**kwargs)
self.assertFalse(result.get('success'))
@@ -46,7 +49,8 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase):
user_answer = "class Test {\n\tint square_num(int a) {\n\treturn a*a"
get_class = JavaCodeEvaluator(self.in_dir)
kwargs = {'user_answer': user_answer,
- 'test_case_data': self.test_case_data
+ 'test_case_data': self.test_case_data,
+ 'file_paths': self.file_paths
}
result = get_class.evaluate(**kwargs)
self.assertFalse(result.get("success"))
@@ -56,12 +60,44 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase):
user_answer = "class Test {\n\tint square_num(int a) {\n\t\twhile(0==0){\n\t\t}\n\t}\n}"
get_class = JavaCodeEvaluator(self.in_dir)
kwargs = {'user_answer': user_answer,
- 'test_case_data': self.test_case_data
+ 'test_case_data': self.test_case_data,
+ 'file_paths': self.file_paths
}
result = get_class.evaluate(**kwargs)
self.assertFalse(result.get("success"))
self.assertEquals(result.get("error"), self.timeout_msg)
+ def test_file_based_assert(self):
+ self.file_paths = [(os.getcwd()+"/yaksh/test.txt", False)]
+ self.test_case_data = [
+ {"test_case": "java_files/read_file.java"}
+ ]
+ user_answer = dedent("""
+ import java.io.BufferedReader;
+ import java.io.FileReader;
+ import java.io.IOException;
+ class Test{
+ String readFile() throws IOException {
+ BufferedReader br = new BufferedReader(new FileReader("test.txt"));
+ try {
+ StringBuilder sb = new StringBuilder();
+ String line = br.readLine();
+ while (line != null) {
+ sb.append(line);
+ line = br.readLine();}
+ return sb.toString();
+ } finally {
+ br.close();
+ }}}
+ """)
+ get_class = JavaCodeEvaluator(self.in_dir)
+ kwargs = {'user_answer': user_answer,
+ 'test_case_data': self.test_case_data,
+ 'file_paths': self.file_paths
+ }
+ result = get_class.evaluate(**kwargs)
+ self.assertTrue(result.get("success"))
+ self.assertEquals(result.get("error"), "Correct answer")
class JavaStdioEvaluationTestCases(unittest.TestCase):