diff options
Diffstat (limited to 'test/particlebodytest.cpp')
-rw-r--r-- | test/particlebodytest.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/test/particlebodytest.cpp b/test/particlebodytest.cpp index 54424b37..c8e493a0 100644 --- a/test/particlebodytest.cpp +++ b/test/particlebodytest.cpp @@ -6,24 +6,33 @@ * ---------------------------------------------------------------------------- */ -#include "Physics/particlebody.hpp" +#include <cmath> +#include <cstdlib> -#include <iostream> +#include "Physics/particlebody.hpp" +#include "gtest/gtest.h" -int main(int, char**) { +double gravityAcceleration(int iterations) { yage::ParticleBody body; - for (int i = 0; i < 60 * 3; ++i) { + for (int i = 0; i < 60 * iterations; ++i) { body.update(); - std::cout << "position: " << body.xPosition() << ", " - << body.yPosition() << "\n"; } - double ideal_position = 0.5 * -9.81 * 3 * 3; + return body.yPosition(); +} + +// Tests + +TEST(ParticleBody, Gravity) { + int random_itr = rand() % 25; + double idealPosition = 0.5 * -9.81 * std::pow(random_itr, 2); - std::cout << "Ideal Position: " << ideal_position << "\n"; + ASSERT_GE(idealPosition * 0.95, gravityAcceleration(random_itr)); + ASSERT_LE(idealPosition * 1.05, gravityAcceleration(random_itr)); +} - if (body.yPosition() < ideal_position * 0.95 && - body.yPosition() > ideal_position * 1.05) - return 0; - return 1; +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + srand(static_cast<unsigned>(time(nullptr))); + return RUN_ALL_TESTS(); } |