MCPcopy Create free account
hub / github.com/PX4/eigen / check_stdvector_quaternion

Function check_stdvector_quaternion

test/stdvector.cpp:86–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84
85template<typename QuaternionType>
86void check_stdvector_quaternion(const QuaternionType&)
87{
88 typedef typename QuaternionType::Coefficients Coefficients;
89 QuaternionType x(Coefficients::Random()), y(Coefficients::Random());
90 std::vector<QuaternionType,Eigen::aligned_allocator<QuaternionType> > v(10), w(20, y);
91 v[5] = x;
92 w[6] = v[5];
93 VERIFY_IS_APPROX(w[6], v[5]);
94 v = w;
95 for(int i = 0; i < 20; i++)
96 {
97 VERIFY_IS_APPROX(w[i], v[i]);
98 }
99
100 v.resize(21);
101 v[20] = x;
102 VERIFY_IS_APPROX(v[20], x);
103 v.resize(22,y);
104 VERIFY_IS_APPROX(v[21], y);
105 v.push_back(x);
106 VERIFY_IS_APPROX(v[22], x);
107 VERIFY((internal::UIntPtr)&(v[22]) == (internal::UIntPtr)&(v[21]) + sizeof(QuaternionType));
108
109 // do a lot of push_back such that the vector gets internally resized
110 // (with memory reallocation)
111 QuaternionType* ref = &w[0];
112 for(int i=0; i<30 || ((ref==&w[0]) && i<300); ++i)
113 v.push_back(w[i%w.size()]);
114 for(unsigned int i=23; i<v.size(); ++i)
115 {
116 VERIFY(v[i].coeffs()==w[(i-23)%w.size()].coeffs());
117 }
118}
119
120void test_stdvector()
121{

Callers 1

test_stdvectorFunction · 0.70

Calls 4

coeffsMethod · 0.80
resizeMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by 1

test_stdvectorFunction · 0.56