-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.py
115 lines (92 loc) · 3.1 KB
/
user.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# CONFIGURATION FILE
from termcolor import colored
import random
"""
user_config params:-
testCases: Number of testCases to test against
usedtt: Multiple testCases in input (NOTE: Refresh each global parameter after each test case)
showEachPass: Print affirmative after each test case passed
removeBlanks: remove blanks (whitespaces) in the output
whereFail: print where the output doesn't match
debug: for each input -> print input, your output & brute output
saveTC: relative path to a file which stores the failed test case, None if file is not to be saved
extraTC: relative path to a folder containing one or more input files for testing against your custom test cases, None if no extra test cases are to be used
"""
user_config = {
"testCases": 1000,
"usedtt": False,
"showEachPass": True,
"removeBlanks": True,
"whereFail": True,
"inputPipe": "_temp/inputf.in",
"debug": False,
"saveTC": "sols/in.txt",
"extraTC": None, # TODO
}
"""
NOTE: "_temp" is created during stress testing, it is advisable to leave these settings intact
NOTE: If you wish to change paths for intermediate executables, change appropriately in the makefile
stress_config params:
inputPipe: input file used to feed input to executables
bruteExec: path to brute executable
myExec: path to your executable
"""
stress_config = {
"inputPipe": "_temp/inputf.in",
"bruteExec": "_temp/bruteOut",
"myExec": "_temp/myOut",
}
# ===========
"""
docs:
Generate your random test cases in this function
return:
list of strings where each string is supposed to be displaed on a new line
"""
def gen_case():
lim = int(1000)
dlim = int(1e9)
n = random.randint(1, lim)
# List containing distinct elements
done = {}
a = []
while len(a) != n:
put = random.randint(-dlim, dlim)
while put in done:
put = random.randint(-dlim, dlim)
a.append(put)
done[put] = 1
# Any List
# a = [random.randint(-dlim, dlim) for _ in range(n)]
tc = [str(n), " ".join(list(map(str, a)))]
return tc
# ===========
"""
docs:
Checks if your solution is correct based on an input
Currently performs string comparison
params:
inp: list of strings denoting the input
brute_response: list of strings denoting brute output
my_response: list of strings denoting my output
return:
boolean denoting if output satisifes the condition
"""
def checker(my_response, brute_response=None, inp=None):
# check matching length
if len(my_response) != len(brute_response):
print(colored("\n!! FAIL !!", "red", attrs=["bold"]))
if user_config["whereFail"]:
print("whereFail: UNMATCHING LENGTH")
return False
# compare each line of response
N = len(my_response)
for i in range(N):
if my_response[i] != brute_response[i]:
print(colored("\n!! FAIL !!", "red", attrs=["bold"]))
if user_config["whereFail"]:
print("whereFail: LINE", i + 1)
print("my_response: ", my_response[i])
print("brute_response: ", brute_response[i])
return False
return True