From 91aa03ded258c13cf3bc31640778df61e233906d Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Thu, 12 Dec 2024 14:35:34 +0100 Subject: updated test --- src/test/PhysicsTest.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/test/PhysicsTest.cpp') diff --git a/src/test/PhysicsTest.cpp b/src/test/PhysicsTest.cpp index 316a567..198a371 100644 --- a/src/test/PhysicsTest.cpp +++ b/src/test/PhysicsTest.cpp @@ -69,29 +69,30 @@ TEST_F(PhysicsTest, max_velocity) { ComponentManager & mgr = this->component_manager; vector> rigidbodies = mgr.get_components_by_id(0); Rigidbody & rigidbody = rigidbodies.front().get(); + rigidbody.data.gravity_scale = 0; ASSERT_FALSE(rigidbodies.empty()); EXPECT_EQ(rigidbody.data.linear_velocity.y, 0); rigidbody.add_force_linear({100, 100}); rigidbody.add_force_angular(100); system.update(); - EXPECT_EQ(rigidbody.data.linear_velocity.y, 10); - EXPECT_EQ(rigidbody.data.linear_velocity.x, 10); + 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_EQ(rigidbody.data.linear_velocity.y, -10); - EXPECT_EQ(rigidbody.data.linear_velocity.x, -10); + 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); } TEST_F(PhysicsTest, movement) { - Config::get_instance().physics.gravity = 0; ComponentManager & mgr = this->component_manager; vector> rigidbodies = mgr.get_components_by_id(0); Rigidbody & rigidbody = rigidbodies.front().get(); + rigidbody.data.gravity_scale = 0; vector> transforms = mgr.get_components_by_id(0); const Transform & transform = transforms.front().get(); ASSERT_FALSE(rigidbodies.empty()); @@ -100,31 +101,31 @@ TEST_F(PhysicsTest, movement) { rigidbody.add_force_linear({1, 1}); rigidbody.add_force_angular(1); system.update(); - EXPECT_EQ(transform.position.x, 1); - EXPECT_EQ(transform.position.y, 1); - EXPECT_EQ(transform.rotation, 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); rigidbody.data.constraints = {1, 1, 1}; - EXPECT_EQ(transform.position.x, 1); - EXPECT_EQ(transform.position.y, 1); - EXPECT_EQ(transform.rotation, 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); 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_EQ(rigidbody.data.linear_velocity.x, 0.5); - EXPECT_EQ(rigidbody.data.linear_velocity.y, 0.5); - EXPECT_EQ(rigidbody.data.angular_velocity, 0.5); + 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_EQ(transform.rotation, 1); + EXPECT_NEAR(transform.rotation, 7.22,0.0001); rigidbody.data.angular_velocity = -360; system.update(); - EXPECT_EQ(transform.rotation, 1); + EXPECT_NEAR(transform.rotation, 0.02,0.001); } -- cgit v1.2.3