Skip to content

Commit

Permalink
Added tests for gp::Color attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Bhavye Mathur <[email protected]>
  • Loading branch information
BhavyeMathur committed Feb 16, 2024
1 parent 3f7b0a2 commit 3621aeb
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/color/color_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,38 @@ TEST(CoreColorTests, ColorToString) {
gp::Color color{0, 10, 20};
EXPECT_EQ(color.toString(), "Color(0, 10, 20, 1.00)");
}

TEST(CoreColorTests, ColorAttributes) {
gp::Color color{0, 0, 0};

color.setRed(153);
EXPECT_EQ(color.getRed(), 153);
EXPECT_EQ(color.getRedf(), 0.6f);

color.setGreen(102);
EXPECT_EQ(color.getGreen(), 102);
EXPECT_EQ(color.getGreenf(), 0.4f);

color.setBlue(51);
EXPECT_EQ(color.getBlue(), 51);
EXPECT_EQ(color.getBluef(), 0.2f);

color.setAlpha(0.5);
EXPECT_EQ(color.getAlpha(), 0.5);
}

TEST(CoreColorTests, ColorAttributesError) {
gp::Color color{0, 0, 0};

EXPECT_THROW(color.setRed(300), std::invalid_argument);
EXPECT_THROW(color.setRed(-30), std::invalid_argument);

EXPECT_THROW(color.setGreen(300), std::invalid_argument);
EXPECT_THROW(color.setGreen(-30), std::invalid_argument);

EXPECT_THROW(color.setBlue(300), std::invalid_argument);
EXPECT_THROW(color.setBlue(-30), std::invalid_argument);

EXPECT_THROW(color.setAlpha(2), std::invalid_argument);
EXPECT_THROW(color.setAlpha(-0.5), std::invalid_argument);
}

0 comments on commit 3621aeb

Please sign in to comment.