just variadic min and max

This commit is contained in:
2019-09-05 02:10:00 +07:00
parent 137ea5c7f6
commit 0e96190872
8 changed files with 122 additions and 29 deletions

View File

@@ -462,17 +462,58 @@ TEST_CASE("math") {
REQUIRE(math::approximately(math::round(-0.6f), -1.f));
}
{
REQUIRE(math::min(1) == 1);
REQUIRE(math::min(1,1) == 1);
REQUIRE(math::min(1,2) == 1);
REQUIRE(math::min(2,1) == 1);
REQUIRE(math::min(1,1,1) == 1);
REQUIRE(math::min(2,1,1) == 1);
REQUIRE(math::min(1,2,1) == 1);
REQUIRE(math::min(1,1,2) == 1);
REQUIRE(math::min(2,3,4) == 2);
REQUIRE(math::min(2,4,3) == 2);
REQUIRE(math::min(2,3,4,5) == 2);
REQUIRE(math::min(2,4,3,5) == 2);
REQUIRE(math::min(5,3,4,2) == 2);
REQUIRE(math::min(5,4,3,2) == 2);
}
{
REQUIRE(math::max(1) == 1);
REQUIRE(math::max(1,1) == 1);
REQUIRE(math::max(1,2) == 2);
REQUIRE(math::max(2,1) == 2);
REQUIRE(math::max(1,1,1) == 1);
REQUIRE(math::max(2,1,1) == 2);
REQUIRE(math::max(1,2,1) == 2);
REQUIRE(math::max(1,1,2) == 2);
REQUIRE(math::max(2,3,4) == 4);
REQUIRE(math::max(2,3,4,5) == 5);
REQUIRE(math::max(2,4,3,5) == 5);
REQUIRE(math::max(5,3,4,2) == 5);
REQUIRE(math::max(5,4,3,2) == 5);
}
{
REQUIRE(math::minmax(1) == std::make_pair(1,1));
REQUIRE(math::minmax(1,2) == std::make_pair(1,2));
REQUIRE(math::minmax(2,1) == std::make_pair(1,2));
REQUIRE(math::minmax(1,2,3) == std::make_pair(1,3));
REQUIRE(math::minmax(3,2,1) == std::make_pair(1,3));
REQUIRE(math::minmax(1,2,3,4) == std::make_pair(1,4));
REQUIRE(math::minmax(1,3,2,4) == std::make_pair(1,4));
REQUIRE(math::minmax(4,2,3,1) == std::make_pair(1,4));
REQUIRE(math::minmax(4,3,2,1) == std::make_pair(1,4));
}
{
REQUIRE(math::clamp(2,1,3) == 2);
REQUIRE(math::clamp(3,1,3) == 3);
REQUIRE(math::clamp(4,1,3) == 3);

View File

@@ -135,5 +135,8 @@ TEST_CASE("color") {
REQUIRE(colors::pack_color(color(color32(0x12,0x34,0x56,0x78))) == 0x78123456);
REQUIRE(colors::unpack_color(0x04010203) == color(color32(1,2,3,4)));
REQUIRE(colors::unpack_color(0x78123456) == color(color32(0x12,0x34,0x56,0x78)));
REQUIRE(colors::pack_color(color(0.001f,0.001f,0.001f,0.001f)) == 0x00000000);
REQUIRE(colors::pack_color(color(0.999f,0.999f,0.999f,0.999f)) == 0xFFFFFFFF);
}
}

View File

@@ -127,5 +127,8 @@ TEST_CASE("color32") {
REQUIRE(colors::pack_color32(color32(0x12,0x34,0x56,0x78)) == 0x78123456);
REQUIRE(colors::unpack_color32(0x04010203) == color32(1,2,3,4));
REQUIRE(colors::unpack_color32(0x78123456) == color32(0x12,0x34,0x56,0x78));
REQUIRE(colors::pack_color32(color32(0x01,0x01,0x01,0x01)) == 0x01010101);
REQUIRE(colors::pack_color32(color32(0xFE,0xFE,0xFE,0xFE)) == 0xFEFEFEFE);
}
}