Skip to main content

A complete test case generator.

Project description

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)

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

pycontest-1.3.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

pycontest-1.3-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file pycontest-1.3.tar.gz.

File metadata

  • Download URL: pycontest-1.3.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pycontest-1.3.tar.gz
Algorithm Hash digest
SHA256 eea95f325a7ad8e0a20da7e05456cd74c3fe14be43936815722561c97ea6d412
MD5 04bff3227a1ebba2f52200ccc02e3e6a
BLAKE2b-256 dcda87e54bcf407024aaccb1eaa48eb3f6c62dd4a4c05c17038c82e0dc08bae5

See more details on using hashes here.

File details

Details for the file pycontest-1.3-py3-none-any.whl.

File metadata

  • Download URL: pycontest-1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pycontest-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d68c4821b47141c7fbd2e8e657e6eb96692fe7d91e4e557f97973dcce58c111e
MD5 9a1de9a2bcc280b39eb916eb0b0a849e
BLAKE2b-256 be1228fbbe48133446c5d50ea30415dfecdf823bc9716caa072e7a9d4c697c3c

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