forked from NJACKWinterOfCode/HackerRank-Test-Case-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TCGen.py
74 lines (59 loc) · 2.49 KB
/
TCGen.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
'''
Aashutosh Rathi
https://github.com/aashutoshrathi/
Testcase Generator for HackerRank
'''
import os
import random
import sys
import zipfile
import math
import shutil
try:
os.mkdir('input')
os.mkdir('output')
except OSError:
pass
choice = int(raw_input("Enter your choice of language\n1 for C\n2 for C++\n3 for Java\n4 for Python\n"))
if choice != 1 and choice != 2 and choice != 3 and choice != 4:
print("Wrong choice entered!")
exit()
tf = 10 # number of test files, change it according to you.
for i in xrange(0, tf + 1):
print >> sys.stderr, 'Generating:', i
sys.stdout = open('input/input%02d.txt' % i, 'wb')
'''
Input area will start here,
everything that you print out here will be taken as input in your logic file.
You can set difficulty of test cases all by you.
'''
# Input File Printing Starts
sys.stdout.close()
# Input File Printing Ends
'''
Output generation and zipping starts here
just replace '<filename>' with your actual filename everywhere
'''
# You can change zip filename as per your wish.
with zipfile.ZipFile('test-cases.zip', 'w', zipfile.ZIP_DEFLATED) as zf:
for i in xrange(0, tf + 1):
print >> sys.stderr, 'Zipping:', i # Will show status of which TC output is generated.
if choice == 1: # Choice of language is C
os.system('gcc -o <filename> <filename>.c') # System call to compile .c file
# System call to generate output files for C
os.system('./<filename> < input/input%02d.txt > output/output%02d.txt' % (i, i))
elif choice == 2: # Choice of language is C++
os.system('g++ -o <filename> <filename>.cpp') # System call to compile .cpp file
# System call to generate output files for C++
os.system('./<filename> < input/input%02d.txt > output/output%02d.txt' % (i, i))
elif choice == 3: # Choice of language is Java
os.system('javac <filename>.java') # System call to compile .java file
# System call to generate output files for Java
os.system('java <filename> < input/input%02d.txt > output/output%02d.txt' % (i, i))
elif choice == 4: # Choice of language is Python
# System call to generate output files for Python
os.system('python <filename>.py < input/input%02d.txt > output/output%02d.txt' % (i, i))
zf.write('input/input%02d.txt' % i)
zf.write('output/output%02d.txt' % i)
shutil.rmtree('input')
shutil.rmtree('output')