AlgoMock
AlgoMock is a flexible and powerful input generator for algorithm testing and competitive programming. It allows you to easily create mock input data for various algorithm problems, helping you test your solutions more efficiently.
Features
- Generate various types of input: integers, strings, arrays, and 2D arrays
- Define input specifications using a simple and intuitive format
- Reference previously generated values in your specifications
- Customizable output format
- Support for loops and repetition in input generation
Installation
You can install AlgoMock using pip:
pip install algomock
Quick Start
Here's a simple example of how to use AlgoMock:
from algomock import generate_input
spec = [
{'type': 'int', 'limit': [1, 10], 'save_as': '$N'}, # N
{'type': 'space'},
{'type': 'int', 'limit': [1, 10], 'save_as': '$M'}, # M
{'type': 'newline'},
{'type': 'array', 'size': '$N', 'element_type': 'int', 'limit': [1, 100]}, # Array of size N
{'type': 'newline'},
{'type': '2d_array', 'rows': '$M', 'cols': '$N', 'element_type': 'int', 'limit': [0, 100]}, # 2D array of size M x N
]
input_data = generate_input(spec)
print(input_data)
This will generate input data according to the specification and print it in a format suitable for most algorithm problems.
Detailed Usage
AlgoMock uses a list of dictionaries to specify the input format. Each dictionary represents one element of the input. Below is a detailed explanation of each input type and how to use them.
Integer (int)
Generates a random integer within a specified range.
Parameters:
type: Set to'int'limit: A list of two integers[min, max]specifying the range (inclusive)save_as(optional): A variable name to save the generated value for later reference
Example:
{'type': 'int', 'limit': [1, 100], 'save_as': '$N'}
This will generate a random integer between 1 and 100 (inclusive) and save it as $N for later reference.
Array (array)
Generates an array of random integers.
Parameters:
type: Set to'array'size: The size of the array (can be a fixed number or a reference to a previously saved variable)element_type: Currently only supports'int'limit: A list of two integers[min, max]specifying the range for each element (inclusive)save_as(optional): A variable name to save the generated array for later reference
Example:
{'type': 'array', 'size': '$N', 'element_type': 'int', 'limit': [1, 1000], 'save_as': '$arr'}
This will generate an array of $N integers, each between 1 and 1000, and save it as $arr.
2D Array (2d_array)
Generates a 2D array (matrix) of random integers.
Parameters:
type: Set to'2d_array'rows: The number of rows in the 2D arraycols: The number of columns in the 2D arrayelement_type: Currently only supports'int'limit: A list of two integers[min, max]specifying the range for each element (inclusive)save_as(optional): A variable name to save the generated 2D array for later reference
Example:
{'type': '2d_array', 'rows': '$M', 'cols': '$N', 'element_type': 'int', 'limit': [0, 100], 'save_as': '$matrix'}
This will generate a 2D array with $M rows and $N columns, filled with integers between 0 and 100, and save it as $matrix.
String (string)
Generates a random string of lowercase letters.
Parameters:
type: Set to'string'length: The length of the string (can be a fixed number or a reference to a previously saved variable)save_as(optional): A variable name to save the generated string for later reference
Example:
{'type': 'string', 'length': 10, 'save_as': '$str'}
This will generate a random string of 10 lowercase letters and save it as $str.
Newline (newline)
Inserts a newline character.
Parameters:
type: Set to'newline'
Example:
{'type': 'newline'}
This will insert a newline character in the output.
Space (space)
Inserts a single space character.
Parameters:
type: Set to'space'
Example:
{'type': 'space'}
This will insert a single space character in the output.
Repeat Character (repeat_char)
Repeats a specified character a given number of times.
Parameters:
type: Set to'repeat_char'char: The character to repeatcount: The number of times to repeat the charactersave_as(optional): A variable name to save the generated string for later reference
Example:
{'type': 'repeat_char', 'char': '*', 'count': '$N', 'save_as': '$stars'}
This will repeat the * character $N times and save the result as $stars.
Repeat Type (repeat_type)
Repeats a specified input type generation a given number of times.
Parameters:
type: Set to'repeat_type'count: The number of times to repeat the specified input typespec: The specification of the input type to repeatsave_as(optional): A variable name to save the generated values for later reference
Example:
{'type': 'repeat_type', 'count': '$M', 'spec': {'type': 'int', 'limit': [0, 9]}, 'save_as': '$digits'}
This will generate $M random digits (0-9) and save them as $digits.
Loop (loop)
Repeats a set of input specifications a specified number of times.
Parameters:
type: Set to'loop'count: The number of times to repeat the loopspec: A list of input specifications to repeatsave_as(optional): A variable name to save the current loop index for use within the loop
Example:
{'type': 'loop', 'count': '$T', 'save_as': '$test_case', 'spec': [
{'type': 'int', 'limit': [1, 100], 'save_as': '$N'},
{'type': 'space'},
{'type': 'array', 'size': '$N', 'element_type': 'int', 'limit': [1, 1000]},
{'type': 'newline'}
]}
This will repeat the generation of an integer $N, a space, and an array of size $N for $T times, representing $T test cases.
Advanced Example
Here's a comprehensive example that demonstrates the use of various input types:
from algomock import InputGenerator
spec = [
{'type': 'int', 'limit': [1, 5], 'save_as': '$T'}, # Number of test cases
{'type': 'newline'},
{'type': 'loop', 'count': '$T', 'save_as': '$test_case', 'spec': [
{'type': 'int', 'limit': [1, 10], 'save_as': '$N'}, # N
{'type': 'space'},
{'type': 'int', 'limit': [1, '$N'], 'save_as': '$M'}, # M, upper limit depends on N
{'type': 'newline'},
{'type': 'repeat_char', 'char': '*', 'count': '$N', 'save_as': '$stars'}, # Repeat '*' N times
{'type': 'newline'},
{'type': 'repeat_type', 'count': '$M', 'spec': { # Repeat a random digit M times
'type': 'int',
'limit': [0, 9]
}, 'save_as': '$digits'},
{'type': 'newline'},
{'type': 'array', 'size': '$N', 'limit': [1, 100], 'save_as': '$array'}, # Array of size N
{'type': 'newline'},
{'type': '2d_array', 'rows': '$M', 'cols': '$N', 'limit': [0, 100], 'save_as': '$matrix'}, # 2D array of size M x N
{'type': 'newline'},
{'type': 'string', 'length': '$M', 'save_as': '$str'}, # String of length M
{'type': 'newline'},
{'type': 'int', 'limit': [0, '$test_case'], 'save_as': '$index'}, # An integer between 0 and the current loop index
{'type': 'newline'}
]}
]
generator = InputGenerator()
input_data = generator.generate_input(spec)
print(input_data)
This example generates multiple test cases, each with various types of input data, demonstrating the flexibility of AlgoMock.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for algomock 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| algomock-0.2.0.tar.gz | 5.8 kB | Without provenance | Details for algomock-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| algomock-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for algomock-0.2.0-py3-none-any.whl |
Total release size: 12.5 kB
Release files / algomock-0.2.0.tar.gz
| Download URL | algomock-0.2.0.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d569e099bfeeb333a6107fb850d032d1b2611f001d6fdf0c9f8cf8f0ad04cce1
|
|
BLAKE2b-256 checksum How to use checksums |
6a12cf854b25f35102c2af8627568d491389386409b4e28816babbffcd048fbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.5
|
Release files / algomock-0.2.0-py3-none-any.whl
| Download URL | algomock-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8e26181febedb3117144f971fa09f0211fa844bd8c949997064a6aa568bb8b5f
|
|
BLAKE2b-256 checksum How to use checksums |
b011d621f86a8dd5a4f29861bda6fa3a3af1f4576a090c32d42a118e6906536b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.5
|
Security for algomock 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.