6 #include <gtest/gtest.h>
7 #include <gmock/gmock.h>
8 using namespace ::testing;
10 #include "../examples/boris/particle.hpp"
11 #include "../examples/boris/particle_cloud.hpp"
12 #include "../examples/boris/particle_util.hpp"
16 #define PRECISION double
21 static uniform_real_distribution<PRECISION>
dist;
30 uniform_real_distribution<PRECISION>
RandomGenerator::dist = uniform_real_distribution<PRECISION>(-10.0, 10.0);
35 for (
auto&& elem : vec) {
40 #define create_single(name, num)\
41 ParticleComponent<PRECISION> name(num)
42 #define create_and_fill_single(name, num)\
43 create_single(name, num);\
45 #define create_cloud(name, num)\
46 create_single(name, num * DIMS)
47 #define create_and_fill_cloud(name, num)\
48 create_and_fill_single(name, num * DIMS)
51 TEST(OperatorTests, AddSingleOnSingle)
56 for(
size_t i = 0; i <
DIMS; ++i) {
57 expected_single[i] = first_single[i] + second_single[i];
60 EXPECT_THAT(result_single, Pointwise(Eq(), expected_single));
63 TEST(OperatorTests, AddCloudOnCloud)
68 for (
size_t i = 0; i < 5; ++i) {
69 for (
size_t j = 0; j <
DIMS; ++j) {
70 expected_cloud[i * DIMS + j] = first_cloud[i * DIMS + j] + second_cloud[i * DIMS + j];
74 EXPECT_THAT(result_cloud, Pointwise(Eq(), expected_cloud));
77 TEST(OperatorTests, AddSingleOnCloud)
82 for (
size_t i = 0; i < 5; ++i) {
83 for (
size_t j = 0; j <
DIMS; ++j) {
84 expected_cloud[i * DIMS + j] = cloud[i * DIMS + j] + single[j];
88 EXPECT_THAT(result_cloud, Pointwise(Eq(), expected_cloud));
91 TEST(OperatorTests, InplaceAddSingleOnSingle)
96 for(
size_t i = 0; i <
DIMS; ++i) {
97 expected_single[i] = first_single[i] + second_single[i];
99 first_single += second_single;
100 EXPECT_THAT(first_single, Pointwise(Eq(), expected_single));
103 TEST(OperatorTests, InplaceAddCloudOnCloud)
108 for (
size_t i = 0; i < 5; ++i) {
109 for (
size_t j = 0; j <
DIMS; ++j) {
110 expected_cloud[i * DIMS + j] = first_cloud[i * DIMS + j] + second_cloud[i * DIMS + j];
113 first_cloud += second_cloud;
114 EXPECT_THAT(first_cloud, Pointwise(Eq(), expected_cloud));
117 TEST(OperatorTests, InplaceAddSingleOnCloud)
122 for (
size_t i = 0; i < 5; ++i) {
123 for (
size_t j = 0; j <
DIMS; ++j) {
124 expected_cloud[i * DIMS + j] = cloud[i * DIMS + j] + single[j];
128 EXPECT_THAT(cloud, Pointwise(Eq(), expected_cloud));
131 TEST(OperatorTests, MinusSingleOnSingle)
136 for(
size_t i = 0; i <
DIMS; ++i) {
137 expected_single[i] = first_single[i] - second_single[i];
140 EXPECT_THAT(result_single, Pointwise(Eq(), expected_single));
143 TEST(OperatorTests, MinusCloudOnCloud)
148 for (
size_t i = 0; i < 5; ++i) {
149 for (
size_t j = 0; j <
DIMS; ++j) {
150 expected_cloud[i * DIMS + j] = first_cloud[i * DIMS + j] - second_cloud[i * DIMS + j];
154 EXPECT_THAT(result_cloud, Pointwise(Eq(), expected_cloud));
157 TEST(OperatorTests, MinusSingleOnCloud)
162 for (
size_t i = 0; i < 5; ++i) {
163 for (
size_t j = 0; j <
DIMS; ++j) {
164 expected_cloud[i * DIMS + j] = cloud[i * DIMS + j] - single[j];
168 EXPECT_THAT(result_cloud, Pointwise(Eq(), expected_cloud));
171 TEST(OperatorTests, InplaceMinusSingleOnSingle)
176 for(
size_t i = 0; i <
DIMS; ++i) {
177 expected_single[i] = first_single[i] - second_single[i];
179 first_single -= second_single;
180 EXPECT_THAT(first_single, Pointwise(Eq(), expected_single));
183 TEST(OperatorTests, InplaceMinusCloudOnCloud)
188 for (
size_t i = 0; i < 5; ++i) {
189 for (
size_t j = 0; j <
DIMS; ++j) {
190 expected_cloud[i * DIMS + j] = first_cloud[i * DIMS + j] - second_cloud[i * DIMS + j];
193 first_cloud -= second_cloud;
194 EXPECT_THAT(first_cloud, Pointwise(Eq(), expected_cloud));
197 TEST(OperatorTests, InplaceMinusSingleOnCloud)
202 for (
size_t i = 0; i < 5; ++i) {
203 for (
size_t j = 0; j <
DIMS; ++j) {
204 expected_cloud[i * DIMS + j] = cloud[i * DIMS + j] - single[j];
208 EXPECT_THAT(cloud, Pointwise(Eq(), expected_cloud));
211 TEST(OperatorTests, MulWithSingle)
216 for(
size_t i = 0; i <
DIMS; ++i) {
217 expected_single[i] = single[i] * value;
220 EXPECT_THAT(result_single1, Pointwise(Eq(), expected_single));
222 EXPECT_THAT(result_single2, Pointwise(Eq(), expected_single));
225 TEST(OperatorTests, MulWithCloud)
230 for (
size_t i = 0; i < 5; ++i) {
231 for (
size_t j = 0; j <
DIMS; ++j) {
232 expected_cloud[i * DIMS + j] = cloud[i * DIMS + j] * value;
236 EXPECT_THAT(result_cloud1, Pointwise(Eq(), expected_cloud));
238 EXPECT_THAT(result_cloud2, Pointwise(Eq(), expected_cloud));
241 TEST(OperatorTests, InplaceMulWithSingle)
246 for(
size_t i = 0; i <
DIMS; ++i) {
247 expected_single[i] = single[i] * value;
250 EXPECT_THAT(single, Pointwise(Eq(), expected_single));
253 TEST(OperatorTests, InplaceMulWithCloud)
258 for (
size_t i = 0; i < 5; ++i) {
259 for (
size_t j = 0; j <
DIMS; ++j) {
260 expected_cloud[i * DIMS + j] = cloud[i * DIMS + j] * value;
264 EXPECT_THAT(cloud, Pointwise(Eq(), expected_cloud));
267 TEST(OperatorTests, DivWithSingle)
272 for(
size_t i = 0; i <
DIMS; ++i) {
273 expected_single[i] = single[i] / value;
276 EXPECT_THAT(result_single, Pointwise(Eq(), expected_single));
279 TEST(OperatorTests, DivWithCloud)
284 for (
size_t i = 0; i < 5; ++i) {
285 for (
size_t j = 0; j <
DIMS; ++j) {
286 expected_cloud[i * DIMS + j] = cloud[i * DIMS + j] / value;
290 EXPECT_THAT(result_cloud, Pointwise(Eq(), expected_cloud));
293 TEST(OperatorTests, InplaceDivWithSingle)
298 for(
size_t i = 0; i <
DIMS; ++i) {
299 expected_single[i] = single[i] / value;
302 EXPECT_THAT(single, Pointwise(Eq(), expected_single));
305 TEST(OperatorTests, InplaceDivWithCloud)
310 for (
size_t i = 0; i < 5; ++i) {
311 for (
size_t j = 0; j <
DIMS; ++j) {
312 expected_cloud[i * DIMS + j] = cloud[i * DIMS + j] / value;
316 EXPECT_THAT(cloud, Pointwise(Eq(), expected_cloud));
319 TEST(OperatorTests, CrossProdSingleOnSingle)
324 expected_single[0] = first_single[1] * second_single[2] - first_single[2] * second_single[1];
325 expected_single[1] = first_single[2] * second_single[0] - first_single[0] * second_single[2];
326 expected_single[2] = first_single[0] * second_single[1] - first_single[1] * second_single[0];
329 EXPECT_THAT(result_single, Pointwise(Eq(), expected_single));
332 TEST(OperatorTests, CrossProdCloudOnCloud)
337 for (
size_t i = 0; i < 5; ++i) {
338 expected_cloud[i *
DIMS] = first_cloud[i *
DIMS + 1] * second_cloud[i *
DIMS + 2] - first_cloud[i *
DIMS + 2] * second_cloud[i *
DIMS + 1];
339 expected_cloud[i *
DIMS + 1] = first_cloud[i *
DIMS + 2] * second_cloud[i *
DIMS] - first_cloud[i *
DIMS] * second_cloud[i *
DIMS + 2];
340 expected_cloud[i *
DIMS + 2] = first_cloud[i *
DIMS] * second_cloud[i *
DIMS + 1] - first_cloud[i *
DIMS + 1] * second_cloud[i *
DIMS];
343 EXPECT_THAT(result_cloud, Pointwise(Eq(), expected_cloud));
346 TEST(OperatorTests, CrossProdSingleOnCloud)
351 for (
size_t i = 0; i < 5; ++i) {
352 expected_cloud[i *
DIMS] = cloud[i *
DIMS + 1] * single[2] - cloud[i *
DIMS + 2] * single[1];
353 expected_cloud[i *
DIMS + 1] = cloud[i *
DIMS + 2] * single[0] - cloud[i *
DIMS] * single[2];
354 expected_cloud[i *
DIMS + 2] = cloud[i *
DIMS] * single[1] - cloud[i *
DIMS + 1] * single[0];
357 EXPECT_THAT(result_cloud, Pointwise(Eq(), expected_cloud));
361 TEST(UtilitiesTests, DistanceBetweenTwoParticles)
365 first_particle.
pos() = first_single;
368 second_particle.
pos() = second_single;
370 for (
size_t i = 0; i <
DIMS; ++i) {
371 expected_distance += (first_single[i] - second_single[i]) * (first_single[i] - second_single[i]);
373 expected_distance = sqrt(expected_distance);
375 EXPECT_THAT(dist, DoubleEq(expected_distance));
378 TEST(UtilitiesTests, DistanceOfCloudToReference)
382 particle.
pos() = single;
386 vector<PRECISION> expected_distance(5, 0.0);
387 for (
size_t j = 0; j < 5; ++j) {
388 for (
size_t i = 0; i <
DIMS; ++i) {
389 expected_distance[j] += (cloud.
positions()[j * DIMS + i] - particle.
pos()[i]) * (cloud.
positions()[j * DIMS + i] - particle.
pos()[i]);
391 expected_distance[j] = sqrt(expected_distance[j]);
394 EXPECT_THAT(dist, Pointwise(Eq(), expected_distance));
398 int main(
int argc,
char** argv)
400 testing::InitGoogleTest(&argc, argv);
401 return RUN_ALL_TESTS();
TEST(OperatorTests, AddSingleOnSingle)
static vector< precision > distance_to_reference(const ParticleCloud< precision > &cloud, const Particle< precision > &reference)
ParticleComponent< precision > & pos()
int main(int argc, char **argv)
#define create_cloud(name, num)
#define create_single(name, num)
static uniform_real_distribution< PRECISION > dist
void cross_prod(const double first[DIM], const double second[DIM], double cross_prod[DIM])
static default_random_engine rd_gen
ParticleCloudComponent< precision > & positions()
vector< precision > ParticleCloudComponent
vector< precision > ParticleComponent
#define create_and_fill_single(name, num)
void fill_single(ParticleComponent< PRECISION > &vec)
#define create_and_fill_cloud(name, num)