Introduce random number (Integral and Float) generators

This commit is contained in:
Martin Hořeňovský
2019-02-19 22:09:14 +01:00
parent e8bfd882e8
commit 269303d9d9
5 changed files with 107 additions and 2 deletions

View File

@@ -43,6 +43,9 @@ a test case,
* `RepeatGenerator<T>` -- repeats output from a generator `n` times
* `MapGenerator<T, U, Func>` -- returns the result of applying `Func`
on elements from a different generator
* 2 specific purpose generators
* `RandomIntegerGenerator<Integral>` -- generates random Integrals from range
* `RandomFloatGenerator<Float>` -- generates random Floats from range
The generators also have associated helper functions that infer their
type, making their usage much nicer. These are
@@ -54,6 +57,7 @@ type, making their usage much nicer. These are
* `repeat(repeats, GeneratorWrapper<T>&&)` for `RepeatGenerator<T>`
* `map(func, GeneratorWrapper<T>&&)` for `MapGenerator<T, T, Func>` (map `T` to `T`)
* `map<T>(func, GeneratorWrapper<U>&&)` for `MapGenerator<T, U, Func>` (map `U` to `T`)
* `range(IntegerOrFloat a, IntegerOrFloat b)` for `RandomIntegerGenerator` or `RandomFloatGenerator`
And can be used as shown in the example below to create a generator
that returns 100 odd random number:
@@ -69,8 +73,6 @@ TEST_CASE("Generating random ints", "[example][generator]") {
}
```
_Note that `random` is currently not a part of the first-party generators_.
Apart from registering generators with Catch2, the `GENERATE` macro has
one more purpose, and that is to provide simple way of generating trivial