ZeroErr
Loading...
Searching...
No Matches
in_range.h
Go to the documentation of this file.
1#pragma once
2
5
7
8namespace zeroerr {
9
27template <typename T>
28class InRange : public DomainConvertable<T> {
29public:
30 using ValueType = T;
31 using CorpusType = T;
32
34
35 InRange(T min, T max) : min(min), max(max) {}
36
37 CorpusType GetRandomCorpus(Rng& rng) const override {
38 ValueType offsize = max - min + 1;
39 ValueType v = rng.bounded(offsize);
40 v = min + v;
41 return v;
42 }
43
44 void Mutate(Rng& rng, CorpusType& v, bool only_shrink) const override {
45 CorpusType offsize = max - min + 1;
46 v = rng.bounded(offsize);
47 v = min + v;
48 }
49};
50
51} // namespace zeroerr
52
DomainConvertable is a base class for domains that can be converted to and from a ValueType.
Definition domain.h:48
InRange is a domain that generates random values within a specified range.
Definition in_range.h:28
ValueType max
Definition in_range.h:33
InRange(T min, T max)
Definition in_range.h:35
ValueType min
Definition in_range.h:33
T CorpusType
Definition in_range.h:31
CorpusType GetRandomCorpus(Rng &rng) const override
Definition in_range.h:37
T ValueType
Definition in_range.h:30
void Mutate(Rng &rng, CorpusType &v, bool only_shrink) const override
Definition in_range.h:44
Definition rng.h:30
uint32_t bounded(uint32_t range) noexcept
Definition rng.h:126
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_POP
Definition config.h:265
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
Definition config.h:218
Definition benchmark.cpp:17