diff options
Diffstat (limited to 'testapp/test_server.py')
-rw-r--r-- | testapp/test_server.py | 115 |
1 files changed, 104 insertions, 11 deletions
diff --git a/testapp/test_server.py b/testapp/test_server.py index 924a6c5..2a17739 100644 --- a/testapp/test_server.py +++ b/testapp/test_server.py @@ -16,6 +16,7 @@ def check_result(result, check='correct answer'): assert result[0], result[1] assert check in result[1].lower(), result[1] + def test_python(): """Test if server runs Python code as expected.""" src = 'while True: pass' @@ -43,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 = """ @@ -58,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 = """ @@ -73,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') @@ -85,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) @@ -94,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 = """ @@ -103,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 = """ @@ -114,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 = """ @@ -132,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 = """\ @@ -164,3 +256,4 @@ if __name__ == '__main__': test_bash() test_c() test_cpp() + test_java() |