From f5ea9ecf903360c2860293639d1c6ba7a78b2339 Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 2 Jun 2016 14:24:57 +0530 Subject: c,cpp,java evaluators with test cases --- yaksh/evaluator_tests/test_c_cpp_evaluation.py | 262 +++++++++++++++++++++++++ yaksh/evaluator_tests/test_java_evaluation.py | 125 ++++++++++++ 2 files changed, 387 insertions(+) (limited to 'yaksh/evaluator_tests') diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py index 71fb843..7a87d87 100644 --- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py +++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py @@ -1,7 +1,10 @@ import unittest import os from yaksh.cpp_code_evaluator import CppCodeEvaluator +from yaksh.cpp_stdio_evaluator import CppStdioEvaluator from yaksh.settings import SERVER_TIMEOUT +from textwrap import dedent + class CEvaluationTestCases(unittest.TestCase): def setUp(self): @@ -52,5 +55,264 @@ class CEvaluationTestCases(unittest.TestCase): self.assertFalse(result.get("success")) self.assertEquals(result.get("error"), self.timeout_msg) + +class CStdioEvaluationTestCases(unittest.TestCase): + + def setUp(self): + self.test_case_data = [{'expected_output': '11', 'expected_input': '5\n6'}] + self.timeout_msg = ("Code took more than {0} seconds to run. " + "You probably have an infinite loop in" + " your code.").format(SERVER_TIMEOUT) + + def test_correct_answer(self): + user_answer = dedent(""" + #include + int main(void){ + int a,b; + scanf("%d%d",&a,&b); + printf("%d",a+b); + }""") + get_class = CppStdioEvaluator() + kwargs = {'user_answer': user_answer, + 'test_case_data': self.test_case_data + } + result = get_class.evaluate(**kwargs) + self.assertEquals(result.get('error'), "Correct Answer") + self.assertTrue(result.get('success')) + + def test_array_input(self): + self.test_case_data = [{'expected_output': '561', + 'expected_input': '5,6,1'}] + user_answer = dedent(""" + #include + int main(void){ + int a[3],i; + for(i=0;i<3;i++){ + scanf("%d",&a[i]);} + for(i=0;i<3;i++){ + printf("%d",a[i]);} + }""") + get_class = CppStdioEvaluator() + kwargs = {'user_answer': user_answer, + 'test_case_data': self.test_case_data + } + result = get_class.evaluate(**kwargs) + self.assertEquals(result.get('error'), "Correct Answer") + self.assertTrue(result.get('success')) + + def test_string_input(self): + self.test_case_data = [{'expected_output': 'abc', + 'expected_input': 'abc'}] + user_answer = dedent(""" + #include + int main(void){ + char a[4]; + scanf("%s",a); + printf("%s",a); + }""") + get_class = CppStdioEvaluator() + kwargs = {'user_answer': user_answer, + 'test_case_data': self.test_case_data + } + result = get_class.evaluate(**kwargs) + self.assertEquals(result.get('error'), "Correct Answer") + self.assertTrue(result.get('success')) + + def test_incorrect_answer(self): + user_answer = dedent(""" + #include + int main(void){ + int a=10; + printf("%d",a); + }""") + get_class = CppStdioEvaluator() + kwargs = {'user_answer': user_answer, + 'test_case_data': self.test_case_data + } + result = get_class.evaluate(**kwargs) + self.assertFalse(result.get('success')) + self.assertIn("Incorrect", result.get('error')) + self.assertTrue(result.get('error').splitlines > 1) + + def test_error(self): + user_answer = dedent(""" + #include + int main(void){ + int a=10; + printf("%d",a) + }""") + get_class = CppStdioEvaluator() + 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 = dedent(""" + #include + int main(void){ + while(0==0){ + printf("abc");} + }""") + get_class = CppStdioEvaluator() + 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) + + def test_only_stdout(self): + self.test_case_data = [{'expected_output': '11', + 'expected_input': ''}] + user_answer = dedent(""" + #include + int main(void){ + int a=5,b=6; + printf("%d",a+b); + }""") + get_class = CppStdioEvaluator() + kwargs = {'user_answer': user_answer, + 'test_case_data': self.test_case_data + } + result = get_class.evaluate(**kwargs) + self.assertEquals(result.get('error'), "Correct Answer") + self.assertTrue(result.get('success')) + + +class CppStdioEvaluationTestCases(unittest.TestCase): + + def setUp(self): + self.test_case_data = [{'expected_output': '11', 'expected_input': '5\n6'}] + self.timeout_msg = ("Code took more than {0} seconds to run. " + "You probably have an infinite loop in" + " your code.").format(SERVER_TIMEOUT) + + def test_correct_answer(self): + user_answer = dedent(""" + #include + using namespace std; + int main(void){ + int a,b; + cin>>a>>b; + cout< + using namespace std; + int main(void){ + int a[3],i; + for(i=0;i<3;i++){ + cin>>a[i];} + for(i=0;i<3;i++){ + cout< + using namespace std; + int main(void){ + char a[4]; + cin>>a; + cout< + using namespace std; + int main(void){ + int a=10; + cout< 1) + + def test_error(self): + user_answer = dedent(""" + #include + using namespace std; + int main(void){ + int a=10; + cout< + using namespace std; + int main(void){ + while(0==0){ + cout<<"abc";} + }""") + get_class = CppStdioEvaluator() + 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) + + def test_only_stdout(self): + self.test_case_data = [{'expected_output': '11', + 'expected_input': ''}] + user_answer = dedent(""" + #include + using namespace std; + int main(void){ + int a=5,b=6; + cout< 1) + + def test_error(self): + + user_answer = dedent(""" + class Test + { + System.out.print("a"); + }""") + get_class = JavaStdioEvaluator() + 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 = dedent(""" + class Test + {public static void main(String[] args){ + while(0==0) + { + System.out.print("a");} + }}""") + get_class = JavaStdioEvaluator() + 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) + + def test_only_stdout(self): + self.test_case_data = [{'expected_output': '11', + 'expected_input': ''}] + user_answer = dedent(""" + class Test + {public static void main(String[] args){ + int a = 5; + int b = 6; + System.out.print(a+b); + }}""") + get_class = JavaStdioEvaluator() + kwargs = {'user_answer': user_answer, + 'test_case_data': self.test_case_data + } + result = get_class.evaluate(**kwargs) + self.assertEquals(result.get('error'), "Correct Answer") + self.assertTrue(result.get('success')) + if __name__ == '__main__': unittest.main() -- cgit From bb76e0a25b113b0f40b47f19eaa2c053e0b4e423 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Thu, 2 Jun 2016 16:00:27 +0530 Subject: changed model class name Stdout to Stdio --- yaksh/evaluator_tests/test_java_evaluation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh/evaluator_tests') diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py index 8cfccb9..fa8d68c 100644 --- a/yaksh/evaluator_tests/test_java_evaluation.py +++ b/yaksh/evaluator_tests/test_java_evaluation.py @@ -68,13 +68,13 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): def setUp(self): self.test_case_data = [{'expected_output': '11', 'expected_input': '5\n6'}] - evaluator.SERVER_TIMEOUT = 9 + evaluator.SERVER_TIMEOUT = 4 self.timeout_msg = ("Code took more than {0} seconds to run. " "You probably have an infinite loop in" " your code.").format(evaluator.SERVER_TIMEOUT) def teardown(self): - evaluator.SERVER_TIMEOUT = 2 + evaluator.SERVER_TIMEOUT = 4 def test_correct_answer(self): user_answer = dedent(""" -- cgit From bdebcc790e6f0ac0f53795c017568ad44c8f01dd Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Thu, 2 Jun 2016 16:01:03 +0530 Subject: changed model class name Stdout to Stdio --- yaksh/evaluator_tests/test_code_evaluation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh/evaluator_tests') diff --git a/yaksh/evaluator_tests/test_code_evaluation.py b/yaksh/evaluator_tests/test_code_evaluation.py index 51c0c51..cbca32d 100644 --- a/yaksh/evaluator_tests/test_code_evaluation.py +++ b/yaksh/evaluator_tests/test_code_evaluation.py @@ -17,7 +17,7 @@ class RegistryTestCase(unittest.TestCase): ) code_evaluators['python'] = \ {"standardtestcase": assertion_evaluator_path, - "stdoutbasedtestcase": stdout_evaluator_path + "stdiobasedtestcase": stdout_evaluator_path } def test_set_register(self): @@ -35,7 +35,7 @@ class RegistryTestCase(unittest.TestCase): ) self.registry_object.register("python", {"standardtestcase": assertion_evaluator_path, - "stdoutbasedtestcase": stdout_evaluator_path + "stdiobasedtestcase": stdout_evaluator_path } ) self.assertEquals(evaluator_class, class_name) -- cgit From de63766dad6ed0755af0171cdfdae916e0e8676b Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Thu, 2 Jun 2016 16:01:59 +0530 Subject: added test cases for python stdio evaluator --- yaksh/evaluator_tests/test_python_evaluation.py | 159 +++++++++++++++++++----- 1 file changed, 127 insertions(+), 32 deletions(-) (limited to 'yaksh/evaluator_tests') diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py index 1e867a3..dfdc6ec 100644 --- a/yaksh/evaluator_tests/test_python_evaluation.py +++ b/yaksh/evaluator_tests/test_python_evaluation.py @@ -1,7 +1,7 @@ import unittest import os from yaksh.python_assertion_evaluator import PythonAssertionEvaluator -from yaksh.python_stdout_evaluator import PythonStdoutEvaluator +from yaksh.python_stdio_evaluator import PythonStdioEvaluator from yaksh.settings import SERVER_TIMEOUT from textwrap import dedent @@ -164,15 +164,15 @@ class PythonAssertionEvaluationTestCases(unittest.TestCase): return int(a) + int(b) + int(c) """) value_error_msg = ["Traceback", - "call", - "ValueError", - "invalid literal", - "base" - ] + "call", + "ValueError", + "invalid literal", + "base" + ] get_class = PythonAssertionEvaluator() kwargs = {'user_answer': user_answer, - 'test_case_data': self.test_case_data - } + 'test_case_data': self.test_case_data + } result = get_class.evaluate(**kwargs) err = result.get("error").splitlines() self.assertFalse(result.get("success")) @@ -180,55 +180,150 @@ class PythonAssertionEvaluationTestCases(unittest.TestCase): for msg in value_error_msg: self.assertIn(msg, result.get("error")) -class PythonStdoutEvaluationTestCases(unittest.TestCase): + +class PythonStdioEvaluationTestCases(unittest.TestCase): def setUp(self): - self.test_case_data = [{"expected_output": "0 1 1 2 3"}] + self.test_case_data = [{"expected_input": None, + "expected_output": "0 1 1 2 3" + }] + self.timeout_msg = ("Code took more than {0} seconds to run. " - "You probably have an infinite loop" - " in your code.").format(SERVER_TIMEOUT) + "You probably have an infinite loop" + " in your code.").format(SERVER_TIMEOUT) def test_correct_answer(self): user_answer = "a,b=0,1\nfor i in range(5):\n\tprint a,\n\ta,b=b,a+b" - get_class = PythonStdoutEvaluator() + get_class = PythonStdioEvaluator() kwargs = {'user_answer': user_answer, - 'test_case_data': self.test_case_data - } + 'test_case_data': self.test_case_data + } result = get_class.evaluate(**kwargs) - self.assertEqual(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) def test_incorrect_answer(self): user_answer = "a,b=0,1\nfor i in range(5):\n\tprint b,\n\ta,b=b,a+b" - get_class = PythonStdoutEvaluator() - kwargs = {'user_answer': user_answer, - 'test_case_data': self.test_case_data - } + get_class = PythonStdioEvaluator() + kwargs = {'user_answer': user_answer, + 'test_case_data': self.test_case_data + } result = get_class.evaluate(**kwargs) self.assertFalse(result.get('success')) - self.assertEqual(result.get('error'), "Incorrect Answer") + self.assertIn("Incorrect Answer", result.get('error')) def test_direct_printed_answer(self): user_answer = "print '0 1 1 2 3'" error_msg = ("Incorrect Answer: Please avoid printing" - " the expected output directly" - ) - get_class = PythonStdoutEvaluator() - kwargs = {'user_answer': user_answer, - 'test_case_data': self.test_case_data - } + " the expected output directly" + ) + get_class = PythonStdioEvaluator() + + kwargs = {'user_answer': user_answer, + 'test_case_data': self.test_case_data + } result = get_class.evaluate(**kwargs) self.assertFalse(result.get('success')) self.assertEqual(result.get('error'), error_msg) def test_infinite_loop(self): - user_answer = "def add(a, b):\n\twhile True:\n\t\tpass" - get_class = PythonStdoutEvaluator() + user_answer = "def add(a, b):\n\twhile True:\n\t\tpass\nadd(1,2)" + get_class = PythonStdioEvaluator() kwargs = {'user_answer': user_answer, - 'test_case_data': self.test_case_data - } + 'test_case_data': self.test_case_data + } + result = get_class.evaluate(**kwargs) + self.assertFalse(result.get('success')) + self.assertEqual(result.get('error'), self.timeout_msg) + + +class PythonStdIOEvaluator(unittest.TestCase): + + def setUp(self): + self.timeout_msg = ("Code took more than {0} seconds to run. " + "You probably have an infinite loop" + " in your code.").format(SERVER_TIMEOUT) + + def test_add_two_integers_correct(self): + self.test_case_data = [{"expected_input": "1\n2", + "expected_output": "3" + }] + user_answer = dedent(""" + a = int(raw_input()) + b = int(raw_input()) + print a+b + """ + ) + + get_class = PythonStdioEvaluator() + + kwargs = {'user_answer': user_answer, + 'test_case_data': self.test_case_data + } + result = get_class.evaluate(**kwargs) + self.assertTrue(result.get('success')) + self.assertIn("Correct Answer", result.get('error')) + + def test_add_two_lists(self): + self.test_case_data = [{"expected_input": "[1,2,3]\n[5,6,7]", + "expected_output": "[1, 2, 3, 5, 6, 7]" + }] + user_answer = dedent(""" + from ast import literal_eval + a = literal_eval(raw_input()) + b = literal_eval(raw_input()) + print a+b + """ + ) + + get_class = PythonStdioEvaluator() + + kwargs = {'user_answer': user_answer, + 'test_case_data': self.test_case_data + } + result = get_class.evaluate(**kwargs) + self.assertTrue(result.get('success')) + self.assertIn("Correct Answer", result.get('error')) + + def test_find_string_in_sentence(self): + self.test_case_data = [{"expected_input": """the quick brown fox jumps\ + over the lazy dog\nthe""", + "expected_output": "2" + }] + user_answer = dedent(""" + a = raw_input() + b = raw_input() + print (a.count(b)) + """ + ) + + get_class = PythonStdioEvaluator() + + kwargs = {'user_answer': user_answer, + 'test_case_data': self.test_case_data + } + result = get_class.evaluate(**kwargs) + self.assertTrue(result.get('success')) + self.assertIn("Correct Answer", result.get('error')) + + def test_add_two_integers_incorrect(self): + self.test_case_data = [{"expected_input": "1\n2", + "expected_output": "4" + }] + user_answer = dedent(""" + a = int(raw_input()) + b = int(raw_input()) + print a+b + """ + ) + + get_class = PythonStdioEvaluator() + + kwargs = {'user_answer': user_answer, + 'test_case_data': self.test_case_data + } result = get_class.evaluate(**kwargs) self.assertFalse(result.get('success')) - self.assertEqual(result.get('error'), 'Incorrect Answer') + self.assertIn("Incorrect Answer", result.get('error')) if __name__ == '__main__': -- cgit From 53192a5f757064b9f8873ea3fcfc7f9cd01e587c Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Wed, 8 Jun 2016 11:18:52 +0530 Subject: made changes to stdio evaluator and added bash evaluator with test cases --- yaksh/evaluator_tests/test_bash_evaluation.py | 81 ++++++++++++++++++++++++- yaksh/evaluator_tests/test_c_cpp_evaluation.py | 2 +- yaksh/evaluator_tests/test_java_evaluation.py | 2 +- yaksh/evaluator_tests/test_python_evaluation.py | 2 +- 4 files changed, 83 insertions(+), 4 deletions(-) (limited to 'yaksh/evaluator_tests') diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py index 4ff3e0a..f954ef0 100644 --- a/yaksh/evaluator_tests/test_bash_evaluation.py +++ b/yaksh/evaluator_tests/test_bash_evaluation.py @@ -1,9 +1,12 @@ import unittest import os from yaksh.bash_code_evaluator import BashCodeEvaluator +from yaksh.bash_stdio_evaluator import BashStdioEvaluator from yaksh.settings import SERVER_TIMEOUT +from textwrap import dedent -class BashEvaluationTestCases(unittest.TestCase): + +class BashAssertionEvaluationTestCases(unittest.TestCase): def setUp(self): self.test_case_data = [ {"test_case": "bash_files/sample.sh,bash_files/sample.args"} @@ -48,5 +51,81 @@ class BashEvaluationTestCases(unittest.TestCase): self.assertEquals(result.get("error"), self.timeout_msg) +class BashStdioEvaluationTestCases(unittest.TestCase): + def setUp(self): + self.timeout_msg = ("Code took more than {0} seconds to run. " + "You probably have an infinite loop in your" + " code.").format(SERVER_TIMEOUT) + + def test_correct_answer(self): + user_answer = dedent(""" #!/bin/bash + read A + read B + echo -n `expr $A + $B` + """ + ) + test_case_data = [{'expected_output': '11', 'expected_input': '5\n6'}] + get_class = BashStdioEvaluator() + kwargs = {"user_answer": user_answer, + "test_case_data": test_case_data + } + result = get_class.evaluate(**kwargs) + self.assertEquals(result.get('error'), "Correct Answer") + self.assertTrue(result.get('success')) + + def test_array_input(self): + user_answer = dedent(""" readarray arr; + COUNTER=0 + while [ $COUNTER -lt 3 ]; do + echo -n "${arr[$COUNTER]}" + let COUNTER=COUNTER+1 + done + """ + ) + test_case_data = [{'expected_output': '1 2 3\n4 5 6\n7 8 9\n', + 'expected_input': '1,2,3\n4,5,6\n7,8,9' + }] + get_class = BashStdioEvaluator() + kwargs = {"user_answer": user_answer, + "test_case_data": test_case_data + } + result = get_class.evaluate(**kwargs) + self.assertEquals(result.get('error'), "Correct Answer") + self.assertTrue(result.get('success')) + + def test_incorrect_answer(self): + user_answer = dedent(""" #!/bin/bash + read A + read B + echo -n `expr $A + $B` + """ + ) + test_case_data = [{'expected_output': '12', 'expected_input': '5\n6'}] + get_class = BashStdioEvaluator() + kwargs = {"user_answer": user_answer, + "test_case_data": test_case_data + } + result = get_class.evaluate(**kwargs) + self.assertIn("Incorrect", result.get('error')) + self.assertFalse(result.get('success')) + + def test_stdout_only(self): + user_answer = dedent(""" #!/bin/bash + A=6 + B=4 + echo -n `expr $A + $B` + """ + ) + test_case_data = [{'expected_output': '10', + 'expected_input': '' + }] + get_class = BashStdioEvaluator() + kwargs = {"user_answer": user_answer, + "test_case_data": test_case_data + } + result = get_class.evaluate(**kwargs) + self.assertEquals(result.get('error'), "Correct Answer") + self.assertTrue(result.get('success')) + if __name__ == '__main__': unittest.main() diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py index 7a87d87..3d2e9fe 100644 --- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py +++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py @@ -6,7 +6,7 @@ from yaksh.settings import SERVER_TIMEOUT from textwrap import dedent -class CEvaluationTestCases(unittest.TestCase): +class CAssertionEvaluationTestCases(unittest.TestCase): def setUp(self): self.test_case_data = [{"test_case": "c_cpp_files/main.cpp"}] self.in_dir = "/tmp" diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py index fa8d68c..211b324 100644 --- a/yaksh/evaluator_tests/test_java_evaluation.py +++ b/yaksh/evaluator_tests/test_java_evaluation.py @@ -7,7 +7,7 @@ from yaksh.settings import SERVER_TIMEOUT from textwrap import dedent -class JavaEvaluationTestCases(unittest.TestCase): +class JavaAssertionEvaluationTestCases(unittest.TestCase): def setUp(self): self.test_case_data = [ {"test_case": "java_files/main_square.java"} diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py index dfdc6ec..a935f1d 100644 --- a/yaksh/evaluator_tests/test_python_evaluation.py +++ b/yaksh/evaluator_tests/test_python_evaluation.py @@ -181,7 +181,7 @@ class PythonAssertionEvaluationTestCases(unittest.TestCase): self.assertIn(msg, result.get("error")) -class PythonStdioEvaluationTestCases(unittest.TestCase): +class PythonStdoutEvaluationTestCases(unittest.TestCase): def setUp(self): self.test_case_data = [{"expected_input": None, "expected_output": "0 1 1 2 3" -- cgit From bca8dd59b6d796af680cac3d7f65fc3ac6ed8420 Mon Sep 17 00:00:00 2001 From: adityacp Date: Wed, 27 Jul 2016 22:49:05 +0530 Subject: added testcase for string input --- yaksh/evaluator_tests/test_java_evaluation.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'yaksh/evaluator_tests') diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py index 211b324..c98a938 100644 --- a/yaksh/evaluator_tests/test_java_evaluation.py +++ b/yaksh/evaluator_tests/test_java_evaluation.py @@ -97,7 +97,7 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): def test_array_input(self): self.test_case_data = [{'expected_output': '561', - 'expected_input': '5,6,1'}] + 'expected_input': '5\n6\n1'}] user_answer = dedent(""" import java.util.Scanner; class Test @@ -186,5 +186,25 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): self.assertEquals(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) + def test_string_input(self): + self.test_case_data = [{'expected_output': 'HelloWorld', + 'expected_input': 'Hello\nWorld'}] + user_answer = dedent(""" + import java.util.Scanner; + class Test + {public static void main(String[] args){ + Scanner s = new Scanner(System.in); + String a = s.nextLine(); + String b = s.nextLine(); + System.out.print(a+b); + }}""") + get_class = JavaStdioEvaluator() + kwargs = {'user_answer': user_answer, + 'test_case_data': self.test_case_data + } + result = get_class.evaluate(**kwargs) + self.assertEquals(result.get('error'), "Correct Answer") + self.assertTrue(result.get('success')) + if __name__ == '__main__': unittest.main() -- cgit From bdbacc0a24970cbe27acd1aa1dbee0bd82157bdb Mon Sep 17 00:00:00 2001 From: adityacp Date: Wed, 27 Jul 2016 22:50:14 +0530 Subject: combined c and cpp testcase classes into single class --- yaksh/evaluator_tests/test_c_cpp_evaluation.py | 27 +++++++++----------------- 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'yaksh/evaluator_tests') diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py index 3d2e9fe..a2fc51f 100644 --- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py +++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py @@ -56,7 +56,7 @@ class CAssertionEvaluationTestCases(unittest.TestCase): self.assertEquals(result.get("error"), self.timeout_msg) -class CStdioEvaluationTestCases(unittest.TestCase): +class CppStdioEvaluationTestCases(unittest.TestCase): def setUp(self): self.test_case_data = [{'expected_output': '11', 'expected_input': '5\n6'}] @@ -181,16 +181,7 @@ class CStdioEvaluationTestCases(unittest.TestCase): self.assertEquals(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) - -class CppStdioEvaluationTestCases(unittest.TestCase): - - def setUp(self): - self.test_case_data = [{'expected_output': '11', 'expected_input': '5\n6'}] - self.timeout_msg = ("Code took more than {0} seconds to run. " - "You probably have an infinite loop in" - " your code.").format(SERVER_TIMEOUT) - - def test_correct_answer(self): + def test_cpp_correct_answer(self): user_answer = dedent(""" #include using namespace std; @@ -207,9 +198,9 @@ class CppStdioEvaluationTestCases(unittest.TestCase): self.assertEquals(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) - def test_array_input(self): + def test_cpp_array_input(self): self.test_case_data = [{'expected_output': '561', - 'expected_input': '5,6,1'}] + 'expected_input': '5\n6\n1'}] user_answer = dedent(""" #include using namespace std; @@ -228,7 +219,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): self.assertEquals(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) - def test_string_input(self): + def test_cpp_string_input(self): self.test_case_data = [{'expected_output': 'abc', 'expected_input': 'abc'}] user_answer = dedent(""" @@ -247,7 +238,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): self.assertEquals(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) - def test_incorrect_answer(self): + def test_cpp_incorrect_answer(self): user_answer = dedent(""" #include using namespace std; @@ -264,7 +255,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): self.assertIn("Incorrect", result.get('error')) self.assertTrue(result.get('error').splitlines > 1) - def test_error(self): + def test_cpp_error(self): user_answer = dedent(""" #include using namespace std; @@ -280,7 +271,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): self.assertFalse(result.get("success")) self.assertTrue("Compilation Error" in result.get("error")) - def test_infinite_loop(self): + def test_cpp_infinite_loop(self): user_answer = dedent(""" #include using namespace std; @@ -296,7 +287,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): self.assertFalse(result.get("success")) self.assertEquals(result.get("error"), self.timeout_msg) - def test_only_stdout(self): + def test_cpp_only_stdout(self): self.test_case_data = [{'expected_output': '11', 'expected_input': ''}] user_answer = dedent(""" -- cgit From 9411ab221e007a6c3e2901ce34f38f2267288b6e Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 28 Jul 2016 00:12:51 +0530 Subject: rebase changes and changed expected input format in cpp tests --- yaksh/evaluator_tests/test_c_cpp_evaluation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh/evaluator_tests') diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py index a2fc51f..ff3cddf 100644 --- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py +++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py @@ -82,7 +82,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): def test_array_input(self): self.test_case_data = [{'expected_output': '561', - 'expected_input': '5,6,1'}] + 'expected_input': '5\n6\n1'}] user_answer = dedent(""" #include int main(void){ -- cgit From 1b71abc9437d721a41f017db406f312755f5a4c4 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Thu, 28 Jul 2016 18:24:18 +0530 Subject: added expected input in traceback for python and made minor changes in bash_stio_evaluator and stdio_evaluator --- yaksh/evaluator_tests/test_bash_evaluation.py | 4 ++-- yaksh/evaluator_tests/test_python_evaluation.py | 14 -------------- 2 files changed, 2 insertions(+), 16 deletions(-) (limited to 'yaksh/evaluator_tests') diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py index f954ef0..ee6c1f0 100644 --- a/yaksh/evaluator_tests/test_bash_evaluation.py +++ b/yaksh/evaluator_tests/test_bash_evaluation.py @@ -97,10 +97,10 @@ class BashStdioEvaluationTestCases(unittest.TestCase): user_answer = dedent(""" #!/bin/bash read A read B - echo -n `expr $A + $B` + echo -n `expr $A - $B` """ ) - test_case_data = [{'expected_output': '12', 'expected_input': '5\n6'}] + test_case_data = [{'expected_output': '11', 'expected_input': '5\n6'}] get_class = BashStdioEvaluator() kwargs = {"user_answer": user_answer, "test_case_data": test_case_data diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py index a935f1d..40562db 100644 --- a/yaksh/evaluator_tests/test_python_evaluation.py +++ b/yaksh/evaluator_tests/test_python_evaluation.py @@ -211,20 +211,6 @@ class PythonStdoutEvaluationTestCases(unittest.TestCase): self.assertFalse(result.get('success')) self.assertIn("Incorrect Answer", result.get('error')) - def test_direct_printed_answer(self): - user_answer = "print '0 1 1 2 3'" - error_msg = ("Incorrect Answer: Please avoid printing" - " the expected output directly" - ) - get_class = PythonStdioEvaluator() - - kwargs = {'user_answer': user_answer, - 'test_case_data': self.test_case_data - } - result = get_class.evaluate(**kwargs) - self.assertFalse(result.get('success')) - self.assertEqual(result.get('error'), error_msg) - def test_infinite_loop(self): user_answer = "def add(a, b):\n\twhile True:\n\t\tpass\nadd(1,2)" get_class = PythonStdioEvaluator() -- cgit From a4b636508d572cbe00ae8d0336c7b30494bad4a6 Mon Sep 17 00:00:00 2001 From: adityacp Date: Wed, 31 Aug 2016 18:10:57 +0530 Subject: change in incorrect answer stdio testcase --- yaksh/evaluator_tests/test_python_evaluation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh/evaluator_tests') diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py index eea9403..e46b21f 100644 --- a/yaksh/evaluator_tests/test_python_evaluation.py +++ b/yaksh/evaluator_tests/test_python_evaluation.py @@ -318,12 +318,12 @@ class PythonStdIOEvaluator(unittest.TestCase): def test_add_two_integers_incorrect(self): self.test_case_data = [{"expected_input": "1\n2", - "expected_output": "4" + "expected_output": "3" }] user_answer = dedent(""" a = int(raw_input()) b = int(raw_input()) - print a+b + print a-b """ ) -- cgit