This is a test generator for Programming Contest tasks. Application reads a test description and generate a set of tests (text files) that satisfy the description.
- CMake 3.28 or later
- C++17 compiler
- yaml-cpp library
Download the source code and build the application using the following commands:
mkdir build
cd build
cmake ../src
cmake --build ../testgenerator <test_description_file>You can generate a sample of the test description file using the following command:
./testgenerator --sampleTest description file is a YAML file that contains the following fields:
filename: pattern for test files, the percent (%) sign is replaced with the test numberfrom: start number of tests to generateto: end number of tests to generatedescription: description of the test (?) - not usedblock: block of lines
Example:
filename: "input%.txt"
from: 1
to: 10
description: "Test description"
blocks: # blocks of lines
- nr_of_lines: 1 # number of lines in the block
line: # line definition
- type: integer
min: 1
max: 100
name: N
- type: integer
min: 1
max: 100
name: M
- nr_of_lines: N # number of lines in the block
line: # line definition
- type: array
size: M
element:
type: integer
min: -100
max: 100
# other blocksStructure of the test defines blocks of lines. Block of lines contain number of lines with the same structure and line definition. Line can contain one or more elements.
Each element can be of the following types:
- integer
- float
- string
- array of integers
- array of floats
- array of strings
For each integer you can define a range of values, also can have a name for reference in the next lines.
For each float you can define a range of values and maximal number of digits in the decimal part.
For each string, you can define minimal and maximal length and allowed symbols.
For each array, you can define a number of elements and a range of values for each element. Number of elements can be a constant or a reference to the previous lines. Array can be generated ordered or unordered.
type: integer
min: 1
max: 100
name: Ntype: float
min: 0.0
max: 1.0
digits: 2If digits is not defined, the number of digits is not limited (number is not truncated).
type: string
min_length: 1
max_length: 10
characters: "abc"type: array
size: 5
order: asc # optional, can be 'asc', 'desc', or 'unordered'. default is 'unordered'.
element:
type: integer
min: 1
max: 100type: array
size: 5
element:
type: float
min: 0.0
max: 1.0
digits: 2type: array
size: 5
element:
type: string
min_length: 1
max_length: 10
characters: "abc"This example defines 10 tests. Test contains 2 lines. First line contains one integer N value in the range from 1 to 100. Second line contains N integer values in the range from -100 to 100.
filename: "input%.txt"
from: 1
to: 10
description: "Test description"
blocks:
- nr_of_lines: 1
line:
- type: integer
min: 1
max: 100
name: N
- type: integer
min: 1
max: 100
name: M
- nr_of_lines: N
line:
- type: array
size: M
element:
type: string
min_length: 10
max_length: 10
characters: "abc"Yet another sample, with multiple document definition:
---
# simple tests
filename: "input%.txt"
from: 1
to: 3
description: "Test description"
blocks:
- nr_of_lines: 1
line:
- type: integer
min: 1
max: 100
- type: integer
min: 1
max: 100
---
# medium tests
filename: "input%.txt"
from: 4
to: 7
description: "Test description"
blocks:
- nr_of_lines: 1
line:
- type: integer
min: 100
max: 1000
- type: integer
min: 100
max: 1000
---
# complex tests
filename: "input%.txt"
from: 8
to: 10
description: "Test description"
blocks:
- nr_of_lines: 1
line:
- type: integer
min: 1000
max: 10000
- type: integer
min: 1000
max: 10000This sample will generate:
- 3 files with 2 integers in the line, values between 1 and 100
- 4 files with 2 integers in the line, values between 100 and 1000
- 3 files with 2 integers in the line, values between 1000 and 10000
This example defines 10 tests. Each test contains N number of lines in the first line and M number of elements in the line. The next N lines contain M integer values in the range from -100 to 100.
filename: "input%.txt"
from: 1
to: 10
description: "Test description"
blocks:
lines:
- nr_of_lines: 1
line:
- type: integer
min: 1
max: 100
name: N
- type: integer
min: 1
max: 100
name: M
- nr_of_lines: N
line:
type: string
min_length: 1
max_length: M
- define more than one element in the line
- define more than one test definition in the file
- define lines generator