aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-12-12 14:35:34 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-12-12 14:35:34 +0100
commit91aa03ded258c13cf3bc31640778df61e233906d (patch)
tree281585b2a68bd77dd0e81ee40efff9c27dd96211
parenta4c65ca6a69987349f703e51beed47a219d3d92d (diff)
updated test
-rw-r--r--src/test/PhysicsTest.cpp33
1 files changed, 17 insertions, 16 deletions
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<reference_wrapper<Rigidbody>> rigidbodies = mgr.get_components_by_id<Rigidbody>(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<reference_wrapper<Rigidbody>> rigidbodies = mgr.get_components_by_id<Rigidbody>(0);
Rigidbody & rigidbody = rigidbodies.front().get();
+ rigidbody.data.gravity_scale = 0;
vector<reference_wrapper<Transform>> transforms = mgr.get_components_by_id<Transform>(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);
}