Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 95ff34b8 authored by Quentin Khan's avatar Quentin Khan
Browse files

Improve and extend FBasicParticle unit tests

parent 9633c02c
Branches
No related tags found
No related merge requests found
......@@ -39,6 +39,10 @@ struct test_FBasicParticle_simple {
test_variadic_constructor_overflow_failure();
test_constructor_from_tuple();
test_position_getter();
test_position_setter();
test_attribute_getter();
test_attribute_setter();
test_compare_equal();
test_pull_push();
}
......@@ -170,6 +174,88 @@ struct test_FBasicParticle_simple {
assert(pos != p.position());
}
/**
* \brief Tests the position setter
*
* Expected result:
* - setting the position changes the particle position
*/
void test_position_setter() {
typename Particle::position_t ref{1.5,2.5,3.5};
Particle p(ref, 1,2,3,4,5);
p.setPosition({10.25,11.25,12.25});
assert(std::get<0>(p) == 10.25);
assert(std::get<1>(p) == 11.25);
assert(std::get<2>(p) == 12.25);
}
/**
* \brief Test compile time attribute getter
*
* Expected result:
* - the attributes are returned using indices starting from 0
*/
void test_attribute_getter() {
// const
const Particle p1(std::make_tuple(1.5,2.5,3.5,1,2,3,4,5));
assert(p1.attribute<0>() == 1);
assert(p1.attribute<1>() == 2);
assert(p1.attribute<2>() == 3);
assert(p1.attribute<3>() == 4);
assert(p1.attribute<4>() == 5);
// non const
Particle p2(std::make_tuple(1.5,2.5,3.5,1,2,3,4,5));
assert(p2.attribute<0>() == 1);
assert(p2.attribute<1>() == 2);
assert(p2.attribute<2>() == 3);
assert(p2.attribute<3>() == 4);
assert(p2.attribute<4>() == 5);
}
/**
* \brief Test compile time attribute setter
*
* Expected result:
* - the attributes are set using indices starting from 0
*/
void test_attribute_setter() {
Particle p1(std::make_tuple(1.5,2.5,3.5,0,0,0,0,0));
p1.attribute<0>() = 1;
p1.attribute<1>() = 2;
p1.attribute<2>() = 3;
p1.attribute<3>() = 4;
p1.attribute<4>() = 5;
assert(p1.attribute<0>() == 1);
assert(p1.attribute<1>() == 2);
assert(p1.attribute<2>() == 3);
assert(p1.attribute<3>() == 4);
assert(p1.attribute<4>() == 5);
}
/**
* \brief Test particle comparison
*
* Expected result:
* - Two particles that have the same position and the same attributes
* compare equal.
*/
void test_compare_equal() {
Particle p1(std::make_tuple(1.5,2.5,3.5,1,2,3,4,5));
Particle p2(std::make_tuple(1.5,2.5,3.5,1,2,3,4,5));
Particle p3(std::make_tuple(1.5,2.5,3.5,1,2,0,4,5));
Particle p4(std::make_tuple(1.5, 0,3.5,1,2,3,4,5));
assert(p1 == p2);
assert(p2 == p1);
assert(p1 != p3);
assert(p1 != p4);
assert(p3 != p4);
}
void test_pull_push() {
Particle p({2.3,3.4,4.5}, 5, 6, 7, 8, 9);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment