-
Notifications
You must be signed in to change notification settings - Fork 312
/
stress_tester.py
79 lines (61 loc) · 1.53 KB
/
stress_tester.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
75
76
77
78
79
import subprocess
def cmd2func(args):
def func(inp):
proc = subprocess.run(args, input=inp, text=True, capture_output=True)
return proc.stdout, proc.stderr
return func
def func2judge(sol):
def func(inp, out):
ans, _ = sol(inp)
return ans == out, ans
return func
def stress_tester(tests, solution, judge=None, catch_all=False):
if judge is None:
verdict, answer = False, ""
catch_all = True
for inp in tests:
out, err = solution(inp)
if judge:
verdict, answer = judge(inp, out)
if not verdict:
print("Input")
print(inp)
print("Output")
print(out)
if err:
print("Error")
print(err)
if answer:
print("Answer")
print(answer)
print("-" * 80)
if not catch_all:
break
# import os
# import sys
# import time
# import traceback
#
# def test_gen():
# for i in range(10):
# yield str(i) + "\n"
#
# def judge(inp, out):
# return out, ""
#
# tests = test_gen()
# solution = cmd2func(["python", "A.py"])
# # judge = func2judge(cmd2func(["python", "judge.py"]))
#
# try:
# stress_tester(tests, solution)
# except (KeyboardInterrupt, SystemExit):
# exit(0)
# except:
# print("Unexpected error: ", sys.exc_info()[:2])
# traceback.print_exc()
#
# time.sleep(1)
# args = sys.argv[:]
# args.insert(0, sys.executable)
# os.execv(sys.executable, args)