From 41b8f220aa013432d259b724eb69303f9f8b1908 Mon Sep 17 00:00:00 2001 From: Lucien Schreiber Date: Sun, 7 Jul 2024 11:55:24 +0200 Subject: [PATCH] Adding test for vrRealRect --- test/src/test_vrrealrect.cpp | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 test/src/test_vrrealrect.cpp diff --git a/test/src/test_vrrealrect.cpp b/test/src/test_vrrealrect.cpp new file mode 100644 index 00000000..7d3ac664 --- /dev/null +++ b/test/src/test_vrrealrect.cpp @@ -0,0 +1,69 @@ +#include +#include "../../src/core/vrrealrect.h" + +// Test fixture for vrRealRect +class VrRealRectTest : public ::testing::Test { + protected: + void SetUp() override { + // Set up common data members here + } + + void TearDown() override { + // Clean up common data members here + } + + vrRealRect rect1; + vrRealRect rect2; +}; + +TEST_F(VrRealRectTest, DefaultConstructor) { + EXPECT_FALSE(rect2.IsOk()); // rect is empty +} + +TEST_F(VrRealRectTest, CopyConstructor) { + rect1 = vrRealRect(0.0, 0.0, 10.0, 10.0); + rect2 = rect1; + vrRealRect rect3(rect1); + EXPECT_TRUE(rect2.IsOk()); + EXPECT_EQ(rect1.GetLeft(), rect2.GetLeft()); + EXPECT_EQ(rect1.GetTop(), rect2.GetTop()); + EXPECT_EQ(rect1.m_width, rect2.m_width); + EXPECT_EQ(rect1.m_width, rect3.m_width); + EXPECT_EQ(rect1.m_height, rect2.m_height); + EXPECT_EQ(rect1.m_height, rect3.m_height); +} + +TEST_F(VrRealRectTest, Constructor) { + vrRealRect rect(0.0, 0.0, 10.0, 10.0); + EXPECT_TRUE(rect.IsOk()); + EXPECT_EQ(rect.GetLeft(), 0.0); + EXPECT_EQ(rect.GetTop(), 0.0); + EXPECT_EQ(rect.m_width, 10.0); + EXPECT_EQ(rect.m_height, 10.0); +} + +TEST_F(VrRealRectTest, Intersect) { + vrRealRect rect1(0.0, 0.0, 10.0, 10.0); + vrRealRect rect2(5.0, 5.0, 5.0, 5.0); + + vrRealRect result = rect1.Intersect(rect2); + + EXPECT_TRUE(result.IsOk()); + EXPECT_EQ(result.GetLeft(), 5.0); + EXPECT_EQ(result.GetTop(), 5.0); + EXPECT_EQ(result.m_width, 5.0); + EXPECT_EQ(result.m_height, 5.0); +} + +TEST_F(VrRealRectTest, IntersectNeg) { + vrRealRect rect1(-10.0, -10.0, 10.0, 10.0); + vrRealRect rect2(-5.0, -5.0, 5.0, 5.0); + + vrRealRect result = rect1.Intersect(rect2); + + EXPECT_TRUE(result.IsOk()); + EXPECT_EQ(result.GetLeft(), -5.0); + EXPECT_EQ(result.GetTop(), -5.0); + EXPECT_EQ(result.m_width, 5.0); + EXPECT_EQ(result.m_height, 5.0); +}