{"id":19817960,"url":"https://github.com/renuka-fernando/hackgen","last_synced_at":"2025-05-01T11:31:33.353Z","repository":{"id":55868810,"uuid":"149021538","full_name":"renuka-fernando/hackgen","owner":"renuka-fernando","description":"Generate Test cases for HackerRank Problems","archived":false,"fork":false,"pushed_at":"2020-11-05T11:40:35.000Z","size":34,"stargazers_count":11,"open_issues_count":0,"forks_count":6,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-10-30T15:56:01.614Z","etag":null,"topics":["c","cpp","hackerrank","java","python3","testcase-generator"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/renuka-fernando.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-16T18:00:24.000Z","updated_at":"2023-10-06T04:51:00.000Z","dependencies_parsed_at":"2022-08-15T08:10:30.396Z","dependency_job_id":null,"html_url":"https://github.com/renuka-fernando/hackgen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renuka-fernando%2Fhackgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renuka-fernando%2Fhackgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renuka-fernando%2Fhackgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renuka-fernando%2Fhackgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/renuka-fernando","download_url":"https://codeload.github.com/renuka-fernando/hackgen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224253335,"owners_count":17280934,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","cpp","hackerrank","java","python3","testcase-generator"],"created_at":"2024-11-12T10:14:14.620Z","updated_at":"2024-11-12T10:14:15.325Z","avatar_url":"https://github.com/renuka-fernando.png","language":"Python","readme":"# HackGen: HackerRank Test Case Generator\n[![Build Status](https://travis-ci.org/renuka-fernando/hackgen.svg?branch=master)](https://travis-ci.org/renuka-fernando/hackgen)\n[![HitCount](http://hits.dwyl.io/renuka-fernando/hackgen.svg)](http://hits.dwyl.io/renuka-fernando/hackgen)\n\nGenerate test cases for your problem easily. Credits to @aashutoshrathi.\n\n## Table of Contents\n\n- [HackGen: HackerRank Test Case Generator](#hackgen-hackerrank-test-case-generator)\n  - [Table of Contents](#table-of-contents)\n  - [1. Installation in Python](#1-installation-in-python)\n  - [2. Getting Started](#2-getting-started)\n    - [2.1. Identify your Input Format and Constraints](#21-identify-your-input-format-and-constraints)\n    - [2.2. Your Solution Algorithm](#22-your-solution-algorithm)\n    - [2.3. Define Input Format](#23-define-input-format)\n      - [2.3.1. Required Information for TestGenerator](#231-required-information-for-testgenerator)\n    - [2.4. Find the Zipped Test Files](#24-find-the-zipped-test-files)\n  - [3. License](#3-license)\n  - [4. Contributions](#4-contributions)\n\n## 1. Installation in Python\nHackGen is on PyPI, so you can use pip to install it:\n```bash\n# bash\n$ pip install hackgen\n```\nAfter installation, you can [get started!](#2-getting-started)\n\n## 2. Getting Started\n\nFor the example lets take the simple problem \"[Clock Delay](https://www.hackerrank.com/contests/hourrank-28/challenges/clock-delay)\" as the problem you have created.\n\n### 2.1. Identify your Input Format and Constraints\n\n\u003e #### Input Format\n\u003e - The first line contains ***q***, the number of queries.\n\u003e - Each query is described by two lines. The first line contains four space-separated integers ***h1, m1, h2, m2***. The second line contains a single integer ***k***.\n\n\u003e #### Constraints\n\u003e - 1 ≤ ***q*** ≤ 1000\n\u003e - 0 ≤ ***h1*** \u003c 23\n\u003e - 0 ≤ ***h2*** \u003c 24\n\u003e - 0 ≤ ***m1***, ***m2*** \u003c 60\n\u003e - 1 ≤ ***k***\n\u003e - ***h1*** + ***k*** \u003c 24\n\u003e - It is guaranteed that ***h1:m1*** is strictly before ***h2:m2***\n\n### 2.2. Your Solution Algorithm\n\nThis can be python, java, c++, c file. If you need support other languages please update the `Language` class in the [language.py](hackgen/language.py) file.\n\n1. Your solution [logic.py](examples/clockdelay/logic.py) file.\n\n```py\nq = int(input())\n\nfor i in range(q):\n    h1, m1, h2, m2 = map(int, input().split())\n    k = int(input())\n    delay = (h1 + k - h2) * 60 + m1 - m2\n    print(delay)\n```\n\n2. Your solution [Logic.java](examples/clockdelay/Logic.java) file.\n\n```java\nimport java.util.Scanner;\n\npublic class Logic {\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n        int q = scanner.nextInt();\n\n        for (int i = 0; i \u003c q; i++) {\n            int h1, m1, h2, m2, k;\n            h1 = scanner.nextInt();\n            m1 = scanner.nextInt();\n            h2 = scanner.nextInt();\n            m2 = scanner.nextInt();\n            k = scanner.nextInt();\n\n            int delay = (h1 + k - h2) * 60 + m1 - m2;\n            System.out.println(delay);\n        }\n    }\n}\n```\n\n### 2.3. Define Input Format\n\nCreate a file [clockdelay.clock_delay.py](examples/clockdelay/clock_delay.py) in the same directory the [logic.py](examples/clockdelay/logic.py) file contains.\n\nCreate the class `ClockDelayInputFormat` extending [`hackgen.TestInputFormat`](python/hackgen/test_input_format.py) and overriding `inputs(difficult_level: int) -\u003e None` method with constraints and input format identified in the second step.\n\nYou can introduce difficulty with using `difficult_level` value which is between 0 and 9 inclusively [0-9].\n\n```py\nimport random\n\nfrom hackgen import TestInputFormat, TestGenerator, Language\n\n\nclass ClockDelayInputFormat(TestInputFormat):\n    \"\"\"\n    Input format of Clock Delay challenge.\n    https://www.hackerrank.com/contests/hourrank-28/challenges/clock-delay\n    \"\"\"\n\n    # difficulty levels with test file number\n    # difficulty level is [0-9]\n    __diff = [(5, 10), (10, 30), (50, 100), (100, 300), (100, 300),\n              (300, 600), (600, 900), (800, 1000), (900, 1000), (950, 1000)]\n\n    def inputs(self, difficult_level: int) -\u003e None:\n        q = random.randint(*self.__diff[difficult_level])  # number of test cases\n        print(q)\n        for n in range(q):\n            # constraints for h1 m1 h2 m2 k\n            h1 = random.randint(0, 23)\n            m1 = random.randint(0, 60)\n            h2 = random.randint(h1, 24)\n            k = random.randint(h2 - h1 + 1 if h1 == h2 else h2 - h1, 24 - h1)\n            m2 = random.randint(0, (m1 if h1 + k == h2 else 60))\n            print(h1, m1, h2, m2)\n            print(k)\n\n\n# input format instance\ninput_format = ClockDelayInputFormat()\n\n# try with Language.java('Logic') also\ntest_generator = TestGenerator(10, input_format, Language.python('logic'), \"ClockDelay\")\ntest_generator.run()\n```\n\nCreate instance `inputFormat` of [`clockdelay.ClockDelayInputFormat`](examples/clockdelay/clock_delay.py) class. Create generator using `hackgen.TestGenerator` class with required information.\n\n#### 2.3.1. Required Information for TestGenerator\n\n- Number of Test Files Needs: ***10***\n- Instance of TestInputFormat: ***ClockDelayInputFormat***\n- Language of Solution File (python, java, c++, c) and File Name: ***python(logic)*** also try with ***java(Logic)***\n- Name of the Problem: ***ClockDelay***\n\n### 2.4. Find the Zipped Test Files\n\nExecute the script [clock_delay.py](examples/clockdelay/clock_delay.py).\n\nRun the following in a terminal.\n```bash\n$ cd examples/clockdelay/ \u0026\u0026 python clock_delay.py\n```\n\nSee the file `${Name}-test-cases.zip` contains in the directory `examples/clockdelay/`.\n\n## 3. License\n\nHackerRank Test Case Generator is [MIT licensed](./LICENSE).\n\n## 4. Contributions\n\nContributions are welcome! :)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenuka-fernando%2Fhackgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frenuka-fernando%2Fhackgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenuka-fernando%2Fhackgen/lists"}