Created
October 20, 2019 11:52
-
-
Save moonblade/43ba3c76ad000e4acddb55f5163694bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python | |
# generic test case maker for hacker rank questions | |
from enum import Enum | |
import random | |
# Input types, Attributes | |
# Int : range (2 tuple), | |
defaults = { | |
"intMinVal": 1, | |
"intMaxVal": 10000 | |
} | |
class Type(Enum): | |
INT="INT" | |
STATIC="STATIC" | |
class Input(): | |
def __init__(self, dict): | |
self.type = Type.INT | |
if "type" in dict: | |
self.type = Type[dict["type"]] | |
if self.type == Type.INT: | |
self.minVal = defaults["intMinVal"] | |
self.maxVal = defaults["intMaxVal"] | |
if "minVal" in dict: | |
self.minVal = dict["minVal"] | |
if "maxVal" in dict: | |
self.maxVal = dict["maxVal"] | |
if self.type == Type.STATIC: | |
self.value = " " | |
if "value" in dict: | |
self.value = dict["value"] | |
def generate(self): | |
if self.type == Type.INT: | |
return str(random.randint(self.minVal, self.maxVal)) | |
if self.type == Type.STATIC: | |
return self.value | |
class Generator(): | |
def __init__(self, input): | |
self.input = [] | |
for x in input: | |
self.input.append(Input(x)) | |
def generate(self, testCases): | |
string = [] | |
for x in range(testCases): | |
for y in self.input: | |
string.append(y.generate()) | |
return string | |
if __name__ == "__main__": | |
input = [ | |
{ | |
"type": "INT", | |
"minVal": 1, | |
"maxVal": 10 | |
}, | |
{ | |
"type": "STATIC", | |
"value": "\n" | |
}, | |
{ | |
"type": "INT", | |
"minVal": 1, | |
"maxVal": 10 | |
}, | |
] | |
g=Generator(input) | |
print(''.join(g.generate(1))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment