diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-08-06 21:42:40 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-08-06 21:42:40 +0100 |
commit | 3ce4865390924d13c525938c5c60c73650564a50 (patch) | |
tree | 973a886ba303ef5f379fb0dbc0f49c23ff8268c1 /test | |
parent | 5401b4a6ea1055e27820fd1155c7093d63491214 (diff) | |
download | YAGE-3ce4865390924d13c525938c5c60c73650564a50.tar.gz YAGE-3ce4865390924d13c525938c5c60c73650564a50.zip |
ParticleBody now passes gravity test
Diffstat (limited to 'test')
-rw-r--r-- | test/matrixtest.cpp | 2 | ||||
-rw-r--r-- | test/particlebodytest.cpp | 33 |
2 files changed, 22 insertions, 13 deletions
diff --git a/test/matrixtest.cpp b/test/matrixtest.cpp index 530d3530..ee568067 100644 --- a/test/matrixtest.cpp +++ b/test/matrixtest.cpp @@ -41,7 +41,7 @@ int vectorDotProduct(const std::vector<int> &vec_contents_f, const std::vector<i int x = yage::matrix::dot(v1, v2); - return x==76; + return x; } bool matrixMultiplication() 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(); } |