mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
added tests for color fixed matrix move operator
This commit is contained in:
@@ -13,7 +13,7 @@ namespace omath
|
||||
float w = 0.f;
|
||||
|
||||
Vector4(const float x = 0.f, const float y = 0.f, const float z = 0.f, const float w = 0.f) : Vector3(x, y, z), w(w) {}
|
||||
Vector4() = default;
|
||||
Vector4();
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator==(const Vector4& src) const;
|
||||
|
||||
@@ -21,11 +21,11 @@ namespace omath::color
|
||||
[[nodiscard]]
|
||||
Vector3 Blend(const Vector3& first, const Vector3& second, float ratio);
|
||||
|
||||
class Color : public Vector4
|
||||
class Color final : public Vector4
|
||||
{
|
||||
public:
|
||||
Color(float r, float g, float b, float a);
|
||||
|
||||
explicit Color();
|
||||
[[nodiscard]]
|
||||
static Color FromRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
|
||||
|
||||
|
||||
@@ -131,4 +131,11 @@ namespace omath
|
||||
{
|
||||
return x + y + z + w;
|
||||
}
|
||||
|
||||
Vector4::Vector4()
|
||||
{
|
||||
x = 0.f;
|
||||
y = 0.f;
|
||||
z = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,4 +95,9 @@ namespace omath::color
|
||||
|
||||
return hsvData;
|
||||
}
|
||||
|
||||
Color::Color() : Vector4(0.f, 0.f, 0.f, 0.f)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,6 +200,9 @@ namespace omath
|
||||
m_columns = other.m_columns;
|
||||
m_data = std::move(other.m_data);
|
||||
|
||||
other.m_rows = 0.f;
|
||||
other.m_columns = 0.f;
|
||||
|
||||
return *this;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,10 +2,15 @@ enable_testing()
|
||||
|
||||
project(unit-tests)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}")
|
||||
file(GLOB TEST_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
||||
|
||||
include(GoogleTest)
|
||||
add_executable(unit-tests UnitTestPrediction.cpp UnitTestMatrix.cpp UnitTestAstar.cpp UnitTestProjection.cpp UnitTestVector3.cpp)
|
||||
add_executable(unit-tests
|
||||
UnitTestPrediction.cpp
|
||||
UnitTestMatrix.cpp
|
||||
UnitTestAstar.cpp
|
||||
UnitTestProjection.cpp
|
||||
UnitTestVector3.cpp
|
||||
UnitTestColor.cpp)
|
||||
|
||||
target_link_libraries(unit-tests PRIVATE gtest gtest_main omath)
|
||||
|
||||
|
||||
113
tests/UnitTestColor.cpp
Normal file
113
tests/UnitTestColor.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
//
|
||||
// Created by Vlad on 01.09.2024.
|
||||
//
|
||||
#include <gtest/gtest.h>
|
||||
#include <omath/Color.h>
|
||||
|
||||
|
||||
using namespace omath::color;
|
||||
|
||||
class ColorTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
Color color1;
|
||||
Color color2;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
color1 = Color::Red();
|
||||
color2 = Color::Green();
|
||||
}
|
||||
};
|
||||
|
||||
// Test constructors
|
||||
TEST_F(ColorTest, Constructor_Float)
|
||||
{
|
||||
Color color(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
EXPECT_FLOAT_EQ(color.x, 0.5f);
|
||||
EXPECT_FLOAT_EQ(color.y, 0.5f);
|
||||
EXPECT_FLOAT_EQ(color.z, 0.5f);
|
||||
EXPECT_FLOAT_EQ(color.w, 1.0f);
|
||||
}
|
||||
|
||||
TEST_F(ColorTest, Constructor_Vector4)
|
||||
{
|
||||
omath::Vector4 vec(0.2f, 0.4f, 0.6f, 0.8f);
|
||||
Color color(vec);
|
||||
EXPECT_FLOAT_EQ(color.x, 0.2f);
|
||||
EXPECT_FLOAT_EQ(color.y, 0.4f);
|
||||
EXPECT_FLOAT_EQ(color.z, 0.6f);
|
||||
EXPECT_FLOAT_EQ(color.w, 0.8f);
|
||||
}
|
||||
|
||||
// Test static methods for color creation
|
||||
TEST_F(ColorTest, FromRGBA)
|
||||
{
|
||||
Color color = Color::FromRGBA(128, 64, 32, 255);
|
||||
EXPECT_FLOAT_EQ(color.x, 128.0f / 255.0f);
|
||||
EXPECT_FLOAT_EQ(color.y, 64.0f / 255.0f);
|
||||
EXPECT_FLOAT_EQ(color.z, 32.0f / 255.0f);
|
||||
EXPECT_FLOAT_EQ(color.w, 1.0f);
|
||||
}
|
||||
|
||||
TEST_F(ColorTest, FromHSV)
|
||||
{
|
||||
Color color = Color::FromHSV(0.0f, 1.0f, 1.0f); // Red in HSV
|
||||
EXPECT_FLOAT_EQ(color.x, 1.0f);
|
||||
EXPECT_FLOAT_EQ(color.y, 0.0f);
|
||||
EXPECT_FLOAT_EQ(color.z, 0.0f);
|
||||
EXPECT_FLOAT_EQ(color.w, 1.0f);
|
||||
}
|
||||
|
||||
// Test HSV conversion
|
||||
TEST_F(ColorTest, ToHSV)
|
||||
{
|
||||
HSV hsv = color1.ToHSV(); // Red color
|
||||
EXPECT_FLOAT_EQ(hsv.m_hue, 0.0f);
|
||||
EXPECT_FLOAT_EQ(hsv.m_saturation, 1.0f);
|
||||
EXPECT_FLOAT_EQ(hsv.m_value, 1.0f);
|
||||
}
|
||||
|
||||
// Test color blending
|
||||
TEST_F(ColorTest, Blend)
|
||||
{
|
||||
Color blended = color1.Blend(color2, 0.5f);
|
||||
EXPECT_FLOAT_EQ(blended.x, 0.5f);
|
||||
EXPECT_FLOAT_EQ(blended.y, 0.5f);
|
||||
EXPECT_FLOAT_EQ(blended.z, 0.0f);
|
||||
EXPECT_FLOAT_EQ(blended.w, 1.0f);
|
||||
}
|
||||
|
||||
// Test predefined colors
|
||||
TEST_F(ColorTest, PredefinedColors)
|
||||
{
|
||||
Color red = Color::Red();
|
||||
Color green = Color::Green();
|
||||
Color blue = Color::Blue();
|
||||
|
||||
EXPECT_FLOAT_EQ(red.x, 1.0f);
|
||||
EXPECT_FLOAT_EQ(red.y, 0.0f);
|
||||
EXPECT_FLOAT_EQ(red.z, 0.0f);
|
||||
EXPECT_FLOAT_EQ(red.w, 1.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(green.x, 0.0f);
|
||||
EXPECT_FLOAT_EQ(green.y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(green.z, 0.0f);
|
||||
EXPECT_FLOAT_EQ(green.w, 1.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(blue.x, 0.0f);
|
||||
EXPECT_FLOAT_EQ(blue.y, 0.0f);
|
||||
EXPECT_FLOAT_EQ(blue.z, 1.0f);
|
||||
EXPECT_FLOAT_EQ(blue.w, 1.0f);
|
||||
}
|
||||
|
||||
// Test non-member function: Blend for Vector3
|
||||
TEST_F(ColorTest, BlendVector3)
|
||||
{
|
||||
omath::Vector3 v1(1.0f, 0.0f, 0.0f); // Red
|
||||
omath::Vector3 v2(0.0f, 1.0f, 0.0f); // Green
|
||||
omath::Vector3 blended = Blend(v1, v2, 0.5f);
|
||||
EXPECT_FLOAT_EQ(blended.x, 0.5f);
|
||||
EXPECT_FLOAT_EQ(blended.y, 0.5f);
|
||||
EXPECT_FLOAT_EQ(blended.z, 0.0f);
|
||||
}
|
||||
Reference in New Issue
Block a user