-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrute.py
More file actions
executable file
·81 lines (69 loc) · 2 KB
/
brute.py
File metadata and controls
executable file
·81 lines (69 loc) · 2 KB
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
80
81
#!/usr/bin/env python
import subprocess
import sys
# -----------------------------------------------------------------------------
# Brute Force Stress Tester for Python Solutions (Python Version)
#
# Usage:
# python brute.py <correct.py> <your_wrong.py>
#
# -----------------------------------------------------------------------------
if len(sys.argv) != 3:
print(f"Usage: {sys.argv[0]} <correct.py> <your_wrong.py>")
sys.exit(1)
CORRECT = sys.argv[1]
WRONG = sys.argv[2]
for i in range(1, 10000):
print(f"Test #{i}")
try:
input_data = subprocess.check_output(["python", "gen.py"], text=True)
except subprocess.CalledProcessError as e:
print("Error generating input:", e)
break
try:
out1 = subprocess.run(
["python", WRONG],
input=input_data,
text=True,
capture_output=True,
timeout=2
)
except subprocess.TimeoutExpired:
print("Timeout on your wrong solution!")
break
try:
out2 = subprocess.run(
["python", CORRECT],
input=input_data,
text=True,
capture_output=True,
timeout=2
)
except subprocess.TimeoutExpired:
print("Timeout on correct solution!")
break
if out1.returncode != 0:
print("❌ Error during execution of your wrong solution!")
print("Input:")
print(input_data)
print("Stderr:")
print(out1.stderr)
break
if out2.returncode != 0:
print("❌ Error during execution of correct solution!")
print("Input:")
print(input_data)
print("Stderr:")
print(out2.stderr)
break
if out1.stdout.strip() != out2.stdout.strip():
print("❌ Mismatch found!")
print("Input:")
print(input_data)
print("Your output:")
print(out1.stdout)
print("Correct output:")
print(out2.stdout)
break
else:
print("✅ OK")