-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgene.py
76 lines (71 loc) · 2.29 KB
/
gene.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
import numpy as np
import click
import random
from time import time
random.seed(int(time()))
def random_array(tc, maxn, minn, length, maxLength):
sizes = []
content = []
for t in range(tc):
if length == -1:
s = random.randint(1, maxLength)
else:
s = length
# if s < maxn - minn:
# raise ValueError("Number of elements is larger than the range!")
nums = random.sample(range(minn, maxn), s)
sizes.append(s)
content.append(nums)
return sizes, content
def print_array(tc, size, content, download):
# with open(f'test_case_{int(time())}.txt', 'w') as f:
out = ""
if download != 'YES':
out += '-' * 50 + '\n'
out += str(tc) + '\n'
for s, c in zip(size, content):
out += '\n' + str(s) + '\n'
for each in c:
out += str(each) + ' '
out += '\n'
if download == 'YES':
with open(f'test_case_{int(time())}.txt', 'w') as f:
print(out, file=f)
else:
print(out)
@click.command()
@click.option('--tc', prompt='Test cases',
type=int, default=1,
help='Mention the number of test cases')
@click.option('--what', prompt='Problem Type',
type=click.Choice(['NUM', 'ARR', 'MAT'], case_sensitive=False),
help='Mention the type of testcase')
@click.option('--maxN', prompt='Maximum value',
type=float,
help='Maximum value of the num, arr or mat')
@click.option('--minN', prompt='Minimum value',
type=float,
help='Minimum value of the num, arr or mat')
@click.option('--fixedLength', prompt='Fixed Length',
type=click.Choice(['YES', 'NO'], case_sensitive=False),
help='Minimum value of the num, arr or mat')
@click.option('--download', prompt='Download tescases',
type=click.Choice(['YES', 'NO'], case_sensitive=False),
default='NO',
help='If you want to download the test cases')
def gene(tc, what, maxn, minn, fixedlength, download):
maxn = int(maxn) if int(maxn) == maxn else maxn
minn = int(minn) if int(minn) == minn else minn
length = -1
if what != 'NUM':
if fixedlength == 'YES':
length = int(input('Length: '))
if what == 'ARR':
if fixedlength == 'YES':
maxLength = fixedlength
else:
maxLength = int(input('Max Len: '))
sizes, content = random_array(tc, maxn, minn, length, maxLength)
print_array(tc, sizes, content, download)
if __name__ == '__main__':
gene()