This repository has been archived by the owner on Nov 26, 2019. It is now read-only.
forked from aashutoshrathi/Testcase-Generator
-
Notifications
You must be signed in to change notification settings - Fork 4
/
tc_gen.py
96 lines (72 loc) · 2.53 KB
/
tc_gen.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
'''
Aashutosh Rathi
https://github.com/aashutoshrathi/
Testcase Generator for HackerRank
'''
from __future__ import print_function
import os
import random
import shutil
import sys
import timeit
import zipfile
import math
from lang_compiler import LANGS
if sys.version[0] == '3':
INPUT = input
XRange = range
try:
os.mkdir('input')
os.mkdir('output')
except OSError:
pass
POWER = math.pow
RINT = random.randint
def generate(choice, i):
try:
os.system('%s < input/input%02d.txt > output/output%02d.txt' %
(LANGS[choice - 1]['command'], i, i))
except Exception:
print("Looks like you don't have {0} :/ \nYou can refer to {1} for help.".format(
LANGS[choice - 1]['req'], LANGS[choice - 1]['link']))
def compile_them(test_files, choice):
if os.system(LANGS[choice - 1]['compile']) == 0:
zip_them(test_files, choice)
def zip_them(test_files, choice):
with zipfile.ZipFile('test-cases.zip', 'w', zipfile.ZIP_DEFLATED) as zip_file:
for i in XRange(0, test_files + 1):
print('Zipping:', i, file=sys.stderr)
exe_command = 'generate({0}, {1})'.format(choice, i)
exe_time = timeit.timeit(
exe_command, globals=globals(), number=1)
print('Time taken to execute this TC %02f seconds' %
(exe_time), file=sys.stderr)
zip_file.write('input/input%02d.txt' % i)
zip_file.write('output/output%02d.txt' % i)
def main():
choice = int(INPUT(
"Enter your choice of language\n1. C\n2. C++\n3. Java\n4. Python\n5. C#\n6. Go\n"))
if choice not in range(1, 7):
print("Wrong choice entered!")
exit()
test_files = 10 # number of test files, change it according to you.
for i in XRange(0, test_files + 1):
print('Generating:', i, file=sys.stderr)
sys.stdout = open('input/input%02d.txt' % i, 'w')
'''
Input area will start here,
everything that you print out here will be taken as input in your logic file.
'''
# Input File Printing Starts
# number of test cases in (1,10^5)
required_input = RINT(5, POWER(10, (i // 2) + 1))
print(required_input) # Prints x into input file
for _ in range(required_input):
print(RINT(1, POWER(10, min(4, max(i // 2, 2)))))
sys.stdout.close()
# Input File Printing Ends
compile_them(test_files, choice)
shutil.rmtree('input')
shutil.rmtree('output')
if __name__ == "__main__":
main()