ZeroErr
domain.h
Go to the documentation of this file.
1 #pragma once
3 
4 #include "zeroerr/internal/rng.h"
6 
8 
9 namespace zeroerr {
10 
11 
21 template <typename ValueType, typename CorpusType = ValueType>
22 class Domain {
23 public:
24  virtual ~Domain() = default;
25 
26  virtual CorpusType GetRandomCorpus(Rng& rng) const = 0;
27  virtual ValueType GetRandomValue(Rng& rng) const { return GetValue(GetRandomCorpus(rng)); };
28 
29  virtual CorpusType FromValue(const ValueType& v) const = 0;
30  virtual ValueType GetValue(const CorpusType& v) const = 0;
31 
32  virtual CorpusType ParseCorpus(IRObject v) const { return IRObject::ToCorpus<CorpusType>(v); }
33  virtual IRObject SerializeCorpus(const CorpusType& v) const { return IRObject::FromCorpus(v); }
34 
35  virtual void Mutate(Rng& rng, CorpusType& v, bool only_shrink = false) const = 0;
36  // virtual void MutateSelectedField(Rng& rng, CorpusType& v, unsigned field,
37  // bool only_shrink = false) const {}
38  // virtual unsigned CountNumberOfFields(CorpusType v) const { return 0; }
39 };
40 
41 template <typename ValueType, typename CorpusType = ValueType>
42 class DomainConvertable : public Domain<ValueType, CorpusType> {
43 public:
44  virtual ValueType GetValue(const CorpusType& v) const { return v; }
45  virtual CorpusType FromValue(const ValueType& v) const { return v; }
46 };
47 
48 
49 } // namespace zeroerr
50 
Definition: domain.h:42
virtual ValueType GetValue(const CorpusType &v) const
Definition: domain.h:44
virtual CorpusType FromValue(const ValueType &v) const
Definition: domain.h:45
Domain class for generating random values of a specific type.
Definition: domain.h:22
virtual ValueType GetValue(const CorpusType &v) const =0
virtual void Mutate(Rng &rng, CorpusType &v, bool only_shrink=false) const =0
virtual ValueType GetRandomValue(Rng &rng) const
Definition: domain.h:27
virtual CorpusType GetRandomCorpus(Rng &rng) const =0
virtual ~Domain()=default
virtual IRObject SerializeCorpus(const CorpusType &v) const
Definition: domain.h:33
virtual CorpusType FromValue(const ValueType &v) const =0
virtual CorpusType ParseCorpus(IRObject v) const
Definition: domain.h:32
Definition: rng.h:30
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_POP
Definition: config.h:265
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
Definition: config.h:218
Definition: benchmark.cpp:17
Definition: serialization.h:17
static std::enable_if< std::is_integral< T >::value||std::is_floating_point< T >::value||std::is_same< T, std::string >::value||std::is_enum< T >::value, IRObject >::type FromCorpus(T val)
Definition: serialization.h:119