ZeroErr
δΈ/En
Loading...
Searching...
No Matches
element_of.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
zeroerr/domains/domain.h
"
4
#include "
zeroerr/internal/config.h
"
5
6
ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
7
8
namespace
zeroerr
{
9
27
template
<
typename
T>
28
class
ElementOf
:
public
Domain
<T, uint64_t> {
29
public
:
30
using
ValueType
= T;
31
using
CorpusType
= uint64_t;
32
33
std::vector<T>
elements
;
34
35
ElementOf
(std::vector<T>
elements
) :
elements
(
elements
) {}
36
37
CorpusType
GetRandomCorpus
(
Rng
& rng)
override
{
return
rng.
bounded
(
elements
.size()); }
38
39
ValueType
GetValue
(
const
CorpusType
& v)
const override
{
return
elements
[v]; }
40
41
CorpusType
FromValue
(
const
ValueType
& v)
const override
{
42
for
(
size_t
i = 0; i <
elements
.size(); i++) {
43
if
(
elements
[i] == v)
return
i;
44
}
45
return
0;
46
}
47
48
void
Mutate
(
Rng
& rng,
CorpusType
& v,
bool
only_shrink)
const override
{
49
if
(
elements
.size() <= 1)
return
;
50
if
(only_shrink) {
51
v = rng.
bounded
(v);
52
}
else
{
53
v = rng.
bounded
(
elements
.size());
54
}
55
}
56
};
57
58
}
// namespace zeroerr
59
60
ZEROERR_SUPPRESS_COMMON_WARNINGS_POP
zeroerr::Domain
Domain class for generating random values of a specific type.
Definition
domain.h:21
zeroerr::ElementOf
ElementOf is a domain that generates random values from a fixed set of elements.
Definition
element_of.h:28
zeroerr::ElementOf::ElementOf
ElementOf(std::vector< T > elements)
Definition
element_of.h:35
zeroerr::ElementOf::ValueType
T ValueType
Definition
element_of.h:30
zeroerr::ElementOf::GetValue
ValueType GetValue(const CorpusType &v) const override
Definition
element_of.h:39
zeroerr::ElementOf::FromValue
CorpusType FromValue(const ValueType &v) const override
Definition
element_of.h:41
zeroerr::ElementOf::GetRandomCorpus
CorpusType GetRandomCorpus(Rng &rng) override
Definition
element_of.h:37
zeroerr::ElementOf::CorpusType
uint64_t CorpusType
Definition
element_of.h:31
zeroerr::ElementOf::elements
std::vector< T > elements
Definition
element_of.h:33
zeroerr::ElementOf::Mutate
void Mutate(Rng &rng, CorpusType &v, bool only_shrink) const override
Definition
element_of.h:48
zeroerr::Rng
Definition
rng.h:30
zeroerr::Rng::bounded
uint32_t bounded(uint32_t range) noexcept
Definition
rng.h:126
config.h
ZEROERR_SUPPRESS_COMMON_WARNINGS_POP
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_POP
Definition
config.h:265
ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
Definition
config.h:218
domain.h
zeroerr
Definition
benchmark.cpp:17
include
zeroerr
domains
element_of.h
Generated by
1.9.8