diff options
| author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-24 16:39:52 +0100 | 
|---|---|---|
| committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-24 16:39:52 +0100 | 
| commit | eb11f6609ab91bc46948ca9fc5743078f88ae48e (patch) | |
| tree | df8044d7df87b5e5011d6f72d5acc6bbca454445 /src/test | |
| parent | 020cdfddcd06e162515deee4941ce91f3a945ee6 (diff) | |
| parent | 1499363d85abedbdb571e33801b821f4dfabc638 (diff) | |
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/gameloop
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/test/ECSTest.cpp | 36 | ||||
| -rw-r--r-- | src/test/ParticleTest.cpp | 10 | ||||
| -rw-r--r-- | src/test/PhysicsTest.cpp | 4 | ||||
| -rw-r--r-- | src/test/SceneManagerTest.cpp | 14 | ||||
| -rw-r--r-- | src/test/ScriptTest.cpp | 99 | ||||
| -rw-r--r-- | src/test/Vector2Test.cpp | 384 | 
7 files changed, 495 insertions, 54 deletions
| diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 8cb4232..d310f6a 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -11,5 +11,5 @@ target_sources(test_main PUBLIC  	SceneManagerTest.cpp  	ValueBrokerTest.cpp  	DBTest.cpp +	Vector2Test.cpp  ) - diff --git a/src/test/ECSTest.cpp b/src/test/ECSTest.cpp index d5a5826..80b936b 100644 --- a/src/test/ECSTest.cpp +++ b/src/test/ECSTest.cpp @@ -17,7 +17,7 @@ public:  };  TEST_F(ECSTest, createGameObject) { -	GameObject obj = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); +	GameObject obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);  	vector<reference_wrapper<Metadata>> metadata = mgr.get_components_by_type<Metadata>();  	vector<reference_wrapper<Transform>> transform = mgr.get_components_by_type<Transform>(); @@ -37,8 +37,8 @@ TEST_F(ECSTest, createGameObject) {  }  TEST_F(ECSTest, deleteAllGameObjects) { -	GameObject obj0 = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); -	GameObject obj1 = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); +	GameObject obj0 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); +	GameObject obj1 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);  	mgr.delete_all_components(); @@ -48,7 +48,7 @@ TEST_F(ECSTest, deleteAllGameObjects) {  	EXPECT_EQ(metadata.size(), 0);  	EXPECT_EQ(transform.size(), 0); -	GameObject obj2 = mgr.new_object("body2", "person2", Vector2{1, 0}, 5, 1); +	GameObject obj2 = mgr.new_object("body2", "person2", vec2{1, 0}, 5, 1);  	metadata = mgr.get_components_by_type<Metadata>();  	transform = mgr.get_components_by_type<Transform>(); @@ -70,8 +70,8 @@ TEST_F(ECSTest, deleteAllGameObjects) {  }  TEST_F(ECSTest, deleteGameObject) { -	GameObject obj0 = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); -	GameObject obj1 = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); +	GameObject obj0 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); +	GameObject obj1 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);  	mgr.delete_all_components_of_id(0); @@ -96,7 +96,7 @@ TEST_F(ECSTest, deleteGameObject) {  TEST_F(ECSTest, manyGameObjects) {  	for (int i = 0; i < 5000; i++) { -		GameObject obj = mgr.new_object("body", "person", Vector2{0, 0}, 0, i); +		GameObject obj = mgr.new_object("body", "person", vec2{0, 0}, 0, i);  	}  	vector<reference_wrapper<Metadata>> metadata = mgr.get_components_by_type<Metadata>(); @@ -128,7 +128,7 @@ TEST_F(ECSTest, manyGameObjects) {  	for (int i = 0; i < 10000 - 5000; i++) {  		string tag = "person" + to_string(i); -		GameObject obj = mgr.new_object("body", tag, Vector2{0, 0}, i, 0); +		GameObject obj = mgr.new_object("body", tag, vec2{0, 0}, i, 0);  	}  	metadata = mgr.get_components_by_type<Metadata>(); @@ -139,8 +139,8 @@ TEST_F(ECSTest, manyGameObjects) {  }  TEST_F(ECSTest, getComponentsByID) { -	GameObject obj0 = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); -	GameObject obj1 = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); +	GameObject obj0 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); +	GameObject obj1 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);  	vector<reference_wrapper<Metadata>> metadata = mgr.get_components_by_id<Metadata>(0);  	vector<reference_wrapper<Transform>> transform = mgr.get_components_by_id<Transform>(1); @@ -163,15 +163,15 @@ TEST_F(ECSTest, getComponentsByID) {  TEST_F(ECSTest, tooMuchComponents) {  	try { -		GameObject obj0 = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); -		obj0.add_component<Transform>(Vector2{10, 10}, 0, 1); +		GameObject obj0 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); +		obj0.add_component<Transform>(vec2{10, 10}, 0, 1);  	} catch (const exception & e) {  		EXPECT_EQ(e.what(),  				  string("Exceeded maximum number of instances for this component type"));  	}  	try { -		GameObject obj1 = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); +		GameObject obj1 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);  		obj1.add_component<Metadata>("body", "person");  	} catch (const exception & e) {  		EXPECT_EQ(e.what(), @@ -187,11 +187,11 @@ TEST_F(ECSTest, tooMuchComponents) {  TEST_F(ECSTest, partentChild) {  	{ -		GameObject body = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); -		GameObject right_leg = mgr.new_object("rightLeg", "person", Vector2{1, 1}, 0, 1); -		GameObject left_leg = mgr.new_object("leftLeg", "person", Vector2{1, 1}, 0, 1); -		GameObject right_foot = mgr.new_object("rightFoot", "person", Vector2{2, 2}, 0, 1); -		GameObject left_foot = mgr.new_object("leftFoot", "person", Vector2{2, 2}, 0, 1); +		GameObject body = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); +		GameObject right_leg = mgr.new_object("rightLeg", "person", vec2{1, 1}, 0, 1); +		GameObject left_leg = mgr.new_object("leftLeg", "person", vec2{1, 1}, 0, 1); +		GameObject right_foot = mgr.new_object("rightFoot", "person", vec2{2, 2}, 0, 1); +		GameObject left_foot = mgr.new_object("leftFoot", "person", vec2{2, 2}, 0, 1);  		// Set the parent of each GameObject  		right_foot.set_parent(right_leg); diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp index eee022f..8b81e74 100644 --- a/src/test/ParticleTest.cpp +++ b/src/test/ParticleTest.cpp @@ -25,7 +25,7 @@ public:  		std::vector<std::reference_wrapper<Transform>> transforms  			= mgr.get_components_by_id<Transform>(0);  		if (transforms.empty()) { -			GameObject game_object = mgr.new_object("", "", Vector2{0, 0}, 0, 0); +			GameObject game_object = mgr.new_object("", "", vec2{0, 0}, 0, 0);  			Color color(0, 0, 0, 0);  			Sprite & test_sprite = game_object.add_component<Sprite>( @@ -42,11 +42,11 @@ public:  				.max_angle = 0,  				.begin_lifespan = 0,  				.end_lifespan = 0, -				.force_over_time = Vector2{0, 0}, +				.force_over_time = vec2{0, 0},  				.boundary{  					.width = 0,  					.height = 0, -					.offset = Vector2{0, 0}, +					.offset = vec2{0, 0},  					.reset_on_exit = false,  				},  				.sprite = test_sprite, @@ -68,8 +68,8 @@ public:  		emitter.data.max_angle = 0;  		emitter.data.begin_lifespan = 0;  		emitter.data.end_lifespan = 0; -		emitter.data.force_over_time = Vector2{0, 0}; -		emitter.data.boundary = {0, 0, Vector2{0, 0}, false}; +		emitter.data.force_over_time = vec2{0, 0}; +		emitter.data.boundary = {0, 0, vec2{0, 0}, false};  		for (auto & particle : emitter.data.particles) {  			particle.active = false;  		} diff --git a/src/test/PhysicsTest.cpp b/src/test/PhysicsTest.cpp index 1e37c26..33b6020 100644 --- a/src/test/PhysicsTest.cpp +++ b/src/test/PhysicsTest.cpp @@ -20,12 +20,12 @@ public:  		vector<reference_wrapper<Transform>> transforms  			= mgr.get_components_by_id<Transform>(0);  		if (transforms.empty()) { -			auto entity = mgr.new_object("", "", Vector2{0, 0}, 0, 0); +			auto entity = mgr.new_object("", "", vec2{0, 0}, 0, 0);  			entity.add_component<Rigidbody>(Rigidbody::Data{  				.mass = 1,  				.gravity_scale = 1,  				.body_type = Rigidbody::BodyType::DYNAMIC, -				.max_linear_velocity = Vector2{10, 10}, +				.max_linear_velocity = vec2{10, 10},  				.max_angular_velocity = 10,  				.constraints = {0, 0},  				.use_gravity = true, diff --git a/src/test/SceneManagerTest.cpp b/src/test/SceneManagerTest.cpp index 1efcfb2..f3d2387 100644 --- a/src/test/SceneManagerTest.cpp +++ b/src/test/SceneManagerTest.cpp @@ -16,9 +16,9 @@ public:  	void load_scene() {  		auto & mgr = this->component_manager; -		GameObject object1 = mgr.new_object("scene_1", "tag_scene_1", Vector2{0, 0}, 0, 1); -		GameObject object2 = mgr.new_object("scene_1", "tag_scene_1", Vector2{1, 0}, 0, 1); -		GameObject object3 = mgr.new_object("scene_1", "tag_scene_1", Vector2{2, 0}, 0, 1); +		GameObject object1 = mgr.new_object("scene_1", "tag_scene_1", vec2{0, 0}, 0, 1); +		GameObject object2 = mgr.new_object("scene_1", "tag_scene_1", vec2{1, 0}, 0, 1); +		GameObject object3 = mgr.new_object("scene_1", "tag_scene_1", vec2{2, 0}, 0, 1);  	}  	string get_name() const { return "scene1"; } @@ -30,10 +30,10 @@ public:  	void load_scene() {  		auto & mgr = this->component_manager; -		GameObject object1 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 0}, 0, 1); -		GameObject object2 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 1}, 0, 1); -		GameObject object3 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 2}, 0, 1); -		GameObject object4 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 3}, 0, 1); +		GameObject object1 = mgr.new_object("scene_2", "tag_scene_2", vec2{0, 0}, 0, 1); +		GameObject object2 = mgr.new_object("scene_2", "tag_scene_2", vec2{0, 1}, 0, 1); +		GameObject object3 = mgr.new_object("scene_2", "tag_scene_2", vec2{0, 2}, 0, 1); +		GameObject object4 = mgr.new_object("scene_2", "tag_scene_2", vec2{0, 3}, 0, 1);  	}  	string get_name() const { return "scene2"; } diff --git a/src/test/ScriptTest.cpp b/src/test/ScriptTest.cpp index 19fef6d..78d5061 100644 --- a/src/test/ScriptTest.cpp +++ b/src/test/ScriptTest.cpp @@ -6,6 +6,8 @@  #include <crepe/ComponentManager.h>  #include <crepe/api/BehaviorScript.h> +#include <crepe/api/Event.h> +#include <crepe/api/EventManager.h>  #include <crepe/api/GameObject.h>  #include <crepe/api/Script.h>  #include <crepe/api/Vector2.h> @@ -15,58 +17,113 @@ using namespace std;  using namespace crepe;  using namespace testing; +class MyEvent : public Event {}; +  class ScriptTest : public Test {  public:  	ComponentManager component_manager{};  	ScriptSystem system{component_manager}; +	EventManager & event_manager = EventManager::get_instance();  	class MyScript : public Script {  		// NOTE: default (private) visibility of init and update shouldn't cause  		// issues! -		void init() { this->init_count++; } +		void init() { +			this->init_count++; + +			subscribe<MyEvent>([this](const MyEvent &) { +				this->event_count++; +				return true; +			}); + +			// init should never be called more than once +			EXPECT_LE(this->init_count, 1); +		}  		void update() { this->update_count++; }  	public:  		unsigned init_count = 0;  		unsigned update_count = 0; +		unsigned event_count = 0;  	}; -	BehaviorScript * behaviorscript_ref = nullptr; -	MyScript * script_ref = nullptr; +	OptionalRef<BehaviorScript> behaviorscript; +	OptionalRef<MyScript> script;  	void SetUp() override {  		auto & mgr = this->component_manager;  		GameObject entity = mgr.new_object("name");  		BehaviorScript & component = entity.add_component<BehaviorScript>(); -		this->behaviorscript_ref = &component; -		EXPECT_EQ(this->behaviorscript_ref->script.get(), nullptr); +		this->behaviorscript = component; +		ASSERT_TRUE(this->behaviorscript); +		EXPECT_EQ(component.script.get(), nullptr);  		component.set_script<MyScript>(); -		ASSERT_NE(this->behaviorscript_ref->script.get(), nullptr); +		ASSERT_NE(component.script.get(), nullptr); -		this->script_ref = (MyScript *) this->behaviorscript_ref->script.get(); -		ASSERT_NE(this->script_ref, nullptr); +		this->script = *(MyScript *) component.script.get(); +		ASSERT_TRUE(this->script); + +		// sanity +		MyScript & script = this->script; +		ASSERT_EQ(script.init_count, 0); +		ASSERT_EQ(script.update_count, 0); +		ASSERT_EQ(script.event_count, 0);  	}  };  TEST_F(ScriptTest, Default) { -	EXPECT_EQ(0, this->script_ref->init_count); -	EXPECT_EQ(0, this->script_ref->update_count); +	MyScript & script = this->script; +	EXPECT_EQ(0, script.init_count); +	EXPECT_EQ(0, script.update_count); +	EXPECT_EQ(0, script.event_count);  }  TEST_F(ScriptTest, UpdateOnce) { -	EXPECT_EQ(0, this->script_ref->init_count); -	EXPECT_EQ(0, this->script_ref->update_count); +	MyScript & script = this->script; -	this->system.update(); -	EXPECT_EQ(1, this->script_ref->init_count); -	EXPECT_EQ(1, this->script_ref->update_count); +	system.update(); +	EXPECT_EQ(1, script.init_count); +	EXPECT_EQ(1, script.update_count); +	EXPECT_EQ(0, script.event_count);  } -TEST_F(ScriptTest, ListScripts) { -	size_t script_count = 0; -	for (auto & _ : this->system.get_scripts()) { -		script_count++; -	} -	ASSERT_EQ(1, script_count); +TEST_F(ScriptTest, UpdateInactive) { +	BehaviorScript & behaviorscript = this->behaviorscript; +	MyScript & script = this->script; + +	behaviorscript.active = false; +	system.update(); +	EXPECT_EQ(0, script.init_count); +	EXPECT_EQ(0, script.update_count); +	EXPECT_EQ(0, script.event_count); + +	behaviorscript.active = true; +	system.update(); +	EXPECT_EQ(1, script.init_count); +	EXPECT_EQ(1, script.update_count); +	EXPECT_EQ(0, script.event_count); +} + +TEST_F(ScriptTest, EventInactive) { +	BehaviorScript & behaviorscript = this->behaviorscript; +	MyScript & script = this->script; +	EventManager & evmgr = this->event_manager; + +	system.update(); +	behaviorscript.active = false; +	EXPECT_EQ(1, script.init_count); +	EXPECT_EQ(1, script.update_count); +	EXPECT_EQ(0, script.event_count); + +	evmgr.trigger_event<MyEvent>(); +	EXPECT_EQ(1, script.init_count); +	EXPECT_EQ(1, script.update_count); +	EXPECT_EQ(0, script.event_count); + +	behaviorscript.active = true; +	evmgr.trigger_event<MyEvent>(); +	EXPECT_EQ(1, script.init_count); +	EXPECT_EQ(1, script.update_count); +	EXPECT_EQ(1, script.event_count);  } diff --git a/src/test/Vector2Test.cpp b/src/test/Vector2Test.cpp new file mode 100644 index 0000000..17bca41 --- /dev/null +++ b/src/test/Vector2Test.cpp @@ -0,0 +1,384 @@ +#include <gtest/gtest.h> + +#include <crepe/api/Vector2.h> + +using namespace crepe; + +class Vector2Test : public ::testing::Test { +public: +	Vector2<int> int_vec1; +	Vector2<int> int_vec2; +	Vector2<double> double_vec1; +	Vector2<double> double_vec2; +	Vector2<long> long_vec1; +	Vector2<long> long_vec2; +	Vector2<float> float_vec1; +	Vector2<float> float_vec2; + +	void SetUp() override { +		int_vec1 = {1, 2}; +		int_vec2 = {3, 4}; +		double_vec1 = {1.0, 2.0}; +		double_vec2 = {3.0, 4.0}; +		long_vec1 = {1, 2}; +		long_vec2 = {3, 4}; +		float_vec1 = {1.0f, 2.0f}; +		float_vec2 = {3.0f, 4.0f}; +	} +}; + +TEST_F(Vector2Test, Subtract) { +	Vector2<int> result = int_vec1 - int_vec2; +	EXPECT_EQ(result.x, -2); +	EXPECT_EQ(result.y, -2); + +	Vector2<double> result2 = double_vec1 - double_vec2; +	EXPECT_FLOAT_EQ(result2.x, -2.0); +	EXPECT_FLOAT_EQ(result2.y, -2.0); + +	Vector2<long> result3 = long_vec1 - long_vec2; +	EXPECT_EQ(result3.x, -2); +	EXPECT_EQ(result3.y, -2); + +	Vector2<float> result4 = float_vec1 - float_vec2; +	EXPECT_FLOAT_EQ(result4.x, -2.0f); +	EXPECT_FLOAT_EQ(result4.y, -2.0f); +} + +TEST_F(Vector2Test, SubtractScalar) { +	Vector2<int> result = int_vec1 - 1; +	EXPECT_EQ(result.x, 0); +	EXPECT_EQ(result.y, 1); + +	Vector2<double> result2 = double_vec1 - 1.0; +	EXPECT_FLOAT_EQ(result2.x, 0.0); +	EXPECT_FLOAT_EQ(result2.y, 1.0); + +	Vector2<long> result3 = long_vec1 - 1; +	EXPECT_EQ(result3.x, 0); +	EXPECT_EQ(result3.y, 1); + +	Vector2<float> result4 = float_vec1 - 1.0f; +	EXPECT_FLOAT_EQ(result4.x, 0.0f); +	EXPECT_FLOAT_EQ(result4.y, 1.0f); +} + +TEST_F(Vector2Test, Add) { +	Vector2<int> result = int_vec1 + int_vec2; +	EXPECT_EQ(result.x, 4); +	EXPECT_EQ(result.y, 6); + +	Vector2<double> result2 = double_vec1 + double_vec2; +	EXPECT_FLOAT_EQ(result2.x, 4.0); +	EXPECT_FLOAT_EQ(result2.y, 6.0); + +	Vector2<long> result3 = long_vec1 + long_vec2; +	EXPECT_EQ(result3.x, 4); +	EXPECT_EQ(result3.y, 6); + +	Vector2<float> result4 = float_vec1 + float_vec2; +	EXPECT_FLOAT_EQ(result4.x, 4.0f); +	EXPECT_FLOAT_EQ(result4.y, 6.0f); +} + +TEST_F(Vector2Test, AddScalar) { +	Vector2<int> result = int_vec1 + 1; +	EXPECT_EQ(result.x, 2); +	EXPECT_EQ(result.y, 3); + +	Vector2<double> result2 = double_vec1 + 1.0; +	EXPECT_FLOAT_EQ(result2.x, 2.0); +	EXPECT_FLOAT_EQ(result2.y, 3.0); + +	Vector2<long> result3 = long_vec1 + 1; +	EXPECT_EQ(result3.x, 2); +	EXPECT_EQ(result3.y, 3); + +	Vector2<float> result4 = float_vec1 + 1.0f; +	EXPECT_FLOAT_EQ(result4.x, 2.0f); +	EXPECT_FLOAT_EQ(result4.y, 3.0f); +} + +TEST_F(Vector2Test, Multiply) { +	Vector2<int> result = int_vec1 * int_vec2; +	EXPECT_EQ(result.x, 3); +	EXPECT_EQ(result.y, 8); + +	Vector2<double> result2 = double_vec1 * double_vec2; +	EXPECT_FLOAT_EQ(result2.x, 3.0); +	EXPECT_FLOAT_EQ(result2.y, 8.0); + +	Vector2<long> result3 = long_vec1 * long_vec2; +	EXPECT_EQ(result3.x, 3); +	EXPECT_EQ(result3.y, 8); + +	Vector2<float> result4 = float_vec1 * float_vec2; +	EXPECT_FLOAT_EQ(result4.x, 3.0f); +	EXPECT_FLOAT_EQ(result4.y, 8.0f); +} + +TEST_F(Vector2Test, MultiplyScalar) { +	Vector2<int> result = int_vec1 * 2; +	EXPECT_EQ(result.x, 2); +	EXPECT_EQ(result.y, 4); + +	Vector2<double> result2 = double_vec1 * 2.0; +	EXPECT_FLOAT_EQ(result2.x, 2.0); +	EXPECT_FLOAT_EQ(result2.y, 4.0); + +	Vector2<long> result3 = long_vec1 * 2; +	EXPECT_EQ(result3.x, 2); +	EXPECT_EQ(result3.y, 4); + +	Vector2<float> result4 = float_vec1 * 2.0f; +	EXPECT_FLOAT_EQ(result4.x, 2.0f); +	EXPECT_FLOAT_EQ(result4.y, 4.0f); +} + +TEST_F(Vector2Test, Divide) { +	Vector2<int> result = int_vec1 / int_vec2; +	EXPECT_EQ(result.x, 0); +	EXPECT_EQ(result.y, 0); + +	Vector2<double> result2 = double_vec1 / double_vec2; +	EXPECT_FLOAT_EQ(result2.x, 0.33333333333333331); +	EXPECT_FLOAT_EQ(result2.y, 0.5); + +	Vector2<long> result3 = long_vec1 / long_vec2; +	EXPECT_EQ(result3.x, 0); +	EXPECT_EQ(result3.y, 0); + +	Vector2<float> result4 = float_vec1 / float_vec2; +	EXPECT_FLOAT_EQ(result4.x, 0.333333343f); +	EXPECT_FLOAT_EQ(result4.y, 0.5f); +} + +TEST_F(Vector2Test, DivideScalar) { +	Vector2<int> result = int_vec1 / 2; +	EXPECT_EQ(result.x, 0); +	EXPECT_EQ(result.y, 1); + +	Vector2<double> result2 = double_vec1 / 2.0; +	EXPECT_FLOAT_EQ(result2.x, 0.5); +	EXPECT_FLOAT_EQ(result2.y, 1.0); + +	Vector2<long> result3 = long_vec1 / 2; +	EXPECT_EQ(result3.x, 0); +	EXPECT_EQ(result3.y, 1); + +	Vector2<float> result4 = float_vec1 / 2.0f; +	EXPECT_FLOAT_EQ(result4.x, 0.5f); +	EXPECT_FLOAT_EQ(result4.y, 1.0f); +} + +TEST_F(Vector2Test, AddChain) { +	Vector2<int> result = int_vec1; +	result += int_vec2; +	EXPECT_EQ(result.x, 4); +	EXPECT_EQ(result.y, 6); + +	Vector2<double> result2 = double_vec1; +	result2 += double_vec2; +	EXPECT_FLOAT_EQ(result2.x, 4.0); +	EXPECT_FLOAT_EQ(result2.y, 6.0); + +	Vector2<long> result3 = long_vec1; +	result3 += long_vec2; +	EXPECT_EQ(result3.x, 4); +	EXPECT_EQ(result3.y, 6); + +	Vector2<float> result4 = float_vec1; +	result4 += float_vec2; +	EXPECT_FLOAT_EQ(result4.x, 4.0f); +	EXPECT_FLOAT_EQ(result4.y, 6.0f); +} + +TEST_F(Vector2Test, AddScalarChain) { +	Vector2<int> result = int_vec1; +	result += 1; +	EXPECT_EQ(result.x, 2); +	EXPECT_EQ(result.y, 3); + +	Vector2<double> result2 = double_vec1; +	result2 += 1.0; +	EXPECT_FLOAT_EQ(result2.x, 2.0); +	EXPECT_FLOAT_EQ(result2.y, 3.0); + +	Vector2<long> result3 = long_vec1; +	result3 += 1; +	EXPECT_EQ(result3.x, 2); +	EXPECT_EQ(result3.y, 3); + +	Vector2<float> result4 = float_vec1; +	result4 += 1.0f; +	EXPECT_FLOAT_EQ(result4.x, 2.0f); +	EXPECT_FLOAT_EQ(result4.y, 3.0f); +} + +TEST_F(Vector2Test, SubtractChain) { +	Vector2<int> result = int_vec1; +	result -= int_vec2; +	EXPECT_EQ(result.x, -2); +	EXPECT_EQ(result.y, -2); + +	Vector2<double> result2 = double_vec1; +	result2 -= double_vec2; +	EXPECT_FLOAT_EQ(result2.x, -2.0); +	EXPECT_FLOAT_EQ(result2.y, -2.0); + +	Vector2<long> result3 = long_vec1; +	result3 -= long_vec2; +	EXPECT_EQ(result3.x, -2); +	EXPECT_EQ(result3.y, -2); + +	Vector2<float> result4 = float_vec1; +	result4 -= float_vec2; +	EXPECT_FLOAT_EQ(result4.x, -2.0f); +	EXPECT_FLOAT_EQ(result4.y, -2.0f); +} + +TEST_F(Vector2Test, SubtractScalarChain) { +	Vector2<int> result = int_vec1; +	result -= 1; +	EXPECT_EQ(result.x, 0); +	EXPECT_EQ(result.y, 1); + +	Vector2<double> result2 = double_vec1; +	result2 -= 1.0; +	EXPECT_FLOAT_EQ(result2.x, 0.0); +	EXPECT_FLOAT_EQ(result2.y, 1.0); + +	Vector2<long> result3 = long_vec1; +	result3 -= 1; +	EXPECT_EQ(result3.x, 0); +	EXPECT_EQ(result3.y, 1); + +	Vector2<float> result4 = float_vec1; +	result4 -= 1.0f; +	EXPECT_FLOAT_EQ(result4.x, 0.0f); +	EXPECT_FLOAT_EQ(result4.y, 1.0f); +} + +TEST_F(Vector2Test, MultiplyChain) { +	Vector2<int> result = int_vec1; +	result *= int_vec2; +	EXPECT_EQ(result.x, 3); +	EXPECT_EQ(result.y, 8); + +	Vector2<double> result2 = double_vec1; +	result2 *= double_vec2; +	EXPECT_FLOAT_EQ(result2.x, 3.0); +	EXPECT_FLOAT_EQ(result2.y, 8.0); + +	Vector2<long> result3 = long_vec1; +	result3 *= long_vec2; +	EXPECT_EQ(result3.x, 3); +	EXPECT_EQ(result3.y, 8); + +	Vector2<float> result4 = float_vec1; +	result4 *= float_vec2; +	EXPECT_FLOAT_EQ(result4.x, 3.0f); +	EXPECT_FLOAT_EQ(result4.y, 8.0f); +} + +TEST_F(Vector2Test, MultiplyScalarChain) { +	Vector2<int> result = int_vec1; +	result *= 2; +	EXPECT_EQ(result.x, 2); +	EXPECT_EQ(result.y, 4); + +	Vector2<double> result2 = double_vec1; +	result2 *= 2.0; +	EXPECT_FLOAT_EQ(result2.x, 2.0); +	EXPECT_FLOAT_EQ(result2.y, 4.0); + +	Vector2<long> result3 = long_vec1; +	result3 *= 2; +	EXPECT_EQ(result3.x, 2); +	EXPECT_EQ(result3.y, 4); + +	Vector2<float> result4 = float_vec1; +	result4 *= 2.0f; +	EXPECT_FLOAT_EQ(result4.x, 2.0f); +	EXPECT_FLOAT_EQ(result4.y, 4.0f); +} + +TEST_F(Vector2Test, DivideChain) { +	Vector2<int> result = int_vec1; +	result /= int_vec2; +	EXPECT_EQ(result.x, 0); +	EXPECT_EQ(result.y, 0); + +	Vector2<double> result2 = double_vec1; +	result2 /= double_vec2; +	EXPECT_FLOAT_EQ(result2.x, 0.33333333333333331); +	EXPECT_FLOAT_EQ(result2.y, 0.5); + +	Vector2<long> result3 = long_vec1; +	result3 /= long_vec2; +	EXPECT_EQ(result3.x, 0); +	EXPECT_EQ(result3.y, 0); + +	Vector2<float> result4 = float_vec1; +	result4 /= float_vec2; +	EXPECT_FLOAT_EQ(result4.x, 0.333333343f); +	EXPECT_FLOAT_EQ(result4.y, 0.5f); +} + +TEST_F(Vector2Test, DivideScalarChain) { +	Vector2<int> result = int_vec1; +	result /= 2; +	EXPECT_EQ(result.x, 0); +	EXPECT_EQ(result.y, 1); + +	Vector2<double> result2 = double_vec1; +	result2 /= 2.0; +	EXPECT_FLOAT_EQ(result2.x, 0.5); +	EXPECT_FLOAT_EQ(result2.y, 1.0); + +	Vector2<long> result3 = long_vec1; +	result3 /= 2; +	EXPECT_EQ(result3.x, 0); +	EXPECT_EQ(result3.y, 1); + +	Vector2<float> result4 = float_vec1; +	result4 /= 2.0f; +	EXPECT_FLOAT_EQ(result4.x, 0.5f); +	EXPECT_FLOAT_EQ(result4.y, 1.0f); +} + +TEST_F(Vector2Test, Negatation) { +	Vector2<int> result = -int_vec1; +	EXPECT_EQ(result.x, -1); +	EXPECT_EQ(result.y, -2); + +	Vector2<double> result2 = -double_vec1; +	EXPECT_FLOAT_EQ(result2.x, -1.0); +	EXPECT_FLOAT_EQ(result2.y, -2.0); + +	Vector2<long> result3 = -long_vec1; +	EXPECT_EQ(result3.x, -1); +	EXPECT_EQ(result3.y, -2); + +	Vector2<float> result4 = -float_vec1; +	EXPECT_FLOAT_EQ(result4.x, -1.0f); +	EXPECT_FLOAT_EQ(result4.y, -2.0f); +} + +TEST_F(Vector2Test, Equals) { +	EXPECT_TRUE(int_vec1 == int_vec1); +	EXPECT_FALSE(int_vec1 == int_vec2); +	EXPECT_TRUE(double_vec1 == double_vec1); +	EXPECT_FALSE(double_vec1 == double_vec2); +	EXPECT_TRUE(long_vec1 == long_vec1); +	EXPECT_FALSE(long_vec1 == long_vec2); +} + +TEST_F(Vector2Test, NotEquals) { +	EXPECT_FALSE(int_vec1 != int_vec1); +	EXPECT_TRUE(int_vec1 != int_vec2); +	EXPECT_FALSE(double_vec1 != double_vec1); +	EXPECT_TRUE(double_vec1 != double_vec2); +	EXPECT_FALSE(long_vec1 != long_vec1); +	EXPECT_TRUE(long_vec1 != long_vec2); +} |