From ffef4b889edd1204e42dfd2e71486894e0ffd106 Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Fri, 23 May 2025 07:25:35 -0600 Subject: [PATCH] :white_check_mark: Add tests for `to_underlying` with arithmetic types Problem: - `to_underlying` works with many types, but is only tested with enums and `int`. Solution: - Add template tests for more integral and floating-point types. --- test/to_underlying.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/test/to_underlying.cpp b/test/to_underlying.cpp index abc032e..eaa5e0f 100644 --- a/test/to_underlying.cpp +++ b/test/to_underlying.cpp @@ -1,5 +1,6 @@ #include +#include #include #include @@ -25,8 +26,18 @@ TEST_CASE("to_underlying values", "[type_traits]") { CHECK(stdx::to_underlying(ScopedEnum::Value5) == 5); } -TEST_CASE("to_underlying works on integral types", "[type_traits]") { - constexpr int x = 0; - CHECK(std::is_same_v); - CHECK(stdx::to_underlying(x) == 0); +TEMPLATE_TEST_CASE("to_underlying works on integral types", "[type_traits]", + bool, char, signed char, unsigned char, short int, + unsigned short int, int, unsigned int, long int, + unsigned long int) { + constexpr TestType x{}; + CHECK(std::is_same_v); + CHECK(stdx::to_underlying(x) == TestType{}); +} + +TEMPLATE_TEST_CASE("to_underlying works on floating point types", + "[type_traits]", float, double) { + constexpr TestType x{}; + CHECK(std::is_same_v); + CHECK(stdx::to_underlying(x) == TestType{}); }