Skip to content

Commit

Permalink
Fix animation unit test, expand math test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed Apr 10, 2023
1 parent 8504531 commit d46d2d5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 13 deletions.
24 changes: 12 additions & 12 deletions Tests/Source/UnitTests/Animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,31 @@ TEST_CASE("animation.decorator")
"gradient(horizontal transparent transparent)",
"gradient(horizontal white white)",

"gradient(horizontal rgba(255,255,255,63) rgba(255,255,255,63))",
"gradient(horizontal rgba(127,127,127,63) rgba(127,127,127,63))",
},
{
"", "",

"none",
"gradient(horizontal transparent transparent)",

"gradient(horizontal rgba(255,255,255,191) rgba(255,255,255,191))",
"gradient(horizontal rgba(220,220,220,191) rgba(220,220,220,191))",
},
{
"", "",

"none",
"gradient(horizontal transparent transparent), gradient(vertical transparent transparent)",

"gradient(horizontal rgba(255,255,255,191) rgba(255,255,255,191)), gradient(horizontal rgba(255,255,255,191) rgba(255,255,255,191))",
"gradient(horizontal rgba(220,220,220,191) rgba(220,220,220,191)), gradient(horizontal rgba(220,220,220,191) rgba(220,220,220,191))",
},
{
"", "",

"gradient(horizontal transparent transparent), gradient(vertical transparent transparent)",
"none",

"gradient(horizontal rgba(255,255,255,63) rgba(255,255,255,63)), gradient(vertical rgba(255,255,255,63) rgba(255,255,255,63))",
"gradient(horizontal rgba(127,127,127,63) rgba(127,127,127,63)), gradient(vertical rgba(127,127,127,63) rgba(127,127,127,63))",
},

/// Only rule declaration
Expand All @@ -123,7 +123,7 @@ TEST_CASE("animation.decorator")
"from_rule",
"to_rule",

"gradient(horizontal rgba(255,255,255,63) rgba(255,255,255,63))",
"gradient(horizontal rgba(127,127,127,63) rgba(127,127,127,63))",
},
{
"",
Expand All @@ -132,7 +132,7 @@ TEST_CASE("animation.decorator")
"from_rule",
"to_rule",

"gradient(horizontal rgba(255,255,255,191) rgba(255,255,255,191))",
"gradient(horizontal rgba(220,220,220,191) rgba(220,220,220,191))",
},
{
"direction: vertical; start-color: transparent; stop-color: transparent;",
Expand All @@ -141,7 +141,7 @@ TEST_CASE("animation.decorator")
"from_rule",
"to_rule",

"gradient(vertical rgba(255,255,255,63) rgba(255,255,255,63))",
"gradient(vertical rgba(127,127,127,63) rgba(127,127,127,63))",
},

/// Mix rule and standard declaration
Expand All @@ -152,7 +152,7 @@ TEST_CASE("animation.decorator")
"from_rule",
"gradient(horizontal white white)",

"gradient(horizontal rgba(255,255,255,63) rgba(255,255,255,63))",
"gradient(horizontal rgba(127,127,127,63) rgba(127,127,127,63))",
},
{
"",
Expand All @@ -161,7 +161,7 @@ TEST_CASE("animation.decorator")
"none",
"to_rule",

"gradient(horizontal rgba(255,255,255,191) rgba(255,255,255,191))",
"gradient(horizontal rgba(220,220,220,191) rgba(220,220,220,191))",
},
{
"direction: vertical; start-color: transparent; stop-color: transparent;",
Expand All @@ -170,23 +170,23 @@ TEST_CASE("animation.decorator")
"from_rule",
"none",

"gradient(vertical rgba(255,255,255,63) rgba(255,255,255,63))",
"gradient(vertical rgba(127,127,127,63) rgba(127,127,127,63))",
},
{
"", "",

"from_rule, to_rule",
"gradient(horizontal transparent transparent), gradient(vertical transparent transparent)",

"gradient(horizontal rgba(255,255,255,191) rgba(255,255,255,191)), gradient(horizontal rgba(255,255,255,191) rgba(255,255,255,191))",
"gradient(horizontal rgba(220,220,220,191) rgba(220,220,220,191)), gradient(horizontal rgba(220,220,220,191) rgba(220,220,220,191))",
},
{
"", "",

"gradient(horizontal transparent transparent), gradient(vertical transparent transparent)",
"from_rule, to_rule",

"gradient(horizontal rgba(255,255,255,63) rgba(255,255,255,63)), gradient(vertical rgba(255,255,255,63) rgba(255,255,255,63))",
"gradient(horizontal rgba(127,127,127,63) rgba(127,127,127,63)), gradient(vertical rgba(127,127,127,63) rgba(127,127,127,63))",
},
};

