diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/PhysicsTest.cpp | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/src/test/PhysicsTest.cpp b/src/test/PhysicsTest.cpp index 198a371..c04e3ff 100644 --- a/src/test/PhysicsTest.cpp +++ b/src/test/PhysicsTest.cpp @@ -3,10 +3,10 @@ #include <crepe/api/Rigidbody.h> #include <crepe/api/Transform.h> #include <crepe/manager/ComponentManager.h> -#include <crepe/system/PhysicsSystem.h> -#include <gtest/gtest.h> #include <crepe/manager/LoopTimerManager.h> #include <crepe/manager/Mediator.h> +#include <crepe/system/PhysicsSystem.h> +#include <gtest/gtest.h> using namespace std; using namespace std::chrono_literals; @@ -20,7 +20,6 @@ public: PhysicsSystem system{m}; LoopTimerManager loop_timer{m}; - void SetUp() override { ComponentManager & mgr = this->component_manager; vector<reference_wrapper<Transform>> transforms @@ -59,10 +58,10 @@ TEST_F(PhysicsTest, gravity) { EXPECT_EQ(transform.position.y, 0); system.update(); - EXPECT_NEAR(transform.position.y, 0.0004,0.0001); + EXPECT_NEAR(transform.position.y, 0.0004, 0.0001); system.update(); - EXPECT_NEAR(transform.position.y, 0.002,0.001); + EXPECT_NEAR(transform.position.y, 0.002, 0.001); } TEST_F(PhysicsTest, max_velocity) { @@ -76,15 +75,15 @@ TEST_F(PhysicsTest, max_velocity) { rigidbody.add_force_linear({100, 100}); rigidbody.add_force_angular(100); system.update(); - EXPECT_NEAR(rigidbody.data.linear_velocity.y, 7.07,0.01); - EXPECT_NEAR(rigidbody.data.linear_velocity.x, 7.07,0.01); + EXPECT_NEAR(rigidbody.data.linear_velocity.y, 7.07, 0.01); + EXPECT_NEAR(rigidbody.data.linear_velocity.x, 7.07, 0.01); EXPECT_EQ(rigidbody.data.angular_velocity, 10); rigidbody.add_force_linear({-100, -100}); rigidbody.add_force_angular(-100); system.update(); - EXPECT_NEAR(rigidbody.data.linear_velocity.y, -7.07,0.01); - EXPECT_NEAR(rigidbody.data.linear_velocity.x, -7.07,0.01); + EXPECT_NEAR(rigidbody.data.linear_velocity.y, -7.07, 0.01); + EXPECT_NEAR(rigidbody.data.linear_velocity.x, -7.07, 0.01); EXPECT_EQ(rigidbody.data.angular_velocity, -10); } @@ -101,31 +100,31 @@ TEST_F(PhysicsTest, movement) { rigidbody.add_force_linear({1, 1}); rigidbody.add_force_angular(1); system.update(); - EXPECT_NEAR(transform.position.x, 0.02,0.001); - EXPECT_NEAR(transform.position.y, 0.02,0.001); - EXPECT_NEAR(transform.rotation, 0.02,0.001); + EXPECT_NEAR(transform.position.x, 0.02, 0.001); + EXPECT_NEAR(transform.position.y, 0.02, 0.001); + EXPECT_NEAR(transform.rotation, 0.02, 0.001); rigidbody.data.constraints = {1, 1, 1}; - EXPECT_NEAR(transform.position.x, 0.02,0.001); - EXPECT_NEAR(transform.position.y, 0.02,0.001); - EXPECT_NEAR(transform.rotation, 0.02,0.001); + EXPECT_NEAR(transform.position.x, 0.02, 0.001); + EXPECT_NEAR(transform.position.y, 0.02, 0.001); + EXPECT_NEAR(transform.rotation, 0.02, 0.001); rigidbody.data.linear_velocity_coefficient.x = 0.5; rigidbody.data.linear_velocity_coefficient.y = 0.5; rigidbody.data.angular_velocity_coefficient = 0.5; system.update(); - EXPECT_NEAR(rigidbody.data.linear_velocity.x, 0.98,0.01); - EXPECT_NEAR(rigidbody.data.linear_velocity.y, 0.98,0.01); - EXPECT_NEAR(rigidbody.data.angular_velocity, 0.98,0.01); + EXPECT_NEAR(rigidbody.data.linear_velocity.x, 0.98, 0.01); + EXPECT_NEAR(rigidbody.data.linear_velocity.y, 0.98, 0.01); + EXPECT_NEAR(rigidbody.data.angular_velocity, 0.98, 0.01); rigidbody.data.constraints = {1, 1, 0}; rigidbody.data.angular_velocity_coefficient = 0; rigidbody.data.max_angular_velocity = 1000; rigidbody.data.angular_velocity = 360; system.update(); - EXPECT_NEAR(transform.rotation, 7.22,0.0001); + EXPECT_NEAR(transform.rotation, 7.22, 0.0001); rigidbody.data.angular_velocity = -360; system.update(); - EXPECT_NEAR(transform.rotation, 0.02,0.001); + EXPECT_NEAR(transform.rotation, 0.02, 0.001); } |