summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/arbitrary/boost_optional.cc1
-rw-r--r--tests/arbitrary/boost_optional.hpp60
2 files changed, 61 insertions, 0 deletions
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 <boost/optional.hpp>
+#include <boost/optional/optional_io.hpp>
+#include <cppqc/Arbitrary.h>
+
+namespace cppqc {
+
+template<typename T>
+boost::optional<T> arbitraryBoostOptional(RngEngine &rng, std::size_t size)
+{
+ std::uniform_int_distribution<> distribution(0, 4);
+
+ if (distribution(rng) == 0)
+ {
+ return boost::none;
+ }
+ else
+ {
+ return Arbitrary<T>::unGen(rng, size);
+ }
+}
+
+template<typename T>
+std::vector<boost::optional<T>> shrinkBoostOptional(boost::optional<T> shrinkInput)
+{
+ std::vector<boost::optional<T>> result;
+
+ if (shrinkInput)
+ {
+ result.push_back(boost::none);
+
+ for (auto const &t: Arbitrary<T>::shrink(*shrinkInput))
+ {
+ result.push_back(t);
+ }
+ }
+
+ return result;
+}
+
+template <typename T>
+class ArbitraryImpl<boost::optional<T>> {
+
+public:
+ static const typename Arbitrary<boost::optional<T>>::unGenType unGen;
+
+ static const typename Arbitrary<boost::optional<T>>::shrinkType shrink;
+
+};
+
+template <typename T>
+const typename Arbitrary<boost::optional<T>>::unGenType
+ArbitraryImpl<boost::optional<T>>::unGen = arbitraryBoostOptional<T>;
+
+template <typename T>
+const typename Arbitrary<boost::optional<T>>::shrinkType
+ArbitraryImpl<boost::optional<T>>::shrink = shrinkBoostOptional<T>;
+
+} // namespace cppqc