The library works using ValueGenerators (not python generators) and Arbitrary classes.
# Test
Test is container that holds name, arbitrary and value provided by said arbitrary. The test also contains functions `shrink` and `to_str` (using `to_str` from arbitrary on value).
Test is container that holds name, arbitrary and value provided by said arbitrary (if you use constructor with None, it will generate value using arbitrary). The test also contains functions `shrink` and `to_str` (both just use the functions from arbitrary on the value held by the test).
# Tester
Tester is abstract class, the most important function `run_test(test: Test[G])` is not defined.
Tester is abstract class, the most important function `run_test(test: Test[G])` is not defined. Tester defines how shrinking works etc.
# RefImlTester
Tester that runs tests on your implementation and the reference implementation, then runs your process output tests on the outputs.
Tester that runs tests on your implementation and the reference implementation, then runs your 'process output tests' on the outputs. More below.
## ProcessOutputTest
...
...
@@ -58,18 +54,22 @@ tester.save_tests()
# Arbitraries
`Arbitrary[T]`
`Arbitrary[T]` defines an object capable of providing arbitrary value with type `T`, shrinking value of type `T` to a simpler instance and converting value of type `T` to `str`.
To define your custom Arbitrary, either extend one of the predefined structures (below) or extend Arbitrary. Note that you have to define functions `shrink`, you don't have to define `to_str` but it will probably create undesirable output. The function `get` uses the value generator from the constructor.
The constructor of `Arbitrary[T]` takes ValueGenerator, function with type `Callable[[], T]`, this function is used in get(). There are some predefined value generatos, see ValueGenerator section.
### Get
`get() -> T`
returns arbitrary value generated by the Arbitrary
returns arbitrary value
### Shrink
`shrink(value: T) -> List[T]`
shrinks any value created by the Arbitrary to simpler value
shrinks any value (created by the Arbitrary) to simpler value
### To string
`to_str(value: T) -> str`
...
...
@@ -102,3 +102,25 @@ shrinks value to: shorter lists
get returns: tuple (index of chosen arb, value generated by that arb), choice is random
shrinks value to: tuples with shrunk values (index of the chosen arb, value shrunk using said arb)
# ValueGenerator
There are some predefined factories. Note that you have to CALL the factory, to recieve value generator.
*- = returns generator that creates
## predefined value generators creators
### Atomic
-`intiger_gen(min_value: int, max_value: int)`*- random intiger in range [min_value, max_value)
-`pos_intiger_gen(max_value: int)`*- random intiger in range [1, max_valaue)
-`lower_case_let_gen()`*- lower case letter
-`upper_case_let_gen()`*- upper case letter
### Generic
-`constant_gen(const: T)`*- the constant
-`oneof_gen(constants: List[T])`*- one of the constants
-`vector_gen(gen: Callable[[], T], size: int)`*- list with constant size with elements generated by the generator
-`listof_gen(gen: Callable[[], T], min_size: int, max_size: int)`*- list with random size [min_value, max_value) with elements generated by the generator
-`tupleof_gen(generators: List[ValueGenerator])`*- tuple created from the values of the different generators
-`choices_gen(choices: List[Tuple[int, Callable[[], T]]])`*- choices are list of tuples in form (weight, generator), generates value created by one of the generators, chooses using weighted random