-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstress_testing.py
74 lines (57 loc) · 2.46 KB
/
stress_testing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from helpers import Colors
from utils import cpp_compiler
from utils import file_handler
def stress_testing():
test_cases = int(
input(f"{Colors.fg.gold}Enter the number of test cases: {Colors.reset}")
)
time_limit = float(
input(
f"{Colors.fg.gold}Enter the time limit for each test case (seconds): {Colors.reset}"
)
)
print(f"{Colors.fg.white}\n=========================={Colors.reset}\n")
list_of_files = ["generator", "correct", "test"]
list_of_input_files = ["", "input.txt", "input.txt"]
list_of_output_files = ["input.txt", "correct_output.txt", "test_output.txt"]
for file in list_of_files:
try:
cpp_compiler.compile_file(file_name=file)
except ValueError as e:
print(f"\n{Colors.fg.red}{e}{Colors.reset}")
return
for test in range(1, test_cases + 1):
for index in range(len(list_of_files)):
try:
cpp_compiler.validate_errors(
list_of_files[index],
list_of_input_files[index],
list_of_output_files[index],
test,
time_limit,
)
except Exception as e:
print(f"\n{Colors.fg.red}{e}{Colors.reset}")
return
if cpp_compiler.check_diff("correct_output.txt", "test_output.txt"):
print(
f"{Colors.fg.white}Test case {test} {Colors.fg.green}passed! ✅{Colors.reset}"
)
else:
print(
f"{Colors.fg.red}Wrong Answer {Colors.fg.white}on test case {test} ❌{Colors.reset}"
)
print(f"{Colors.fg.white}\n=========================={Colors.reset}\n")
print(f"{Colors.fg.purple}Input: {Colors.reset}")
cpp_compiler.print_output("input.txt")
print(f"{Colors.fg.purple}Expected Output: {Colors.reset}")
cpp_compiler.print_output("correct_output.txt")
print(f"{Colors.fg.purple}Your Output: {Colors.reset}")
cpp_compiler.print_output("test_output.txt")
print(f"{Colors.fg.white}=========================={Colors.reset}\n")
return
print(f"{Colors.fg.white}==========================\n{Colors.reset}")
print(f"\n{Colors.fg.pink}All test cases {Colors.fg.green}passed! ✅{Colors.reset}")
if __name__ == "__main__":
stress_testing()
file_handler.clean_up()