diff options
author | adityacp | 2017-01-04 11:42:32 +0530 |
---|---|---|
committer | adityacp | 2017-01-04 11:42:32 +0530 |
commit | 58481cdcba38e8e602b8e2d3e5172f9e653f93a9 (patch) | |
tree | 21312113c078b6b22f24d5bab052a52bd185a3c9 /yaksh/evaluator_tests | |
parent | b271e3b33f673c70114893bf461d2a6116dd7cf7 (diff) | |
parent | ef6a61b1938ec399efb6d66b914f245afa3ed5ff (diff) | |
download | online_test-58481cdcba38e8e602b8e2d3e5172f9e653f93a9.tar.gz online_test-58481cdcba38e8e602b8e2d3e5172f9e653f93a9.tar.bz2 online_test-58481cdcba38e8e602b8e2d3e5172f9e653f93a9.zip |
Merge https://github.com/fossee/online_test into fix_management_commands
Diffstat (limited to 'yaksh/evaluator_tests')
-rw-r--r-- | yaksh/evaluator_tests/test_bash_evaluation.py | 49 | ||||
-rw-r--r-- | yaksh/evaluator_tests/test_c_cpp_evaluation.py | 133 | ||||
-rw-r--r-- | yaksh/evaluator_tests/test_java_evaluation.py | 120 | ||||
-rw-r--r-- | yaksh/evaluator_tests/test_scilab_evaluation.py | 35 |
4 files changed, 317 insertions, 20 deletions
diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py index abadf26..4b551d7 100644 --- a/yaksh/evaluator_tests/test_bash_evaluation.py +++ b/yaksh/evaluator_tests/test_bash_evaluation.py @@ -13,10 +13,17 @@ from textwrap import dedent class BashAssertionEvaluationTestCases(EvaluatorBaseTest): def setUp(self): - with open('/tmp/test.txt', 'wb') as f: + self.f_path = os.path.join(tempfile.gettempdir(), "test.txt") + with open(self.f_path, 'wb') as f: f.write('2'.encode('ascii')) + self.tc_data = dedent(""" + #!/bin/bash + [[ $# -eq 2 ]] && echo $(( $1 + $2 )) && exit $(( $1 + $2 )) + """) + self.tc_data_args = "1 2\n2 1" self.test_case_data = [ - {"test_case": "bash_files/sample.sh,bash_files/sample.args", + {"test_case": self.tc_data, + "test_case_args": self.tc_data_args, "test_case_type": "standardtestcase", "weight": 0.0 } @@ -28,10 +35,11 @@ class BashAssertionEvaluationTestCases(EvaluatorBaseTest): self.file_paths = None def tearDown(self): - os.remove('/tmp/test.txt') + os.remove(self.f_path) shutil.rmtree(self.in_dir) def test_correct_answer(self): + # Given user_answer = ("#!/bin/bash\n[[ $# -eq 2 ]]" " && echo $(( $1 + $2 )) && exit $(( $1 + $2 ))" ) @@ -45,12 +53,15 @@ class BashAssertionEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_error(self): + # Given user_answer = ("#!/bin/bash\n[[ $# -eq 2 ]] " "&& echo $(( $1 - $2 )) && exit $(( $1 - $2 ))") kwargs = { @@ -63,13 +74,16 @@ class BashAssertionEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertFalse(result.get("success")) self.assert_correct_output("Error", result.get("error")) def test_infinite_loop(self): + # Given user_answer = ("#!/bin/bash\nwhile [ 1 ] ;" " do echo "" > /dev/null ; done") kwargs = { @@ -82,16 +96,25 @@ class BashAssertionEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) def test_file_based_assert(self): - self.file_paths = [('/tmp/test.txt', False)] + # Given + self.file_paths = [(self.f_path, False)] + self.tc_data = dedent(""" + #!/bin/bash + cat $1 + """) + self.tc_data_args = "test.txt" self.test_case_data = [ - {"test_case": "bash_files/sample1.sh,bash_files/sample1.args", + {"test_case": self.tc_data, + "test_case_args": self.tc_data_args, "test_case_type": "standardtestcase", "weight": 0.0 } @@ -107,9 +130,11 @@ class BashAssertionEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get("success")) class BashStdIOEvaluationTestCases(EvaluatorBaseTest): @@ -122,6 +147,7 @@ class BashStdIOEvaluationTestCases(EvaluatorBaseTest): def test_correct_answer(self): + # Given user_answer = dedent(""" #!/bin/bash read A read B @@ -143,12 +169,15 @@ class BashStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_array_input(self): + # Given user_answer = dedent(""" readarray arr; COUNTER=0 while [ $COUNTER -lt 3 ]; do @@ -172,12 +201,15 @@ class BashStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_incorrect_answer(self): + # Given user_answer = dedent(""" #!/bin/bash read A read B @@ -199,12 +231,16 @@ class BashStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + + # Then self.assert_correct_output("Incorrect", result.get('error')) self.assertFalse(result.get('success')) def test_stdout_only(self): + # Given user_answer = dedent(""" #!/bin/bash A=6 B=4 @@ -226,8 +262,11 @@ class BashStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + + # Then self.assertTrue(result.get('success')) if __name__ == '__main__': diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py index ec59a6b..d734cf2 100644 --- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py +++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py @@ -15,10 +15,45 @@ from yaksh.settings import SERVER_TIMEOUT class CAssertionEvaluationTestCases(EvaluatorBaseTest): def setUp(self): - with open('/tmp/test.txt', 'wb') as f: + self.f_path = os.path.join(tempfile.gettempdir(), "test.txt") + with open(self.f_path, 'wb') as f: f.write('2'.encode('ascii')) tmp_in_dir_path = tempfile.mkdtemp() - self.test_case_data = [{"test_case": "c_cpp_files/main.cpp", + self.tc_data = dedent(""" + #include <stdio.h> + #include <stdlib.h> + + extern int add(int, int); + + template <class T> + + void check(T expect, T result) + { + if (expect == result) + { + printf("Correct: Expected %d got %d ",expect,result); + } + else + { + printf("Incorrect: Expected %d got %d ",expect,result); + exit (1); + } + } + + int main(void) + { + int result; + result = add(0,0); + printf("Input submitted to the function: 0, 0"); + check(0, result); + result = add(2,3); + printf("Input submitted to the function: 2 3"); + check(5,result); + printf("All Correct"); + return 0; + } + """) + self.test_case_data = [{"test_case": self.tc_data, "test_case_type": "standardtestcase", "weight": 0.0 }] @@ -29,10 +64,11 @@ class CAssertionEvaluationTestCases(EvaluatorBaseTest): self.file_paths = None def tearDown(self): - os.remove('/tmp/test.txt') + os.remove(self.f_path) shutil.rmtree(self.in_dir) def test_correct_answer(self): + # Given user_answer = "int add(int a, int b)\n{return a+b;}" kwargs = { 'metadata': { @@ -44,12 +80,15 @@ class CAssertionEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_incorrect_answer(self): + # Given user_answer = "int add(int a, int b)\n{return a-b;}" kwargs = { 'metadata': { @@ -61,15 +100,18 @@ class CAssertionEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then lines_of_error = len(result.get('error')[0].splitlines()) self.assertFalse(result.get('success')) self.assert_correct_output("Incorrect:", result.get('error')) self.assertTrue(lines_of_error > 1) def test_compilation_error(self): + # Given user_answer = "int add(int a, int b)\n{return a+b}" kwargs = { 'metadata': { @@ -81,13 +123,16 @@ class CAssertionEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertFalse(result.get("success")) self.assert_correct_output("Compilation Error", result.get("error")) def test_infinite_loop(self): + # Given user_answer = "int add(int a, int b)\n{while(1>0){}}" kwargs = { 'metadata': { @@ -99,15 +144,45 @@ class CAssertionEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) def test_file_based_assert(self): - self.file_paths = [('/tmp/test.txt', False)] - self.test_case_data = [{"test_case": "c_cpp_files/file_data.c", + # Given + self.file_paths = [(self.f_path, False)] + self.tc_data = dedent(""" + #include <stdio.h> + #include <stdlib.h> + + extern int ans(); + + template <class T> + void check(T expect,T result) + { + if (expect == result) + { + printf("Correct: Expected %d got %d ",expect,result); + } + else + { + printf("Incorrect: Expected %d got %d ",expect,result); + exit (0); + } + } + + int main(void) + { + int result; + result = ans(); + check(50, result); + } + """) + self.test_case_data = [{"test_case": self.tc_data, "test_case_type": "standardtestcase", "weight": 0.0 }] @@ -133,11 +208,14 @@ class CAssertionEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) + class CppStdIOEvaluationTestCases(EvaluatorBaseTest): def setUp(self): self.test_case_data = [{'expected_output': '11', @@ -151,7 +229,11 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): " your code.").format(SERVER_TIMEOUT) self.file_paths = None + def tearDown(self): + shutil.rmtree(self.in_dir) + def test_correct_answer(self): + # Given user_answer = dedent(""" #include<stdio.h> int main(void){ @@ -169,12 +251,15 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_array_input(self): + # Given self.test_case_data = [{'expected_output': '561', 'expected_input': '5\n6\n1', 'weight': 0.0, @@ -199,12 +284,15 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_string_input(self): + # Given self.test_case_data = [{'expected_output': 'abc', 'expected_input': 'abc', 'weight': 0.0, @@ -227,12 +315,15 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_incorrect_answer(self): + # Given user_answer = dedent(""" #include<stdio.h> int main(void){ @@ -249,15 +340,18 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then lines_of_error = len(result.get('error')[0].splitlines()) self.assertFalse(result.get('success')) self.assert_correct_output("Incorrect", result.get('error')) self.assertTrue(lines_of_error > 1) def test_error(self): + # Given user_answer = dedent(""" #include<stdio.h> int main(void){ @@ -274,13 +368,16 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertFalse(result.get("success")) self.assert_correct_output("Compilation Error", result.get("error")) def test_infinite_loop(self): + # Given user_answer = dedent(""" #include<stdio.h> int main(void){ @@ -297,13 +394,16 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) def test_only_stdout(self): + # Given self.test_case_data = [{'expected_output': '11', 'expected_input': '', 'weight': 0.0, @@ -325,12 +425,15 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_cpp_correct_answer(self): + # Given user_answer = dedent(""" #include<iostream> using namespace std; @@ -349,12 +452,15 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_cpp_array_input(self): + # Given self.test_case_data = [{'expected_output': '561', 'expected_input': '5\n6\n1', 'weight': 0.0, @@ -380,12 +486,15 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_cpp_string_input(self): + # Given self.test_case_data = [{'expected_output': 'abc', 'expected_input': 'abc', 'weight': 0.0, @@ -409,12 +518,15 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_cpp_incorrect_answer(self): + # Given user_answer = dedent(""" #include<iostream> using namespace std; @@ -432,15 +544,18 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then lines_of_error = len(result.get('error')[0].splitlines()) self.assertFalse(result.get('success')) self.assert_correct_output("Incorrect", result.get('error')) self.assertTrue(lines_of_error > 1) def test_cpp_error(self): + # Given user_answer = dedent(""" #include<iostream> using namespace std; @@ -458,13 +573,16 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertFalse(result.get("success")) self.assert_correct_output("Compilation Error", result.get("error")) def test_cpp_infinite_loop(self): + # Given user_answer = dedent(""" #include<iostream> using namespace std; @@ -482,13 +600,16 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) def test_cpp_only_stdout(self): + # Given self.test_case_data = [{'expected_output': '11', 'expected_input': '', 'weight': 0.0, @@ -511,9 +632,11 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) if __name__ == '__main__': diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py index bfba38f..b53d8aa 100644 --- a/yaksh/evaluator_tests/test_java_evaluation.py +++ b/yaksh/evaluator_tests/test_java_evaluation.py @@ -15,11 +15,47 @@ from yaksh.evaluator_tests.test_python_evaluation import EvaluatorBaseTest class JavaAssertionEvaluationTestCases(EvaluatorBaseTest): def setUp(self): - with open('/tmp/test.txt', 'wb') as f: + self.f_path = os.path.join(tempfile.gettempdir(), "test.txt") + with open(self.f_path, 'wb') as f: f.write('2'.encode('ascii')) tmp_in_dir_path = tempfile.mkdtemp() + self.tc_data = dedent(""" + class main + { + public static <E> void check(E expect, E result) + { + if(result.equals(expect)) + { + System.out.println("Correct:Output expected "+expect+" and got "+result); + } + else + { + System.out.println("Incorrect:Output expected "+expect+" but got "+result); + System.exit(1); + } + } + public static void main(String arg[]) + { + Test t = new Test(); + int result, input, output; + input = 0; output = 0; + result = t.square_num(input); + System.out.println("Input submitted to the function: "+input); + check(output, result); + input = 5; output = 25; + result = t.square_num(input); + System.out.println("Input submitted to the function: "+input); + check(output, result); + input = 6; output = 36; + result = t.square_num(input); + System.out.println("Input submitted to the function: "+input); + check(output, result); + } + } + """) + self.test_case_data = [ - {"test_case": "java_files/main_square.java", + {"test_case": self.tc_data, "test_case_type": "standardtestcase", "weight": 0.0 } @@ -34,10 +70,11 @@ class JavaAssertionEvaluationTestCases(EvaluatorBaseTest): def tearDown(self): gd.SERVER_TIMEOUT = 4 - os.remove('/tmp/test.txt') + os.remove(self.f_path) shutil.rmtree(self.in_dir) def test_correct_answer(self): + # Given user_answer = "class Test {\n\tint square_num(int a) {\n\treturn a*a;\n\t}\n}" kwargs = { 'metadata': { @@ -49,12 +86,15 @@ class JavaAssertionEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_incorrect_answer(self): + # Given user_answer = "class Test {\n\tint square_num(int a) {\n\treturn a;\n\t}\n}" kwargs = { 'metadata': { @@ -66,9 +106,11 @@ class JavaAssertionEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertFalse(result.get('success')) lines_of_error = len(result.get('error')[0].splitlines()) self.assertFalse(result.get('success')) @@ -76,6 +118,7 @@ class JavaAssertionEvaluationTestCases(EvaluatorBaseTest): self.assertTrue(lines_of_error > 1) def test_error(self): + # Given user_answer = "class Test {\n\tint square_num(int a) {\n\treturn a*a" kwargs = { 'metadata': { @@ -87,13 +130,16 @@ class JavaAssertionEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertFalse(result.get("success")) self.assert_correct_output("Error", result.get("error")) def test_infinite_loop(self): + # Given user_answer = "class Test {\n\tint square_num(int a) {\n\t\twhile(0==0){\n\t\t}\n\t}\n}" kwargs = { 'metadata': { @@ -105,16 +151,47 @@ class JavaAssertionEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) def test_file_based_assert(self): - self.file_paths = [("/tmp/test.txt", False)] + # Given + self.file_paths = [(self.f_path, False)] + self.tc_data = dedent(""" + class main + { + public static <E> void check(E expect, E result) + { + if(result.equals(expect)) + { + System.out.println("Correct:Output expected "+expect+" and got "+result); + } + else + { + System.out.println("Incorrect:Output expected "+expect+" but got "+result); + System.exit(1); + } + } + public static void main(String arg[]) + { + String result = ""; + Test t = new Test(); + try{ + result = t.readFile();} + catch(Exception e){ + System.out.print(e); + } + check("2", result); + } + } + """) self.test_case_data = [ - {"test_case": "java_files/read_file.java", + {"test_case": self.tc_data, "test_case_type": "standardtestcase", "weight": 0.0 } @@ -147,14 +224,17 @@ class JavaAssertionEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get("success")) class JavaStdIOEvaluationTestCases(EvaluatorBaseTest): def setUp(self): - with open('/tmp/test.txt', 'wb') as f: + self.f_path = os.path.join(tempfile.gettempdir(), "test.txt") + with open(self.f_path, 'wb') as f: f.write('2'.encode('ascii')) tmp_in_dir_path = tempfile.mkdtemp() self.in_dir = tmp_in_dir_path @@ -171,10 +251,11 @@ class JavaStdIOEvaluationTestCases(EvaluatorBaseTest): def tearDown(self): gd.SERVER_TIMEOUT = 4 - os.remove('/tmp/test.txt') + os.remove(self.f_path) shutil.rmtree(self.in_dir) def test_correct_answer(self): + # Given user_answer = dedent(""" import java.util.Scanner; class Test @@ -194,12 +275,15 @@ class JavaStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_array_input(self): + # Given self.test_case_data = [{'expected_output': '561', 'expected_input': '5\n6\n1', 'test_case_type': 'stdiobasedtestcase', @@ -225,12 +309,15 @@ class JavaStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_incorrect_answer(self): + # Given user_answer = dedent(""" import java.util.Scanner; class Test @@ -250,15 +337,18 @@ class JavaStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then lines_of_error = len(result.get('error')[0].splitlines()) self.assertFalse(result.get('success')) self.assert_correct_output("Incorrect", result.get('error')) self.assertTrue(lines_of_error > 1) def test_error(self): + # Given user_answer = dedent(""" class Test { @@ -274,13 +364,16 @@ class JavaStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertFalse(result.get("success")) self.assertTrue("Compilation Error" in '\n'.join(result.get("error"))) def test_infinite_loop(self): + # Given user_answer = dedent(""" class Test {public static void main(String[] args){ @@ -298,13 +391,16 @@ class JavaStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) def test_only_stdout(self): + # Given self.test_case_data = [{'expected_output': '11', 'expected_input': '', 'test_case_type': 'stdiobasedtestcase', @@ -327,12 +423,15 @@ class JavaStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_string_input(self): + # Given self.test_case_data = [{'expected_output': 'HelloWorld', 'expected_input': 'Hello\nWorld', 'test_case_type': 'stdiobasedtestcase', @@ -357,13 +456,16 @@ class JavaStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get('success')) def test_file_based_stdout(self): - self.file_paths = [("/tmp/test.txt", False)] + # Given + self.file_paths = [(self.f_path, False)] self.test_case_data = [{'expected_output': '2', 'expected_input': '', 'test_case_type': 'stdiobasedtestcase', @@ -397,9 +499,11 @@ class JavaStdIOEvaluationTestCases(EvaluatorBaseTest): 'test_case_data': self.test_case_data, } + # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) + # Then self.assertTrue(result.get("success")) diff --git a/yaksh/evaluator_tests/test_scilab_evaluation.py b/yaksh/evaluator_tests/test_scilab_evaluation.py index 938d0e5..5a452a3 100644 --- a/yaksh/evaluator_tests/test_scilab_evaluation.py +++ b/yaksh/evaluator_tests/test_scilab_evaluation.py @@ -3,7 +3,7 @@ import unittest import os import shutil import tempfile - +from textwrap import dedent from yaksh import grader as gd from yaksh.grader import Grader from yaksh.scilab_code_evaluator import ScilabCodeEvaluator @@ -13,7 +13,38 @@ from yaksh.evaluator_tests.test_python_evaluation import EvaluatorBaseTest class ScilabEvaluationTestCases(EvaluatorBaseTest): def setUp(self): tmp_in_dir_path = tempfile.mkdtemp() - self.test_case_data = [{"test_case": "scilab_files/test_add.sce", + self.tc_data = dedent(""" + mode(-1) + exec("function.sci",-1); + i = 0 + p = add(3,5); + correct = (p == 8); + if correct then + i=i+1 + end + disp("Input submitted 3 and 5") + disp("Expected output 8 got " + string(p)) + p = add(22,-20); + correct = (p==2); + if correct then + i=i+1 + end + disp("Input submitted 22 and -20") + disp("Expected output 2 got " + string(p)) + p =add(91,0); + correct = (p==91); + if correct then + i=i+1 + end + disp("Input submitted 91 and 0") + disp("Expected output 91 got " + string(p)) + if i==3 then + exit(5); + else + exit(3); + end + """) + self.test_case_data = [{"test_case": self.tc_data, "test_case_type": "standardtestcase", "weight": 0.0 }] |