diff options
author | Prabhu Ramachandran | 2013-07-29 23:58:29 -0700 |
---|---|---|
committer | Prabhu Ramachandran | 2013-07-29 23:58:29 -0700 |
commit | 70b73660f9c10174e318d570a820ca0cc01f8d5f (patch) | |
tree | 26df2b155c4db789dabd53f309057ac0aaca5f04 /testapp/test_server.py | |
parent | ee64cfe58c42540d0736cc32d3acd36ab7a6d31d (diff) | |
parent | b522a1ba1c1edff7648c6c7d69fa2867a08b4100 (diff) | |
download | online_test-70b73660f9c10174e318d570a820ca0cc01f8d5f.tar.gz online_test-70b73660f9c10174e318d570a820ca0cc01f8d5f.tar.bz2 online_test-70b73660f9c10174e318d570a820ca0cc01f8d5f.zip |
Merge pull request #14 from prathamesh920/fresh_java
fresh java
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() |