Skip to main content

pycontest(v1.2)

An easy to use testcase generator for generating testcases for online judges.

Installation

$ pip install pycontest

Basic Usage

I highly recommend you reading this example.

Types

Type Description Example
IntVar(a, b) Generates a random integer N such that a <= N <= b. IntVar(1, IntVar(10, 20))
FloatVar(a, b) Generates a random float N such that a <= N <= b. FloatVar(1.5, FloatVar(1.6, 20))
CustomArray(l, g, *args) Generates an array with length l and g as generator of each element Here
IntArray(a, b, l) Generates a random integer array with length l and IntVar(a, b) as generator. IntArray(0, 100, IntVar(0, 10**9))
FloatArray(a, b, l) Generates a random float array with length l and FloatVar(a, b) as generator. FloatArray(2.2, 80.3, IntVar(0, 10**9))
ChoiceList(l, c_l: list or string) Generates a random array with length l and a random choice of c_l ChoiceList(100, string.hexdigits)
Array2d(l, array:[IntArray, FloatArray, ChoiceList]) Populates a 2d array with given array Here

Usage

from pycontest import Case, IntArray, \
    IntVar

from pycontest.helper import list_printer


class TestCase(Case):
    batch_size = 10

    n = IntVar(1, 10**2)
    arr = IntArray(-1000, 1000, n)

    def __inp_str__(self):
        return f"{self.n}\n" +\
                f"{list_printer(self.arr)}"

    def config(self):
        self.function = min
        self.input_sequence = [self.arr]


Case.main()

Instead of function you can use a python file, set self.app to the python file path.

    def config(self):
        self.path = 'my_app.py'

in this method your app will run with __inp_str__ function as input, and all the stdout prints will captured as output. see example_app.

writer

Default writer, writes each testcase into separate files:

        # └───tests
        #     ├────in
        #     │     ├───input0.txt
        #     │     ├───input1.txt
        #     │     │  . . .
        #     │     └───input10.txt
        #     └────out
        #           ├───output0.txt
        #           ├───output1.txt
        #           │  . . .
        #           └───output10.txt

each tests/in/input<n>.txt file contains the output of __inp_str__function.

each tests/out/output<n>.txt file contains the the output of function with *input_sequence as parameters.

For more examples and explanation see examples.

Using more than one TestCase

you can simply generate different test cases with making more classes inheriting from Case class.

...
class TestCase1(Case):
    # ...
    pass

class TestCase2(Case):
    # ...
    pass
Case.main()

Using custom generator

To use your own generator for generating variables you can use CustomArray.

from pycontest import Case, IntVar, CustomArray
import random


def q(n: int):
    while True:
        x = random.randint(0, 3000)
        if n > 0 and x > 1000 or x == 0:
            yield 0
            n -= 1
        else:
            yield x


class TestCase(Case):
    m = IntVar(0, 5)
    arr = CustomArray(100, q, m)

    def __str__(self):
        return f"input:\n{self.m}\n" + \
               f"\n{self.arr}\n"


Case.main()

from pycontest import Case, IntVar, IntArray Here with CustomArray via our q generator we were able to generate an array that has maximum m 0s in and chance of a member being 0 is 1/3.

###using-2d-array

class TestCase(Case):
    m = IntVar(0, 5)
    arr = IntArray(100, q, m)
    arr2d = Array2d(m, arr)

Metadata

Release files for pycontest 1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycontest 1.3
File Size Uploaded
pycontest-1.3.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycontest 1.3
File Interpreter ABI Platform
pycontest-1.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.6 kB

Release files / pycontest-1.3.tar.gz

Download URL pycontest-1.3.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
eea95f325a7ad8e0a20da7e05456cd74c3fe14be43936815722561c97ea6d412
BLAKE2b-256 checksum
How to use checksums
dcda87e54bcf407024aaccb1eaa48eb3f6c62dd4a4c05c17038c82e0dc08bae5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

Release files / pycontest-1.3-py3-none-any.whl

Download URL pycontest-1.3-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d68c4821b47141c7fbd2e8e657e6eb96692fe7d91e4e557f97973dcce58c111e
BLAKE2b-256 checksum
How to use checksums
be1228fbbe48133446c5d50ea30415dfecdf823bc9716caa072e7a9d4c697c3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

Release history Release notifications | RSS feed

This release

1.3 This release

2 release files

1.2

2 release files

1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page