diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2024-11-10 19:34:15 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2024-11-10 19:34:15 +0100 |
commit | e42d0877592aa1e88afbe0bc65822cd53a82205d (patch) | |
tree | 271d0529fc08bd37af193a85325a95ec57e34241 /src/test/ParticleTest.cpp | |
parent | 608a8783d3bbe5845ff87861369fe1287fcbc792 (diff) |
clang format and tidy
Diffstat (limited to 'src/test/ParticleTest.cpp')
-rw-r--r-- | src/test/ParticleTest.cpp | 103 |
1 files changed, 56 insertions, 47 deletions
diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp index 7883eca..6fe3133 100644 --- a/src/test/ParticleTest.cpp +++ b/src/test/ParticleTest.cpp @@ -1,22 +1,20 @@ #include "api/Vector2.h" -#include <math.h> #include <crepe/ComponentManager.h> +#include <crepe/Particle.h> #include <crepe/api/Config.h> #include <crepe/api/GameObject.h> +#include <crepe/api/ParticleEmitter.h> #include <crepe/api/Rigidbody.h> +#include <crepe/api/Sprite.h> #include <crepe/api/Transform.h> -#include <crepe/api/ParticleEmitter.h> -#include <crepe/Particle.h> #include <crepe/system/ParticleSystem.h> #include <gtest/gtest.h> -#include <crepe/api/Sprite.h> +#include <math.h> using namespace std; using namespace std::chrono_literals; using namespace crepe; - - class ParticlesTest : public ::testing::Test { protected: ParticleSystem particle_system; @@ -25,17 +23,16 @@ protected: std::vector<std::reference_wrapper<Transform>> transforms = mgr.get_components_by_id<Transform>(0); if (transforms.empty()) { - - + GameObject game_object(0, "", "", Vector2{0, 0}, 0, 0); Color color(0, 0, 0, 0); Sprite test_sprite = game_object.add_component<Sprite>( - make_shared<Texture>("../asset/texture/img.png"), color, - FlipSettings{true, true}); + make_shared<Texture>("../asset/texture/img.png"), color, + FlipSettings{true, true}); game_object.add_component<ParticleEmitter>(ParticleEmitter::Data{ - .position = {0,0}, + .position = {0, 0}, .max_particles = 100, .emission_rate = 0, .min_speed = 0, @@ -44,11 +41,11 @@ protected: .max_angle = 0, .begin_lifespan = 0, .end_lifespan = 0, - .force_over_time = Vector2{0,0}, + .force_over_time = Vector2{0, 0}, .boundary{ .width = 0, .height = 0, - .offset = Vector2{0,0}, + .offset = Vector2{0, 0}, .reset_on_exit = false, }, .sprite = test_sprite, @@ -72,7 +69,7 @@ protected: emitter.data.end_lifespan = 0; emitter.data.force_over_time = Vector2{0, 0}; emitter.data.boundary = {0, 0, Vector2{0, 0}, false}; - for (auto& particle : emitter.data.particles) { + for (auto & particle : emitter.data.particles) { particle.active = false; } } @@ -81,7 +78,8 @@ protected: TEST_F(ParticlesTest, spawnParticle) { Config::get_instance().physics.gravity = 1; ComponentManager & mgr = ComponentManager::get_instance(); - ParticleEmitter & emitter = mgr.get_components_by_id<ParticleEmitter>(0).front().get(); + ParticleEmitter & emitter + = mgr.get_components_by_id<ParticleEmitter>(0).front().get(); emitter.data.end_lifespan = 5; emitter.data.boundary.height = 100; emitter.data.boundary.width = 100; @@ -89,7 +87,7 @@ TEST_F(ParticlesTest, spawnParticle) { emitter.data.max_angle = 0.1; emitter.data.max_speed = 10; emitter.data.max_angle = 10; - particle_system.update(); + particle_system.update(); //check if nothing happend EXPECT_EQ(emitter.data.particles[0].active, false); emitter.data.emission_rate = 1; @@ -103,24 +101,30 @@ TEST_F(ParticlesTest, spawnParticle) { particle_system.update(); EXPECT_EQ(emitter.data.particles[3].active, true); - for (auto& particle : emitter.data.particles) { - // Check velocity range - EXPECT_GE(particle.velocity.x, emitter.data.min_speed); // Speed should be greater than or equal to min_speed - EXPECT_LE(particle.velocity.x, emitter.data.max_speed); // Speed should be less than or equal to max_speed - EXPECT_GE(particle.velocity.y, emitter.data.min_speed); // Speed should be greater than or equal to min_speed - EXPECT_LE(particle.velocity.y, emitter.data.max_speed); // Speed should be less than or equal to max_speed - - // Check angle range - EXPECT_GE(particle.angle, emitter.data.min_angle); // Angle should be greater than or equal to min_angle - EXPECT_LE(particle.angle, emitter.data.max_angle); // Angle should be less than or equal to max_angle - } - + for (auto & particle : emitter.data.particles) { + // Check velocity range + EXPECT_GE(particle.velocity.x, emitter.data.min_speed); + // Speed should be greater than or equal to min_speed + EXPECT_LE(particle.velocity.x, emitter.data.max_speed); + // Speed should be less than or equal to max_speed + EXPECT_GE(particle.velocity.y, emitter.data.min_speed); + // Speed should be greater than or equal to min_speed + EXPECT_LE(particle.velocity.y, emitter.data.max_speed); + // Speed should be less than or equal to max_speed + + // Check angle range + EXPECT_GE(particle.angle, emitter.data.min_angle); + // Angle should be greater than or equal to min_angle + EXPECT_LE(particle.angle, emitter.data.max_angle); + // Angle should be less than or equal to max_angle + } } TEST_F(ParticlesTest, moveParticleHorizontal) { Config::get_instance().physics.gravity = 1; ComponentManager & mgr = ComponentManager::get_instance(); - ParticleEmitter & emitter = mgr.get_components_by_id<ParticleEmitter>(0).front().get(); + ParticleEmitter & emitter + = mgr.get_components_by_id<ParticleEmitter>(0).front().get(); emitter.data.end_lifespan = 100; emitter.data.boundary.height = 100; emitter.data.boundary.width = 100; @@ -128,17 +132,17 @@ TEST_F(ParticlesTest, moveParticleHorizontal) { emitter.data.max_speed = 1; emitter.data.max_angle = 0; emitter.data.emission_rate = 1; - for (int a = 1; a < emitter.data.boundary.width/2; a++) { - particle_system.update(); - EXPECT_EQ(emitter.data.particles[0].position.x,a); + for (int a = 1; a < emitter.data.boundary.width / 2; a++) { + particle_system.update(); + EXPECT_EQ(emitter.data.particles[0].position.x, a); } } - TEST_F(ParticlesTest, moveParticleVertical) { Config::get_instance().physics.gravity = 1; ComponentManager & mgr = ComponentManager::get_instance(); - ParticleEmitter & emitter = mgr.get_components_by_id<ParticleEmitter>(0).front().get(); + ParticleEmitter & emitter + = mgr.get_components_by_id<ParticleEmitter>(0).front().get(); emitter.data.end_lifespan = 100; emitter.data.boundary.height = 100; emitter.data.boundary.width = 100; @@ -147,16 +151,17 @@ TEST_F(ParticlesTest, moveParticleVertical) { emitter.data.min_angle = 90; emitter.data.max_angle = 90; emitter.data.emission_rate = 1; - for (int a = 1; a < emitter.data.boundary.width/2; a++) { - particle_system.update(); - EXPECT_EQ(emitter.data.particles[0].position.y,a); + for (int a = 1; a < emitter.data.boundary.width / 2; a++) { + particle_system.update(); + EXPECT_EQ(emitter.data.particles[0].position.y, a); } } TEST_F(ParticlesTest, boundaryParticleReset) { Config::get_instance().physics.gravity = 1; ComponentManager & mgr = ComponentManager::get_instance(); - ParticleEmitter & emitter = mgr.get_components_by_id<ParticleEmitter>(0).front().get(); + ParticleEmitter & emitter + = mgr.get_components_by_id<ParticleEmitter>(0).front().get(); emitter.data.end_lifespan = 100; emitter.data.boundary.height = 10; emitter.data.boundary.width = 10; @@ -166,16 +171,17 @@ TEST_F(ParticlesTest, boundaryParticleReset) { emitter.data.min_angle = 90; emitter.data.max_angle = 90; emitter.data.emission_rate = 1; - for (int a = 0; a < emitter.data.boundary.width/2+1; a++) { - particle_system.update(); + for (int a = 0; a < emitter.data.boundary.width / 2 + 1; a++) { + particle_system.update(); } - EXPECT_EQ(emitter.data.particles[0].active,false); + EXPECT_EQ(emitter.data.particles[0].active, false); } TEST_F(ParticlesTest, boundaryParticleStop) { Config::get_instance().physics.gravity = 1; ComponentManager & mgr = ComponentManager::get_instance(); - ParticleEmitter & emitter = mgr.get_components_by_id<ParticleEmitter>(0).front().get(); + ParticleEmitter & emitter + = mgr.get_components_by_id<ParticleEmitter>(0).front().get(); emitter.data.end_lifespan = 100; emitter.data.boundary.height = 10; emitter.data.boundary.width = 10; @@ -185,13 +191,16 @@ TEST_F(ParticlesTest, boundaryParticleStop) { emitter.data.min_angle = 90; emitter.data.max_angle = 90; emitter.data.emission_rate = 1; - for (int a = 0; a < emitter.data.boundary.width/2+1; a++) { - particle_system.update(); + for (int a = 0; a < emitter.data.boundary.width / 2 + 1; a++) { + particle_system.update(); } const double TOLERANCE = 0.01; EXPECT_NEAR(emitter.data.particles[0].velocity.x, 0, TOLERANCE); EXPECT_NEAR(emitter.data.particles[0].velocity.y, 0, TOLERANCE); - if(emitter.data.particles[0].velocity.x != 0) EXPECT_NEAR(std::abs(emitter.data.particles[0].position.x), emitter.data.boundary.height / 2, TOLERANCE); - if(emitter.data.particles[0].velocity.y != 0) EXPECT_NEAR(std::abs(emitter.data.particles[0].position.y), emitter.data.boundary.width / 2, TOLERANCE); + if (emitter.data.particles[0].velocity.x != 0) + EXPECT_NEAR(std::abs(emitter.data.particles[0].position.x), + emitter.data.boundary.height / 2, TOLERANCE); + if (emitter.data.particles[0].velocity.y != 0) + EXPECT_NEAR(std::abs(emitter.data.particles[0].position.y), + emitter.data.boundary.width / 2, TOLERANCE); } - |