Expand Down
53 changes: 52 additions & 1 deletion Tests/Source/UnitTests/Math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

using namespace Rml;

TEST_CASE("Math")
TEST_CASE("Math.RoundedLerp")
{
const Colourb c0(0, 0, 0, 255);
const Colourb c1(255, 0, 0, 255);
Expand Down Expand Up @@ -103,3 +103,54 @@ TEST_CASE("Math")
REQUIRE(r2 == c2.red);
}
}

TEST_CASE("Math.Clamp")
{
// Clamp(Value, Min, Max)
CHECK(Math::Clamp(1, 1, 2) == 1);
CHECK(Math::Clamp(0, 1, 2) == 1);
CHECK(Math::Clamp(3, 1, 2) == 2);

CHECK(Math::Clamp(0, 2, 1) == 2);
CHECK(Math::Clamp(3, 2, 1) == 1);

CHECK(Math::Clamp<Vector2i>({1, 1}, {1, 1}, {2, 2}) == Vector2i(1, 1));
CHECK(Math::Clamp<Vector2i>({0, 0}, {1, 1}, {2, 2}) == Vector2i(1, 1));
CHECK(Math::Clamp<Vector2i>({3, 3}, {1, 1}, {2, 2}) == Vector2i(2, 2));
CHECK(Math::Clamp<Vector2i>({1, 3}, {1, 1}, {2, 2}) == Vector2i(1, 2));
CHECK(Math::Clamp<Vector2i>({1, 1}, {2, 0}, {2, 0}) == Vector2i(2, 0));

CHECK(Math::Clamp<Vector2f>({1, 1}, {1, 1}, {2, 2}) == Vector2f(1, 1));
CHECK(Math::Clamp<Vector2f>({0, 0}, {1, 1}, {2, 2}) == Vector2f(1, 1));
CHECK(Math::Clamp<Vector2f>({3, 3}, {1, 1}, {2, 2}) == Vector2f(2, 2));
CHECK(Math::Clamp<Vector2f>({1, 3}, {1, 1}, {2, 2}) == Vector2f(1, 2));
CHECK(Math::Clamp<Vector2f>({1, 1}, {2, 0}, {2, 0}) == Vector2f(2, 0));
}

TEST_CASE("Math.Min")
{
CHECK(Math::Min(1, 2) == 1);
CHECK(Math::Min(2, 1) == 1);

CHECK(Math::Min<Vector2i>({1, 1}, {2, 2}) == Vector2i(1, 1));
CHECK(Math::Min<Vector2i>({2, 2}, {1, 1}) == Vector2i(1, 1));
CHECK(Math::Min<Vector2i>({2, 1}, {1, 2}) == Vector2i(1, 1));

CHECK(Math::Min<Vector2f>({1, 1}, {2, 2}) == Vector2f(1, 1));
CHECK(Math::Min<Vector2f>({2, 2}, {1, 1}) == Vector2f(1, 1));
CHECK(Math::Min<Vector2f>({2, 1}, {1, 2}) == Vector2f(1, 1));
}

TEST_CASE("Math.Max")
{
CHECK(Math::Max(1, 2) == 2);
CHECK(Math::Max(2, 1) == 2);

CHECK(Math::Max<Vector2i>({1, 1}, {2, 2}) == Vector2i(2, 2));
CHECK(Math::Max<Vector2i>({2, 2}, {1, 1}) == Vector2i(2, 2));
CHECK(Math::Max<Vector2i>({2, 1}, {1, 2}) == Vector2i(2, 2));

CHECK(Math::Max<Vector2f>({1, 1}, {2, 2}) == Vector2f(2, 2));
CHECK(Math::Max<Vector2f>({2, 2}, {1, 1}) == Vector2f(2, 2));
CHECK(Math::Max<Vector2f>({2, 1}, {1, 2}) == Vector2f(2, 2));
}

0 comments on commit d46d2d5

Please sign in to comment.