summaryrefslogtreecommitdiff
path: root/vendor/CppQuickCheck-2018-03-28/examples/src
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/CppQuickCheck-2018-03-28/examples/src')
-rw-r--r--vendor/CppQuickCheck-2018-03-28/examples/src/BoostTupleSupport.cpp131
-rw-r--r--vendor/CppQuickCheck-2018-03-28/examples/src/TestChooseGenerator.cpp54
-rw-r--r--vendor/CppQuickCheck-2018-03-28/examples/src/TestReverse.cpp59
-rw-r--r--vendor/CppQuickCheck-2018-03-28/examples/src/TestReverseArray.cpp69
-rw-r--r--vendor/CppQuickCheck-2018-03-28/examples/src/TestSlowShrinking.cpp61
-rw-r--r--vendor/CppQuickCheck-2018-03-28/examples/src/TestSort.cpp79
-rw-r--r--vendor/CppQuickCheck-2018-03-28/examples/src/TestSortCompact.cpp95
-rw-r--r--vendor/CppQuickCheck-2018-03-28/examples/src/TestWithCustomGenerator.cpp86
-rw-r--r--vendor/CppQuickCheck-2018-03-28/examples/src/exampleElementsGen.cpp55
-rw-r--r--vendor/CppQuickCheck-2018-03-28/examples/src/sampleOutput.cpp73
-rw-r--r--vendor/CppQuickCheck-2018-03-28/examples/src/sampleShrinkOutput.cpp82
11 files changed, 844 insertions, 0 deletions
diff --git a/vendor/CppQuickCheck-2018-03-28/examples/src/BoostTupleSupport.cpp b/vendor/CppQuickCheck-2018-03-28/examples/src/BoostTupleSupport.cpp
new file mode 100644
index 00000000..72a5f17d
--- /dev/null
+++ b/vendor/CppQuickCheck-2018-03-28/examples/src/BoostTupleSupport.cpp
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2015, Gregory Rogers All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// It demonstrates how to add support for boost::tuple by
+// writing a custom generator (using std::tuple).
+//
+// Note this file uses C++14 features.
+
+#include "cppqc.h"
+
+#include <boost/tuple/tuple.hpp>
+#include "boost/tuple/tuple_comparison.hpp"
+#include <boost/tuple/tuple_io.hpp>
+#include <utility>
+
+using namespace cppqc;
+
+namespace {
+
+ template <typename StdTuple, std::size_t... Is>
+ auto asBoostTuple(StdTuple &&stdTuple, std::index_sequence<Is...>) {
+ return boost::tuple<std::tuple_element_t<Is, std::decay_t<StdTuple>>...>
+ (std::get<Is>(std::forward<StdTuple>(stdTuple))...);
+ }
+
+ template <typename BoostTuple, std::size_t... Is>
+ auto asStdTuple(BoostTuple &&boostTuple, std::index_sequence<Is...>) {
+ return std::tuple<typename boost::tuples::element<Is, std::decay_t<BoostTuple>>::type...>
+ (boost::get<Is>(std::forward<BoostTuple>(boostTuple))...);
+ }
+
+ template <typename StdTuple>
+ auto asBoostTuple(StdTuple &&stdTuple) {
+ return asBoostTuple(std::forward<StdTuple>(stdTuple),
+ std::make_index_sequence<std::tuple_size<std::decay_t<StdTuple>>::value>());
+ }
+
+ template <typename BoostTuple>
+ auto asStdTuple(BoostTuple&& boostTuple) {
+ return asStdTuple(std::forward<BoostTuple>(boostTuple),
+ std::make_index_sequence<boost::tuples::length<std::decay_t<BoostTuple>>::value>());
+ }
+
+ template<typename... T>
+ struct BoostTupleGenerator
+ {
+ BoostTupleGenerator(const Generator<T> &...g) :
+ m_tupleGenerator(tupleOf(g...))
+ {
+ }
+
+ boost::tuple<T...> unGen(RngEngine &rng, std::size_t size) const
+ {
+ return asBoostTuple(m_tupleGenerator.unGen(rng, size));
+ }
+
+ std::vector<boost::tuple<T...>> shrink(boost::tuple<T...> shrinkInput) const
+ {
+ std::vector<boost::tuple<T...>> result;
+ for (const auto &shrink : m_tupleGenerator.shrink(asStdTuple(shrinkInput))) {
+ result.push_back(asBoostTuple(shrink));
+ }
+ return result;
+ }
+
+ private:
+
+ Generator<std::tuple<T...>> m_tupleGenerator;
+ };
+
+}
+
+template<typename... T>
+Generator<boost::tuple<T...>> boostTupleOf(const Generator<T> &...g)
+{
+ return BoostTupleGenerator<T...>(g...);
+}
+
+template<typename... T>
+Generator<boost::tuple<T...>> boostTupleOf()
+{
+ return BoostTupleGenerator<T...>(Arbitrary<T>()...);
+}
+
+
+struct AntisymmetricRelationProp : Property<boost::tuple<int, std::string, int>,
+ boost::tuple<int, std::string, int>>
+{
+ AntisymmetricRelationProp() : Property(
+ boostTupleOf<int, std::string, int>(),
+ boostTupleOf<int, std::string, int>())
+ {}
+
+ bool check(const boost::tuple<int, std::string, int> &v1,
+ const boost::tuple<int, std::string, int> &v2) const override
+ {
+ return (v1 <= v2 && v1 >= v2) == (v1 == v2);
+ }
+
+ std::string name() const override
+ {
+ return "Comparison must be antisymmetric";
+ }
+};
+
+int main()
+{
+ cppqc::quickCheckOutput(AntisymmetricRelationProp());
+}
diff --git a/vendor/CppQuickCheck-2018-03-28/examples/src/TestChooseGenerator.cpp b/vendor/CppQuickCheck-2018-03-28/examples/src/TestChooseGenerator.cpp
new file mode 100644
index 00000000..25d69aa4
--- /dev/null
+++ b/vendor/CppQuickCheck-2018-03-28/examples/src/TestChooseGenerator.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2010, Gregory Rogers All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "cppqc.h"
+
+// This property tests that A*A > A holds.
+//
+// In general, this is not true, for instance, if A is zero.
+// However, by using the "choose" generator, we can define that
+// A is in a given interval (between 2 and 1000 in this example).
+struct AxA_isGreaterThan_A : cppqc::Property<int>
+{
+ static constexpr int MIN = 2;
+ static constexpr int MAX = 1000;
+
+ AxA_isGreaterThan_A() : Property(cppqc::choose(MIN, MAX)) {}
+
+ bool check(const int &A) const override
+ {
+ return A * A > A;
+ }
+
+ std::string name() const override
+ {
+ return "A*A > A";
+ }
+};
+
+int main()
+{
+ cppqc::quickCheckOutput(AxA_isGreaterThan_A());
+}
diff --git a/vendor/CppQuickCheck-2018-03-28/examples/src/TestReverse.cpp b/vendor/CppQuickCheck-2018-03-28/examples/src/TestReverse.cpp
new file mode 100644
index 00000000..751e19c5
--- /dev/null
+++ b/vendor/CppQuickCheck-2018-03-28/examples/src/TestReverse.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2010, Gregory Rogers All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "cppqc.h"
+
+#include <algorithm>
+#include <sstream>
+
+struct PropTestReverse : cppqc::Property<std::vector<int>>
+{
+ bool check(const std::vector<int> &v) const override
+ {
+ std::vector<int> vrev(v);
+ std::reverse(vrev.begin(), vrev.end());
+ std::reverse(vrev.begin(), vrev.end());
+ return std::equal(v.begin(), v.end(), vrev.begin());
+ }
+ std::string name() const override
+ {
+ return "Reversing Twice is Identity";
+ }
+ std::string classify(const std::vector<int> &v) const override
+ {
+ std::ostringstream sstr;
+ sstr << "size " << v.size();
+ return sstr.str();
+ }
+ bool trivial(const std::vector<int> &v) const override
+ {
+ return v.empty() || v.size() == 1;
+ }
+};
+
+int main()
+{
+ cppqc::quickCheckOutput(PropTestReverse());
+}
diff --git a/vendor/CppQuickCheck-2018-03-28/examples/src/TestReverseArray.cpp b/vendor/CppQuickCheck-2018-03-28/examples/src/TestReverseArray.cpp
new file mode 100644
index 00000000..02ba1956
--- /dev/null
+++ b/vendor/CppQuickCheck-2018-03-28/examples/src/TestReverseArray.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2014, Gregory Rogers All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "cppqc.h"
+
+#include <algorithm>
+#include <boost/static_assert.hpp>
+
+const int ArraySize = 5;
+
+struct PropTestArrayReverse :
+ cppqc::Property<std::array<std::string, ArraySize>>
+{
+ bool check(const std::array<std::string, ArraySize> &v) const override
+ {
+ auto vrev = v;
+ std::reverse(vrev.begin(), vrev.end());
+ std::reverse(vrev.begin(), vrev.end());
+ return std::equal(v.begin(), v.end(), vrev.begin());
+ }
+ std::string name() const override
+ {
+ return "Reversing Twice is Identity";
+ }
+};
+
+struct PropTestBoolArrayReverse :
+ cppqc::Property<std::array<bool, ArraySize>>
+{
+ bool check(const std::array<bool, ArraySize> &v) const override
+ {
+ auto vrev = v;
+ std::reverse(vrev.begin(), vrev.end());
+ std::reverse(vrev.begin(), vrev.end());
+ return std::equal(v.begin(), v.end(), vrev.begin());
+ }
+ std::string name() const override
+ {
+ return "Reversing Twice is Identity";
+ }
+};
+
+int main()
+{
+ cppqc::quickCheckOutput(PropTestArrayReverse());
+ cppqc::quickCheckOutput(PropTestBoolArrayReverse());
+}
diff --git a/vendor/CppQuickCheck-2018-03-28/examples/src/TestSlowShrinking.cpp b/vendor/CppQuickCheck-2018-03-28/examples/src/TestSlowShrinking.cpp
new file mode 100644
index 00000000..641016c4
--- /dev/null
+++ b/vendor/CppQuickCheck-2018-03-28/examples/src/TestSlowShrinking.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2016, Philipp Classen All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "cppqc.h"
+
+#include <vector>
+#include <chrono>
+#include <thread>
+#include <atomic>
+
+// This simulates a test that is extremely slow. For such tests,
+// shrinking can become a problem, as it can take quite a while.
+struct PropTestSlowFunction: cppqc::Property<std::vector<int>>
+{
+ mutable std::atomic<bool> shrinking{false};
+
+ bool check(const std::vector<int> &v) const override
+ {
+ if (shrinking) {
+ std::cout << "Sleeping..." << std::endl;
+ std::this_thread::sleep_for(std::chrono::seconds(1));
+ }
+
+ if (v.size() >= 4 && (v[3] % 5) == 1) {
+ shrinking = true;
+ return false;
+ }
+ return true;
+ }
+ std::string name() const override
+ {
+ return "Sorting should be sorted";
+ }
+};
+
+int main()
+{
+ cppqc::quickCheckOutput(PropTestSlowFunction());
+}
diff --git a/vendor/CppQuickCheck-2018-03-28/examples/src/TestSort.cpp b/vendor/CppQuickCheck-2018-03-28/examples/src/TestSort.cpp
new file mode 100644
index 00000000..f5e3c4dc
--- /dev/null
+++ b/vendor/CppQuickCheck-2018-03-28/examples/src/TestSort.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2010, Gregory Rogers All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "cppqc.h"
+
+#include <algorithm>
+#include <iterator>
+#include <boost/static_assert.hpp>
+#include <sstream>
+
+namespace uut {
+
+template <typename InputIterator>
+void selection_sort(InputIterator b, InputIterator e, bool make_mistakes = false)
+{
+ //Selection sort performs the following steps:
+ //1) From the current iterator, find the smallest value
+ //2) Swap the smallest value with the current iterator
+ //3) Continue until end of range
+
+ make_mistakes && b != e ? ++b : b;
+ for(InputIterator c = b; c != e ; ++c)
+ {
+ std::swap(*(std::min_element(c, e)), *c);
+ }
+}
+
+}
+
+struct PropTestSort: cppqc::Property<std::vector<int>>
+{
+ bool check(const std::vector<int> &v) const override
+ {
+ std::vector<int> v_copy(v);
+ uut::selection_sort(std::begin(v_copy), std::end(v_copy), true);
+ return std::is_sorted(std::begin(v_copy), std::end(v_copy));
+ }
+ std::string name() const override
+ {
+ return "Sorting should be sorted";
+ }
+ std::string classify(const std::vector<int> &v) const override
+ {
+ std::ostringstream sstr;
+ sstr << "size " << v.size();
+ return sstr.str();
+ }
+ bool trivial(const std::vector<int> &v) const override
+ {
+ return v.empty() || v.size() == 1;
+ }
+};
+
+int main()
+{
+ cppqc::quickCheckOutput(PropTestSort());
+}
diff --git a/vendor/CppQuickCheck-2018-03-28/examples/src/TestSortCompact.cpp b/vendor/CppQuickCheck-2018-03-28/examples/src/TestSortCompact.cpp
new file mode 100644
index 00000000..a3a6ee71
--- /dev/null
+++ b/vendor/CppQuickCheck-2018-03-28/examples/src/TestSortCompact.cpp
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2016, Vladimir Strisovsky All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "cppqc.h"
+#include "cppqc/CompactCheck.h"
+
+#include <algorithm>
+#include <iterator>
+#include <boost/static_assert.hpp>
+#include <sstream>
+
+namespace uut {
+
+template <typename InputIterator>
+void selection_sort(InputIterator b, InputIterator e, bool make_mistakes = false)
+{
+ //Selection sort performs the following steps:
+ //1) From the current iterator, find the smallest value
+ //2) Swap the smallest value with the current iterator
+ //3) Continue until end of range
+
+ make_mistakes && b != e ? ++b : b;
+ for(InputIterator c = b; c != e ; ++c)
+ {
+ std::swap(*(std::min_element(c, e)), *c);
+ }
+}
+
+}
+
+int main()
+{
+ std::cout << "* uut::selection_sort" << std::endl;
+
+ cppqc::gen<std::vector<int>>()
+ .property("Sorting should be sorted",
+ [](const std::vector<int> &v)
+ {
+ std::vector<int> v_copy(v);
+ uut::selection_sort(std::begin(v_copy), std::end(v_copy), true);
+ return std::is_sorted(std::begin(v_copy), std::end(v_copy));
+ })
+ .classify([](const std::vector<int> &v)
+ {
+ return std::to_string(v.size());
+ })
+ .trivial([](const std::vector<int> &v)
+ {
+ return v.empty() || v.size() == 1;
+ })
+ .testWithOutput();
+
+ std::cout << "* std::sort" << std::endl;
+
+ cppqc::gen<std::vector<int>>()
+ .property("Sorting should be sorted",
+ [](const std::vector<int> &v)
+ {
+ std::vector<int> v_copy(v);
+ std::sort(v_copy.begin(), v_copy.end());
+ return std::is_sorted(std::begin(v_copy), std::end(v_copy));
+ })
+ .classify([](const std::vector<int> &v)
+ {
+ return std::to_string(v.size());
+ })
+ .trivial([](const std::vector<int> &v)
+ {
+ return v.empty() || v.size() == 1;
+ })
+ .testWithOutput();
+
+}
diff --git a/vendor/CppQuickCheck-2018-03-28/examples/src/TestWithCustomGenerator.cpp b/vendor/CppQuickCheck-2018-03-28/examples/src/TestWithCustomGenerator.cpp
new file mode 100644
index 00000000..0113cac4
--- /dev/null
+++ b/vendor/CppQuickCheck-2018-03-28/examples/src/TestWithCustomGenerator.cpp
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2018, Amy de Buitléir All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "cppqc.h"
+
+#include <random>
+#include <sstream>
+
+class Rectangle {
+public:
+ Rectangle (int w, int h) {
+ width = w;
+ height = h;
+ }
+ int getWidth() const { return width; }
+ int getHeight() const { return height; }
+ int getArea() const { return width*height; }
+ friend std::ostream& operator << (std::ostream& os, const Rectangle& r) {
+ os << "width: " << r.width << " height: " << r.height << std::endl;
+ return os ;
+ }
+private:
+ int width;
+ int height;
+};
+
+class CustomGenerator {
+public:
+ Rectangle unGen(cppqc::RngEngine &rng, std::size_t n) {
+ std::uniform_int_distribution<> dist{1, static_cast<int>(n) + 1};
+ int w = dist(rng);
+ int h = (n + 1)/w;
+ return Rectangle(w, h);
+ }
+
+ std::vector<Rectangle> shrink(const Rectangle &r) {
+ std::vector<Rectangle> ret;
+ if (r.getWidth() > 1)
+ ret.push_back(Rectangle(r.getWidth()-1, r.getHeight()));
+ if (r.getHeight() > 1) {
+ ret.push_back(Rectangle(r.getWidth(), r.getHeight()-1));
+ }
+ return ret;
+ }
+};
+
+// A silly test just to demonstrate the custom generator.
+struct PropTestCustomGen : cppqc::Property<Rectangle>
+{
+ PropTestCustomGen() : Property(CustomGenerator()) {}
+ bool check(const Rectangle &r) const override
+ {
+ return (r.getArea() == r.getWidth() * r.getHeight());
+ }
+ std::string name() const override
+ {
+ return "TestCustomGen";
+ }
+};
+
+int main()
+{
+ cppqc::quickCheckOutput(PropTestCustomGen());
+}
diff --git a/vendor/CppQuickCheck-2018-03-28/examples/src/exampleElementsGen.cpp b/vendor/CppQuickCheck-2018-03-28/examples/src/exampleElementsGen.cpp
new file mode 100644
index 00000000..fe6e953f
--- /dev/null
+++ b/vendor/CppQuickCheck-2018-03-28/examples/src/exampleElementsGen.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2010, Gregory Rogers All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "cppqc.h"
+
+#include <algorithm>
+#include <sstream>
+
+// Useless property just to show usage of elements generator
+
+struct PropTestElementsGen : cppqc::Property<int>
+{
+ PropTestElementsGen() : Property(cppqc::elements({1, 4, 5})) {}
+ bool check(const int &v) const override
+ {
+ return (v == 1) || (v == 4) || (v == 5);
+ }
+ std::string name() const override
+ {
+ return "TestElementsGen";
+ }
+ std::string classify(const int &v) const override
+ {
+ std::ostringstream sstr;
+ sstr << v;
+ return sstr.str();
+ }
+};
+
+int main()
+{
+ cppqc::quickCheckOutput(PropTestElementsGen());
+}
diff --git a/vendor/CppQuickCheck-2018-03-28/examples/src/sampleOutput.cpp b/vendor/CppQuickCheck-2018-03-28/examples/src/sampleOutput.cpp
new file mode 100644
index 00000000..82d586b3
--- /dev/null
+++ b/vendor/CppQuickCheck-2018-03-28/examples/src/sampleOutput.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2010, Gregory Rogers All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "cppqc.h"
+
+#include <map>
+#include <boost/bind.hpp>
+#include <boost/assign/list_of.hpp>
+
+using namespace cppqc;
+
+const std::map<std::string, boost::function<void ()> >
+sampleOutputCommand = boost::assign::map_list_of<std::string, boost::function<void ()> >
+("bool", boost::bind(sampleOutput<bool>, Arbitrary<bool>(), boost::ref(std::cout), 0, 0))
+("char", boost::bind(sampleOutput<char>, Arbitrary<char>(), boost::ref(std::cout), 0, 0))
+("wchar_t", boost::bind(sampleOutput<wchar_t>, Arbitrary<wchar_t>(), boost::ref(std::cout), 0, 0))
+("signed char", boost::bind(sampleOutput<signed char>, Arbitrary<signed char>(), boost::ref(std::cout), 0, 0))
+("unsigned char", boost::bind(sampleOutput<unsigned char>, Arbitrary<unsigned char>(), boost::ref(std::cout), 0, 0))
+("short", boost::bind(sampleOutput<short>, Arbitrary<short>(), boost::ref(std::cout), 0, 0))
+("signed short", boost::bind(sampleOutput<signed short>, Arbitrary<signed short>(), boost::ref(std::cout), 0, 0))
+("unsigned short", boost::bind(sampleOutput<unsigned short>, Arbitrary<unsigned short>(), boost::ref(std::cout), 0, 0))
+("int", boost::bind(sampleOutput<int>, Arbitrary<int>(), boost::ref(std::cout), 0, 0))
+("signed", boost::bind(sampleOutput<signed>, Arbitrary<signed>(), boost::ref(std::cout), 0, 0))
+("unsigned", boost::bind(sampleOutput<unsigned>, Arbitrary<unsigned>(), boost::ref(std::cout), 0, 0))
+("signed int", boost::bind(sampleOutput<signed int>, Arbitrary<signed int>(), boost::ref(std::cout), 0, 0))
+("unsigned int", boost::bind(sampleOutput<unsigned int>, Arbitrary<unsigned int>(), boost::ref(std::cout), 0, 0))
+("long", boost::bind(sampleOutput<long>, Arbitrary<long>(), boost::ref(std::cout), 0, 0))
+("signed long", boost::bind(sampleOutput<signed long>, Arbitrary<signed long>(), boost::ref(std::cout), 0, 0))
+("unsigned long", boost::bind(sampleOutput<unsigned long>, Arbitrary<unsigned long>(), boost::ref(std::cout), 0, 0))
+("float", boost::bind(sampleOutput<float>, Arbitrary<float>(), boost::ref(std::cout), 0, 0))
+("double", boost::bind(sampleOutput<double>, Arbitrary<double>(), boost::ref(std::cout), 0, 0))
+("long double", boost::bind(sampleOutput<long double>, Arbitrary<long double>(), boost::ref(std::cout), 0, 0))
+("pair", boost::bind(sampleOutput<std::pair<int,int> >, Arbitrary<std::pair<int,int> >(), boost::ref(std::cout), 0, 0))
+("tuple", boost::bind(sampleOutput<std::tuple<int,int,int> >, tupleOf<int,int,int>(), boost::ref(std::cout), 0, 0))
+("string", boost::bind(sampleOutput<std::string>, Arbitrary<std::string>(), boost::ref(std::cout), 0, 0));
+
+int main(int argc, char **argv)
+{
+ if(argc == 1) {
+ std::cout << "Usage: TYPES... (e.g., int, double, string)\n";
+ return 0;
+ }
+
+ for (int i = 1; i < argc; ++i) {
+ auto it = sampleOutputCommand.find(argv[i]);
+ if (it != sampleOutputCommand.end())
+ it->second();
+ else
+ std::cout << "unrecognized type \"" << argv[i] << "\"\n";
+ }
+}
diff --git a/vendor/CppQuickCheck-2018-03-28/examples/src/sampleShrinkOutput.cpp b/vendor/CppQuickCheck-2018-03-28/examples/src/sampleShrinkOutput.cpp
new file mode 100644
index 00000000..b7c65ff2
--- /dev/null
+++ b/vendor/CppQuickCheck-2018-03-28/examples/src/sampleShrinkOutput.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2010, Gregory Rogers All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "cppqc.h"
+
+#include <map>
+#include <boost/bind.hpp>
+#include <boost/assign/list_of.hpp>
+
+using namespace cppqc;
+
+namespace std {
+ template<class T1, class T2>
+ std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &x)
+ {
+ return out << '(' << x.first << ',' << x.second << ')';
+ }
+}
+
+const std::map<std::string, boost::function<void ()> >
+sampleShrinkOutputCommand = boost::assign::map_list_of<std::string, boost::function<void ()> >
+("bool", boost::bind(sampleShrinkOutput<bool>, Arbitrary<bool>(), boost::ref(std::cout), 0, true, 0))
+("char", boost::bind(sampleShrinkOutput<char>, Arbitrary<char>(), boost::ref(std::cout), 0, true, 0))
+("wchar_t", boost::bind(sampleShrinkOutput<wchar_t>, Arbitrary<wchar_t>(), boost::ref(std::cout), 0, true, 0))
+("signed char", boost::bind(sampleShrinkOutput<signed char>, Arbitrary<signed char>(), boost::ref(std::cout), 0, true, 0))
+("unsigned char", boost::bind(sampleShrinkOutput<unsigned char>, Arbitrary<unsigned char>(), boost::ref(std::cout), 0, true, 0))
+("short", boost::bind(sampleShrinkOutput<short>, Arbitrary<short>(), boost::ref(std::cout), 0, true, 0))
+("signed short", boost::bind(sampleShrinkOutput<signed short>, Arbitrary<signed short>(), boost::ref(std::cout), 0, true, 0))
+("unsigned short", boost::bind(sampleShrinkOutput<unsigned short>, Arbitrary<unsigned short>(), boost::ref(std::cout), 0, true, 0))
+("int", boost::bind(sampleShrinkOutput<int>, Arbitrary<int>(), boost::ref(std::cout), 0, true, 0))
+("signed", boost::bind(sampleShrinkOutput<signed>, Arbitrary<signed>(), boost::ref(std::cout), 0, true, 0))
+("unsigned", boost::bind(sampleShrinkOutput<unsigned>, Arbitrary<unsigned>(), boost::ref(std::cout), 0, true, 0))
+("signed int", boost::bind(sampleShrinkOutput<signed int>, Arbitrary<signed int>(), boost::ref(std::cout), 0, true, 0))
+("unsigned int", boost::bind(sampleShrinkOutput<unsigned int>, Arbitrary<unsigned int>(), boost::ref(std::cout), 0, true, 0))
+("long", boost::bind(sampleShrinkOutput<long>, Arbitrary<long>(), boost::ref(std::cout), 0, true, 0))
+("signed long", boost::bind(sampleShrinkOutput<signed long>, Arbitrary<signed long>(), boost::ref(std::cout), 0, true, 0))
+("unsigned long", boost::bind(sampleShrinkOutput<unsigned long>, Arbitrary<unsigned long>(), boost::ref(std::cout), 0, true, 0))
+("float", boost::bind(sampleShrinkOutput<float>, Arbitrary<float>(), boost::ref(std::cout), 0, true, 0))
+("double", boost::bind(sampleShrinkOutput<double>, Arbitrary<double>(), boost::ref(std::cout), 0, true, 0))
+("long double", boost::bind(sampleShrinkOutput<long double>, Arbitrary<long double>(), boost::ref(std::cout), 0, true, 0))
+("pair", boost::bind(sampleShrinkOutput<std::pair<int,int> >, Arbitrary<std::pair<int,int> >(), boost::ref(std::cout), 0, true, 0))
+("tuple", boost::bind(sampleShrinkOutput<std::tuple<int,int,int> >, tupleOf<int,int,int>(), boost::ref(std::cout), 0, true, 0))
+("string", boost::bind(sampleShrinkOutput<std::string>, Arbitrary<std::string>(), boost::ref(std::cout), 0, true, 0));
+
+int main(int argc, char **argv)
+{
+ if(argc == 1) {
+ std::cout << "Usage: TYPES... (e.g., int, double, string)\n";
+ return 0;
+ }
+
+ for (int i = 1; i < argc; ++i) {
+ std::map<std::string, boost::function<void ()> >::const_iterator it =
+ sampleShrinkOutputCommand.find(argv[i]);
+ if (it != sampleShrinkOutputCommand.end())
+ it->second();
+ else
+ std::cout << "unrecognized type \"" << argv[i] << "\"\n";
+ }
+}