Skip to main content

HackerRank Test-Case Generator

Project description

Generate test cases for your HackrRank challenge. You need your solution algorithm, input format and constraints only. Generate the zipped file and upload :)

Installation

$ pip install hackgen

Example usage

>>> import random
>>> from hackgen import TestInputFormat, TestGenerator, Language
>>> class ClockDelayInputFormat(TestInputFormat):
>>>     """
>>>     Input format of Clock Delay challenge.
>>>     https://www.hackerrank.com/contests/hourrank-28/challenges/clock-delay
>>>     """
>>>
>>>     # difficulty levels with test file number
>>>     # difficulty level is [0-9]
>>>     __diff = [(5, 10), (10, 30), (50, 100), (100, 300), (100, 300),
>>>               (300, 600), (600, 900), (800, 1000), (900, 1000), (950, 1000)]
>>>
>>>     def inputs(self, difficult_level: int) -> None:
>>>         q = random.randint(*self.__diff[difficult_level])  # number of test cases
>>>         print(q)
>>>         for n in range(q):
>>>             # constraints for h1 m1 h2 m2 k
>>>             h1 = random.randint(0, 23)
>>>             m1 = random.randint(0, 60)
>>>             h2 = random.randint(h1, 24)
>>>             k = random.randint(h2 - h1 + 1 if h1 == h2 else h2 - h1, 24 - h1)
>>>             m2 = random.randint(0, (m1 if h1 + k == h2 else 60))
>>>             print(h1, m1, h2, m2)
>>>             print(k)
>>>
>>> # input format instance
>>> input_format = ClockDelayInputFormat()
>>>
>>> # try with Language.java('Logic') also
>>> test_generator = TestGenerator(10, input_format, Language.python('logic'), "ClockDelay")
>>> test_generator.run()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for hackgen, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size hackgen-1.0.1-py3-none-any.whl (4.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size hackgen-1.0.1.tar.gz (3.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page