From d7533e931cfb49a68dc8e6e3f524d49e364cef83 Mon Sep 17 00:00:00 2001 From: Manoj Srivastava Date: Wed, 27 May 2020 16:31:00 -0700 Subject: New upstream version 2.41-ah~0.git.20200131 --- tests/arbitrary/boost_optional.cc | 1 + tests/arbitrary/boost_optional.hpp | 60 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tests/arbitrary/boost_optional.cc create mode 100644 tests/arbitrary/boost_optional.hpp (limited to 'tests') diff --git a/tests/arbitrary/boost_optional.cc b/tests/arbitrary/boost_optional.cc new file mode 100644 index 00000000..36b0b770 --- /dev/null +++ b/tests/arbitrary/boost_optional.cc @@ -0,0 +1 @@ +#include "boost_optional.hpp" diff --git a/tests/arbitrary/boost_optional.hpp b/tests/arbitrary/boost_optional.hpp new file mode 100644 index 00000000..445e8aca --- /dev/null +++ b/tests/arbitrary/boost_optional.hpp @@ -0,0 +1,60 @@ +#pragma once + +#include +#include +#include + +namespace cppqc { + +template +boost::optional arbitraryBoostOptional(RngEngine &rng, std::size_t size) +{ + std::uniform_int_distribution<> distribution(0, 4); + + if (distribution(rng) == 0) + { + return boost::none; + } + else + { + return Arbitrary::unGen(rng, size); + } +} + +template +std::vector> shrinkBoostOptional(boost::optional shrinkInput) +{ + std::vector> result; + + if (shrinkInput) + { + result.push_back(boost::none); + + for (auto const &t: Arbitrary::shrink(*shrinkInput)) + { + result.push_back(t); + } + } + + return result; +} + +template +class ArbitraryImpl> { + +public: + static const typename Arbitrary>::unGenType unGen; + + static const typename Arbitrary>::shrinkType shrink; + +}; + +template +const typename Arbitrary>::unGenType +ArbitraryImpl>::unGen = arbitraryBoostOptional; + +template +const typename Arbitrary>::shrinkType +ArbitraryImpl>::shrink = shrinkBoostOptional; + +} // namespace cppqc -- cgit v1.2.3