Mercurial > hg > CbC > CbC_llvm
comparison unittests/ADT/TinyPtrVectorTest.cpp @ 121:803732b1fca8
LLVM 5.0
author | kono |
---|---|
date | Fri, 27 Oct 2017 17:07:41 +0900 |
parents | 1172e4bd9c6f |
children | 3a76565eade5 |
comparison
equal
deleted
inserted
replaced
120:1172e4bd9c6f | 121:803732b1fca8 |
---|---|
15 #include "llvm/ADT/ArrayRef.h" | 15 #include "llvm/ADT/ArrayRef.h" |
16 #include "llvm/ADT/STLExtras.h" | 16 #include "llvm/ADT/STLExtras.h" |
17 #include "llvm/Support/type_traits.h" | 17 #include "llvm/Support/type_traits.h" |
18 #include "gtest/gtest.h" | 18 #include "gtest/gtest.h" |
19 #include <algorithm> | 19 #include <algorithm> |
20 #include <random> | |
20 #include <vector> | 21 #include <vector> |
21 | 22 |
22 using namespace llvm; | 23 using namespace llvm; |
23 | 24 |
24 namespace { | 25 namespace { |
25 | |
26 // The world's worst RNG, but it is deterministic and makes it easy to get | |
27 // *some* shuffling of elements. | |
28 static ptrdiff_t test_shuffle_rng(ptrdiff_t i) { | |
29 return (i + i * 33) % i; | |
30 } | |
31 static ptrdiff_t (*test_shuffle_rng_p)(ptrdiff_t) = &test_shuffle_rng; | |
32 | 26 |
33 template <typename VectorT> | 27 template <typename VectorT> |
34 class TinyPtrVectorTest : public testing::Test { | 28 class TinyPtrVectorTest : public testing::Test { |
35 protected: | 29 protected: |
36 typedef typename VectorT::value_type PtrT; | 30 typedef typename VectorT::value_type PtrT; |
44 | 38 |
45 TinyPtrVectorTest() { | 39 TinyPtrVectorTest() { |
46 for (size_t i = 0, e = array_lengthof(TestValues); i != e; ++i) | 40 for (size_t i = 0, e = array_lengthof(TestValues); i != e; ++i) |
47 TestPtrs.push_back(&TestValues[i]); | 41 TestPtrs.push_back(&TestValues[i]); |
48 | 42 |
49 std::random_shuffle(TestPtrs.begin(), TestPtrs.end(), test_shuffle_rng_p); | 43 std::shuffle(TestPtrs.begin(), TestPtrs.end(), std::mt19937{}); |
50 } | 44 } |
51 | 45 |
52 ArrayRef<PtrT> testArray(size_t N) { | 46 ArrayRef<PtrT> testArray(size_t N) { |
53 return makeArrayRef(&TestPtrs[0], N); | 47 return makeArrayRef(&TestPtrs[0], N); |
54 } | 48 } |