aboutsummaryrefslogtreecommitdiffstats
path: root/test/particlebodytest.cpp
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-08-06 21:42:40 +0100
committerYann Herklotz <ymherklotz@gmail.com>2017-08-06 21:42:40 +0100
commit3ce4865390924d13c525938c5c60c73650564a50 (patch)
tree973a886ba303ef5f379fb0dbc0f49c23ff8268c1 /test/particlebodytest.cpp
parent5401b4a6ea1055e27820fd1155c7093d63491214 (diff)
downloadYAGE-3ce4865390924d13c525938c5c60c73650564a50.tar.gz
YAGE-3ce4865390924d13c525938c5c60c73650564a50.zip
ParticleBody now passes gravity test
Diffstat (limited to 'test/particlebodytest.cpp')
-rw-r--r--test/particlebodytest.cpp33
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();
}