Skip to content

Commit 4771bb3

Browse files
committed
write more tests
1 parent 7080596 commit 4771bb3

9 files changed

Lines changed: 64 additions & 7 deletions

File tree

judge.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ def readStandardInput(output_file):
4545

4646
def readStatus(token):
4747
while True:
48-
res = requests.get("https://api.judge0.com/submissions/" + token['token'])
49-
response = res.json()
48+
req = requests.get("https://api.judge0.com/submissions/" + token['token'])
49+
response = req.json()
5050
status = response['status']['description']
5151
if status != "Processing" and status != "In Queue":
5252
break
53-
print(f'{status} ...')
53+
print(status)
5454

55-
if response['status']['description'] == "Accepted":
55+
if status == "Accepted":
5656
print(f'Output : \n{response["stdout"]}')
5757
print("Compile Success ✅")
58-
return response['status']['description']
58+
return status
5959
else:
6060
return response
6161

testfiles/input2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12 33

testfiles/input3.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
121

testfiles/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
1 4 9 16
22
25 36 49
33
64 81
4-
100
4+
100

testfiles/output3.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sum of the numbers = 45

testfiles/output4.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The reverse of the number is: 121
2+
The number is a palindrome.

testfiles/test_c++.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <iostream>
2+
using namespace std;
3+
int main(){
4+
int n, num, digit, rev = 0;
5+
cin >> num;
6+
n = num;
7+
do
8+
{
9+
digit = num % 10;
10+
rev = (rev * 10) + digit;
11+
num = num / 10;
12+
} while (num != 0);
13+
cout << "The reverse of the number is: " << rev << endl;
14+
if (n == rev)
15+
cout << "The number is a palindrome.";
16+
else
17+
cout << "The number is not a palindrome.";
18+
return 0;
19+
}

testfiles/test_c.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include<stdio.h>
2+
3+
int main(){
4+
int a, b, c;
5+
6+
scanf("%d%d", &a, &b);
7+
8+
c = a + b;
9+
10+
printf("Sum of the numbers = %d\n", c);
11+
12+
return 0;
13+
}

tests.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
from judge import run
33

4+
#test for Java program
45
class TestRunA(unittest.TestCase):
56
def test_run(self):
67
program_name = "testfiles/" + "test_java.java"
@@ -9,7 +10,7 @@ def test_run(self):
910
self.assertEqual(run(program_name, language, output),
1011
"Accepted", "Something Wrong")
1112

12-
13+
#test for Python program
1314
class TestRunB(unittest.TestCase):
1415
def test_run(self):
1516
program_name = "testfiles/" + "test_python.py"
@@ -18,6 +19,25 @@ def test_run(self):
1819
Input = "testfiles/" + "input.txt"
1920
self.assertEqual(run(program_name, language, output, Input),
2021
"Accepted", "Something Wrong")
22+
#test for C program
23+
class TestRunC(unittest.TestCase):
24+
def test_run(self):
25+
program_name = "testfiles/" + "test_c.c"
26+
language = "C"
27+
output = "testfiles/" + "output3.txt"
28+
Input = "testfiles/" + "input2.txt"
29+
self.assertEqual(run(program_name, language, output, Input),
30+
"Accepted", "Something Wrong")
31+
32+
#test for C++ program
33+
class TestRunD(unittest.TestCase):
34+
def test_run(self):
35+
program_name = "testfiles/" + "test_c++.cpp"
36+
language = "C++"
37+
output = "testfiles/" + "output4.txt"
38+
Input = "testfiles/" + "input3.txt"
39+
self.assertEqual(run(program_name, language, output, Input),
40+
"Accepted", "Something Wrong")
2141

2242

2343
if __name__ == '__main__':

0 commit comments

Comments
 (0)