ZeroErr
δΈ/En
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
10
template
<
typename
T>
11
class
ElementOf
:
public
Domain
<T, uint64_t> {
12
public
:
13
using
ValueType
= T;
14
using
CorpusType
= uint64_t;
15
16
std::vector<T>
elements
;
17
18
ElementOf
(std::vector<T>
elements
) :
elements
(
elements
) {}
19
20
CorpusType
GetRandomCorpus
(
Rng
& rng)
override
{
return
rng.
bounded
(
elements
.size()); }
21
22
ValueType
GetValue
(
const
CorpusType
& v)
const override
{
return
elements
[v]; }
23
24
CorpusType
FromValue
(
const
ValueType
& v)
const override
{
25
for
(
size_t
i = 0; i <
elements
.size(); i++) {
26
if
(
elements
[i] == v)
return
i;
27
}
28
return
0;
29
}
30
31
void
Mutate
(
Rng
& rng,
CorpusType
& v,
bool
only_shrink)
const override
{
32
if
(
elements
.size() <= 1)
return
;
33
if
(only_shrink) {
34
v = rng.
bounded
(v);
35
}
else
{
36
v = rng.
bounded
(
elements
.size());
37
}
38
}
39
};
40
41
}
// namespace zeroerr
42
43
ZEROERR_SUPPRESS_COMMON_WARNINGS_POP
zeroerr::Domain
Domain class for generating random values of a specific type.
Definition:
domain.h:22
zeroerr::ElementOf
Definition:
element_of.h:11
zeroerr::ElementOf::ElementOf
ElementOf(std::vector< T > elements)
Definition:
element_of.h:18
zeroerr::ElementOf::ValueType
T ValueType
Definition:
element_of.h:13
zeroerr::ElementOf::GetValue
ValueType GetValue(const CorpusType &v) const override
Definition:
element_of.h:22
zeroerr::ElementOf::FromValue
CorpusType FromValue(const ValueType &v) const override
Definition:
element_of.h:24
zeroerr::ElementOf::GetRandomCorpus
CorpusType GetRandomCorpus(Rng &rng) override
Definition:
element_of.h:20
zeroerr::ElementOf::CorpusType
uint64_t CorpusType
Definition:
element_of.h:14
zeroerr::ElementOf::elements
std::vector< T > elements
Definition:
element_of.h:16
zeroerr::ElementOf::Mutate
void Mutate(Rng &rng, CorpusType &v, bool only_shrink) const override
Definition:
element_of.h:31
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.1