[libcxx] r296830 - Fix libc++ test experimental/algorithms/alg.random.sample/sample.pass.cpp when ran in c++11 mode 32 bits

Mehdi Amini via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 2 14:08:42 PST 2017


Author: mehdi_amini
Date: Thu Mar  2 16:08:42 2017
New Revision: 296830

URL: http://llvm.org/viewvc/llvm-project?rev=296830&view=rev
Log:
Fix libc++ test experimental/algorithms/alg.random.sample/sample.pass.cpp when ran in c++11 mode 32 bits

Modified:
    libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp

Modified: libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp?rev=296830&r1=296829&r2=296830&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp Thu Mar  2 16:08:42 2017
@@ -58,19 +58,23 @@ void test() {
   const unsigned os = Expectations::os;
   SampleItem oa[os];
   const int *oa1 = Expectations::oa1;
+  ((void)oa1); // Prevent unused warning
   const int *oa2 = Expectations::oa2;
+  ((void)oa2); // Prevent unused warning
   std::minstd_rand g;
   SampleIterator end;
   end = std::experimental::sample(PopulationIterator(ia),
                                   PopulationIterator(ia + is),
                                   SampleIterator(oa), os, g);
-  assert(end.base() - oa == std::min(os, is));
-  assert(std::equal(oa, oa + os, oa1));
+  assert(static_cast<std::size_t>(end.base() - oa) == std::min(os, is));
+  // sample() is deterministic but non-reproducible;
+  // its results can vary between implementations.
+  LIBCPP_ASSERT(std::equal(oa, oa + os, oa1));
   end = std::experimental::sample(PopulationIterator(ia),
                                   PopulationIterator(ia + is),
                                   SampleIterator(oa), os, std::move(g));
-  assert(end.base() - oa == std::min(os, is));
-  assert(std::equal(oa, oa + os, oa2));
+  assert(static_cast<std::size_t>(end.base() - oa) == std::min(os, is));
+  LIBCPP_ASSERT(std::equal(oa, oa + os, oa2));
 }
 
 template <template<class...> class PopulationIteratorType, class PopulationItem,
@@ -119,7 +123,7 @@ void test_small_population() {
   end = std::experimental::sample(PopulationIterator(ia),
                                   PopulationIterator(ia + is),
                                   SampleIterator(oa), os, g);
-  assert(end.base() - oa == std::min(os, is));
+  assert(static_cast<std::size_t>(end.base() - oa) == std::min(os, is));
   assert(std::equal(oa, end.base(), oa1));
 }
 




More information about the cfe-commits mailing list