Skip to main content

An easy to use test case generator.

Project description

pycontest(v1.0)

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

Installation

$ pip install pycontest

Basic Usage

I highly recommend you to read 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)

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 using 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()

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.

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.2.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.2-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pycontest-1.2.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.0

File hashes

Hashes for pycontest-1.2.tar.gz
Algorithm Hash digest
SHA256 05eeb0cc96cb3acad56d0c4f4251907240ce81d0fad4bc8c9d85f7182be07285
MD5 b53f1f6565e8c7a5e756e1043643dccd
BLAKE2b-256 b794545ebab1e001515113beb7e3f71ec64450a27d6fd8ca7ea2459ea7c4a490

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycontest-1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.0

File hashes

Hashes for pycontest-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6f1fd0977e2626cc978b7a74a1c98993ad12aea4d581c7dd9ae5aa97e5b00676
MD5 0ac15c022771e5401b450a521281d79b
BLAKE2b-256 bdd4d440669029b69392a49d9ea69258e9d777596c1c74be5445a40cfa96aca2

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