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.

Source Distribution

hackgen-1.0.1.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

hackgen-1.0.1-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page