summaryrefslogtreecommitdiffstats
path: root/pstl/test/test_includes.cpp
diff options
context:
space:
mode:
authorJF Bastien <jfbastien@apple.com>2018-12-19 17:45:32 +0000
committerJF Bastien <jfbastien@apple.com>2018-12-19 17:45:32 +0000
commite637637ae46a5b2fa1e9d10c16ae5b0922289f82 (patch)
tree1bd45f3e03d8bbb85a9dca6b46015769d521b186 /pstl/test/test_includes.cpp
parent5d409b22781f5854f1bac3fd60c8499af0c865bf (diff)
downloadbcm5719-llvm-e637637ae46a5b2fa1e9d10c16ae5b0922289f82.tar.gz
bcm5719-llvm-e637637ae46a5b2fa1e9d10c16ae5b0922289f82.zip
Initial PSTL commit
The initial commit of the Parallel STL upstream (under LLVM umbrella) based on Parallel STL 20181204 open source release, which is available by https://github.com/intel/parallelstl Author: Mikhail Dvorskiy <mikhail.dvorskiy@intel.com> Differential Revision: https://reviews.llvm.org/D55889 llvm-svn: 349653
Diffstat (limited to 'pstl/test/test_includes.cpp')
-rw-r--r--pstl/test/test_includes.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/pstl/test/test_includes.cpp b/pstl/test/test_includes.cpp
new file mode 100644
index 00000000000..7f44166f0ae
--- /dev/null
+++ b/pstl/test/test_includes.cpp
@@ -0,0 +1,105 @@
+// -*- C++ -*-
+//===-- test_includes.cpp -------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Tests for partial_sort
+
+#include <cmath>
+
+#include "pstl/execution"
+#include "pstl/algorithm"
+#include "utils.h"
+
+using namespace TestUtils;
+
+template <typename T>
+struct Num
+{
+ T val;
+ explicit Num(const T& v) : val(v) {}
+
+ //for "includes" checks
+ template <typename T1>
+ bool
+ operator<(const Num<T1>& v1) const
+ {
+ return val < v1.val;
+ }
+
+ //The types Type1 and Type2 must be such that an object of type InputIt can be dereferenced and then implicitly converted to both of them
+ template <typename T1>
+ operator Num<T1>() const
+ {
+ return Num<T1>((T1)val);
+ }
+};
+
+struct test_one_policy
+{
+ template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
+ typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type
+ operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
+ Compare comp)
+ {
+
+ auto expect_res = std::includes(first1, last1, first2, last2, comp);
+ auto res = std::includes(exec, first1, last1, first2, last2, comp);
+
+ EXPECT_TRUE(expect_res == res, "wrong result for includes");
+ }
+
+ template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
+ typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type
+ operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
+ Compare comp)
+ {
+ }
+};
+
+template <typename T1, typename T2, typename Compare>
+void
+test_includes(Compare compare)
+{
+
+ const std::size_t n_max = 1000000;
+
+ // The rand()%(2*n+1) encourages generation of some duplicates.
+ std::srand(42);
+
+ for (std::size_t n = 0; n < n_max; n = n <= 16 ? n + 1 : size_t(3.1415 * n))
+ {
+ for (std::size_t m = 0; m < n_max; m = m <= 16 ? m + 1 : size_t(2.71828 * m))
+ {
+ //prepare the input ranges
+ Sequence<T1> in1(n, [n](std::size_t k) { return rand() % (2 * k + 1); });
+ Sequence<T2> in2(m, [m](std::size_t k) { return rand() % (k + 1); });
+
+ std::sort(in1.begin(), in1.end(), compare);
+ std::sort(in2.begin(), in2.end(), compare);
+
+ invoke_on_all_policies(test_one_policy(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(), compare);
+
+ //test w/ non constant predicate
+ if (n < 5 && m < 5)
+ invoke_on_all_policies(test_one_policy(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(),
+ non_const(compare));
+ }
+ }
+}
+
+int32_t
+main()
+{
+
+ test_includes<float64_t, float64_t>(__pstl::internal::pstl_less());
+ test_includes<Num<int64_t>, Num<int32_t>>([](const Num<int64_t>& x, const Num<int32_t>& y) { return x < y; });
+ std::cout << done() << std::endl;
+
+ return 0;
+}
OpenPOWER on IntegriCloud