diff --git a/src/caste.hpp b/src/caste.hpp index 8eb851e..b8667fc 100644 --- a/src/caste.hpp +++ b/src/caste.hpp @@ -2,6 +2,7 @@ #include #include +#include enum class Caste { Mini, @@ -43,16 +44,16 @@ struct CasteRange { Caste min; Caste max; - constexpr Caste lower() const { - return min <= max ? min : max; - } - - constexpr Caste upper() const { - return min <= max ? max : min; + constexpr CasteRange(Caste a, Caste b) + : min{}, max{} + { + auto [lo, hi] = std::minmax(a, b); + min = lo; + max = hi; } constexpr bool contains(Caste caste) const { - return caste >= lower() && caste <= upper(); + return caste >= min && caste <= max; } }; diff --git a/tests/test_classify.cpp b/tests/test_classify.cpp index 7272936..d5f6c8c 100644 --- a/tests/test_classify.cpp +++ b/tests/test_classify.cpp @@ -129,8 +129,8 @@ TEST_CASE("Caste ranges support reusable policy buckets") { TEST_CASE("Caste ranges normalize reversed endpoints") { constexpr CasteRange rigs_down_to_user{Caste::Rig, Caste::User}; - REQUIRE(rigs_down_to_user.lower() == Caste::User); - REQUIRE(rigs_down_to_user.upper() == Caste::Rig); + REQUIRE(rigs_down_to_user.min == Caste::User); + REQUIRE(rigs_down_to_user.max == Caste::Rig); REQUIRE(rigs_down_to_user.contains(Caste::User)); REQUIRE(rigs_down_to_user.contains(Caste::Developer)); REQUIRE(rigs_down_to_user.contains(Caste::Workstation));