diff options
Diffstat (limited to 'testapp/test_server.py')
-rw-r--r-- | testapp/test_server.py | 114 |
1 files changed, 103 insertions, 11 deletions
diff --git a/testapp/test_server.py b/testapp/test_server.py index 5c88d73..2a17739 100644 --- a/testapp/test_server.py +++ b/testapp/test_server.py @@ -44,14 +44,16 @@ def test_c(): int ad(int a, int b) {return a+b;} """ - result = code_server.run_code(src, 'c_cpp_files/main.cpp', '/tmp', language="C") + result = code_server.run_code(src, 'c_cpp_files/main.cpp', + '/tmp', language="C") check_result(result, 'error') src = """ int add(int a, int b) {return a+b} """ - result = code_server.run_code(src, 'c_cpp_files/main.cpp', '/tmp', language="C") + result = code_server.run_code(src, 'c_cpp_files/main.cpp', + '/tmp', language="C") check_result(result, 'compilation error') src = """ @@ -59,14 +61,16 @@ def test_c(): {while(1>0){} return a+b;} """ - result = code_server.run_code(src, 'c_cpp_files/main.cpp', '/tmp', language="C") + result = code_server.run_code(src, 'c_cpp_files/main.cpp', + '/tmp', language="C") check_result(result, 'more than') src = """ int add(int a, int b) {return a+b;} """ - result = code_server.run_code(src, 'c_cpp_files/main.cpp', '/tmp', language="C") + result = code_server.run_code(src, 'c_cpp_files/main.cpp', + '/tmp', language="C") check_result(result, 'correct answer') src = """ @@ -74,7 +78,8 @@ def test_c(): int add(int a, int b) {printf("All Correct");} """ - result = code_server.run_code(src, 'c_cpp_files/main.cpp', '/tmp', language="C") + result = code_server.run_code(src, 'c_cpp_files/main.cpp', + '/tmp', language="C") check_result(result, 'incorrect') @@ -86,8 +91,9 @@ def test_cpp(): return a+b } """ - result = code_server.run_code(src, 'c_cpp_files/main.cpp', '/tmp', language="C++") - check_result(result, 'compilation error') + result = code_server.run_code(src, 'c_cpp_files/main.cpp', + '/tmp', language="C++") + check_result(result, 'error') src = """ int add(int a, int b) @@ -95,7 +101,8 @@ def test_cpp(): return a+b; } """ - result = code_server.run_code(src, 'c_cpp_files/main.cpp', '/tmp', language="C++") + result = code_server.run_code(src, 'c_cpp_files/main.cpp', + '/tmp', language="C++") check_result(result, 'correct answer') src = """ @@ -104,7 +111,8 @@ def test_cpp(): return a+b; } """ - result = code_server.run_code(src, 'c_cpp_files/main.cpp', '/tmp', language="C++") + result = code_server.run_code(src, 'c_cpp_files/main.cpp', + '/tmp', language="C++") check_result(result, 'error') src = """ @@ -115,9 +123,92 @@ def test_cpp(): return a+b; } """ - result = code_server.run_code(src, 'c_cpp_files/main.cpp', '/tmp', language="C++") + result = code_server.run_code(src, 'c_cpp_files/main.cpp', + '/tmp', language="C++") + check_result(result, 'more than') + + +def test_java(): + """Test if server runs java code as expected.""" + src = """ + class Test + { + int square_num(int a) + { + return a*a; + } + } + """ + result = code_server.run_code(src, 'java_files/main_square.java', + '/tmp', language="java") + check_result(result, 'correct answer') + + src = """ + class Test + { + int square_num(int a) + { + return b*b; + } + } + """ + result = code_server.run_code(src, 'java_files/main_square.java', + '/tmp', language="java") + check_result(result, 'error') + + src = """ + class Test + { + int square_nu(int a) + { + return a*a; + } + } + """ + result = code_server.run_code(src, 'java_files/main_square.java', + '/tmp', language="java") + check_result(result, 'error') + + src = """ + class Test + { + int square_num(int a) + { + while(0==0) + {} + } + } + """ + result = code_server.run_code(src, 'java_files/main_square.java', + '/tmp', language="java") check_result(result, 'more than') + src = """ + class Test + { + int square_num(int a) + { + return a+b + } + } + """ + result = code_server.run_code(src, 'java_files/main_square.java', + '/tmp', language="java") + check_result(result, 'error') + + src = """ + class Test + { + int square_num(int a) + { + return a+b + + """ + result = code_server.run_code(src, 'java_files/main_square.java', + '/tmp', language="java") + check_result(result, 'error') + + def test_bash(): """Test if server runs Bash code as expected.""" src = """ @@ -133,7 +224,7 @@ def test_bash(): [[ $# -eq 2 ]] && echo $(( $1 - $2 )) && exit $(( $1 - $2 )) """ result = code_server.run_code(src, - 'docs/sample.sh\ndocs/sample.args', '/tmp', language="bash") + 'docs/sample.sh\ndocs/sample.args', '/tmp', language="bash") check_result(result, 'error') src = """\ @@ -165,3 +256,4 @@ if __name__ == '__main__': test_bash() test_c() test_cpp() + test_java() |