Skip to main content

Coding Test Input Generator

CoTeGen automatically generates test suite of a typical coding test problem from the bottom. First, an initial test suite can be constructed with minimal cost. Next, search-based input generation with mutation fitness complement the initial test suite. Using mutated reference solution as a simplified form of wrong answers, we aim to kill as many mutants as possible. Hence, mutation coverage is provided as a complementary result.

Adding New Reference Solution

After installing our cotegen package, You can write a new reference solution as a simple python file to generate corresponding test cases.

Please locate your reference solution file in examples/tasks directory to utilize command line execution.

You should define a new class inherits cotegen.Task and with the same with filename.

input_parameters, solve(reference solution), compare, and convert_input_to_string are essential methods to override.

Please refer the example:

import cotegen

# http://codeforces.com/problemset/problem/1/A

class CF1A(cotegen.Task):
    input_parameters = \
        {
            'n': cotegen.types.Integer(1, 10**9),
            'm': cotegen.types.Integer(1, 10**9),
            'a': cotegen.types.Integer(1, 10**9),
        }

    def solve(n: int, m: int, a: int) -> int:
        # 1 <= n, m, a <= 10**9
        return ((n + (a-1)) // a) * ((m + (a-1)) // a)

    @staticmethod
    def compare(user_answer: int, jury_answer: int) -> bool:
        return user_answer == jury_answer

    @staticmethod
    def convert_input_to_string(n: int, m: int, a: int):
        return "%d %d %d\n" % (n, m, a)


if __name__ == '__main__':
    import os
    CF1A.generate_test_files(os.path.expanduser("~/Downloads/CS453/CF1A"))

Define Input Parameters

Predefine the types of input parameters and the range of each argument as a dictionary format.

Currently, CoTeGen supports following types:

cotegen.types.Integer
cotegen.types.IntegerSequence
cotegen.types.NonIncreasingIntegerSequence
cotegen.types.FixedVariableLengthIntegerSequence
cotegen.types.IntegerPermutation

Define constraint

If needed, define the constraints among input parameters as list.

constraints = [
        cotegen.constraints.Leq('M', 'N')
    ]

You can utilize these predefined constraints:

cotegen.constraints.Leq (Less than or equal)
cotegen.constraints.ListLengthLeqInteger
cotegen.constraints.ListLengthReqInteger

or, use custom constraints giving custom function (which receives parameter dictionary and returns true/false) as an argument

cotegen.constraints.CustomConstraint(lambda test: 'd1' not in test or 'd2' not in test or test['d1'] != test['d2'])

Command Line Usage

python -m cotegen run random --filename <filename>

python -m cotegen run mutation --filename <filename> --show-survived <true or false>

python -m cotegen run kill --filename <filename> --save <directory path> --mutation-fitness <true or false>

For example:

python -m cotegen run random --filename CF158A

python -m cotegen run mutation --filename CF158A

python -m cotegen run kill --filename CF158A --save ~/Downloads --mutation-fitness true

Metadata

Release files for cotegen 1.1

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

Source distribution (sdist)

Source distribution for cotegen 1.1
File Size Uploaded
cotegen-1.1.tar.gz 17.9 kB Details

Built distribution (wheel)

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

Total release size: 42.5 kB

Release files / cotegen-1.1.tar.gz

Download URL cotegen-1.1.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
85d2fe84b1658867978bf9c47f24a272d525e41077fc79e53379af663f315188
BLAKE2b-256 checksum
How to use checksums
26d8c8f19eb47b074f740f325b51caf7504c3295583227e474c2893c415982e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.1

Release files / cotegen-1.1-py3-none-any.whl

Download URL cotegen-1.1-py3-none-any.whl
Size 24.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb090de064405e9e958a57d4d8527a18e718de04c0db342fa01c0cabbbc98ba5
BLAKE2b-256 checksum
How to use checksums
62eccd23f6b460cce1fab15f1a61fc65f07bce610f8cbdf9c2a6dd58d9b3b88f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.1

Release history Release notifications | RSS feed

This release

1.1 This release

2 release files

1.0

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