Skip to main content

A flexible framework for generating randomized test cases with input/output validation, designed for competitive programming and algorithmic testing.

Project description

Easy Random Test Case Generator Framework

A flexible framework for generating randomized test cases with input/output validation, designed for competitive programming and algorithmic testing.

Features

  • Type-safe generators for all basic data types and structures
  • Automatic test validation with BadTestException handling
  • Customizable I/O formatting for any problem format
  • Sample test integration alongside generated cases
  • Extensible architecture for custom generators

Installation

pip install contest-helper

Quick Start

from contest_helper import *


# 1. Define your solution with validation
def word_count(text: str) -> int:
    if len(text) > 1000:
        raise BadTestException("Input too long")
    return len(text.split())


# 2. Configure generator
generator = Generator(
    solution=word_count,
    tests_generator=RandomSentence(min_length=1, max_length=20),
    tests_count=10,
    input_parser=lambda lines: ' '.join(lines),
    input_printer=lambda text: [text],
    output_printer=lambda count: [str(count)]
)

# 3. Generate tests
generator.run()

Core Components

Value Generators

Generator Description Example
Value Basic value wrapper Value(5)
Lambda Custom generator functions Lambda(lambda: datetime.now())
RandomValue Random value from sequence RandomValue(['red', 'green', 'blue'])
RandomNumber Numeric ranges RandomNumber(1, 100)
RandomWord Random strings RandomWord()
RandomSentence Natural language-like text RandomSentence()
RandomList Random sequences RandomList(gen, 5)
RandomSet Random sequences RandomSet(gen, 5)
RandomDict Key-value pairs RandomDict(kgen, vgen, 3)

Test Validation

def solution(input_data):
    # Validate input before processing
    if is_invalid(input_data):
        raise BadTestException("Validation failed")
    
    # Normal processing...

I/O Configuration

Generator(
    input_parser=lambda lines: parse_custom_format(lines),
    input_printer=lambda obj: format_as_text(obj),
    output_printer=lambda result: [str(result)]
)

Advanced Usage

Dynamic Test Generation

dynamic_gen = RandomDict(
    key_generator=RandomWord(),
    value_generator=RandomList(
        RandomNumber(1, 100),
        length=RandomNumber(2, 5)
    ),
    length=RandomNumber(3, 10)
)

Custom Generators

class RandomGraph(Value[Dict]):
    def __init__(self, node_count: Value[int]):
        self.node_count = node_count
    
    def __call__(self) -> Dict:
        nodes = [f"node{i}" for i in range(self.node_count())]
        return {
            n: random.sample(nodes, k=random.randint(1, len(nodes)))
            for n in nodes
        }

Directory Structure

Generated tests follow this structure:

tests/
├── sample01    # Sample input
├── sample01.a  # Sample output
├── 01          # Generated test input
├── 01.a        # Generated test output
└── ...

Best Practices

  1. Validation: Always validate inputs in your solution function
  2. Descriptive Messages: Provide clear BadTestException messages
  3. Generator Composition: Build complex types from simple generators
  4. Test Diversity: Configure generators to produce edge cases
  5. Performance: Avoid expensive operations in validation

License

MIT License - Free for commercial and personal use

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

contest_helper-0.1.4.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

contest_helper-0.1.4-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file contest_helper-0.1.4.tar.gz.

File metadata

  • Download URL: contest_helper-0.1.4.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for contest_helper-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b4f7a92f4748abf4d1c210cd88426eeac4e439ba170a03920247aa87e4bbfcb9
MD5 ebd73300ccf42643d2932ac54f42dd58
BLAKE2b-256 d7dd346b4e6fe61ae734a1d55203f6fa4946db5f0866998b3413e37395273b51

See more details on using hashes here.

File details

Details for the file contest_helper-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: contest_helper-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for contest_helper-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 97c1aca8958640abfa27c2b43e4ab94d0aa2f20cdd2d425708b545df2d0ac32d
MD5 7d32e2cad59e7a64d5eae80e17472652
BLAKE2b-256 1b920cf0d363a7c2528c2e2476d4b07c961d6f8df2e29c5018575c55da49ee28

See more details on using hashes here.

Supported by

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