-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_limits.cpp
More file actions
63 lines (50 loc) · 2.32 KB
/
Copy pathtest_limits.cpp
File metadata and controls
63 lines (50 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <cmath>
#include <concepts>
#include <gtest/gtest.h>
#include <limits>
#include <type_traits>
import mcpplibs.primitives.algorithms;
import mcpplibs.primitives.underlying;
#include "../../support/underlying_custom_types.hpp"
using namespace mcpplibs::primitives;
using namespace mcpplibs::primitives::test_support::underlying;
TEST(AlgorithmLimitsTest, BuiltinIntegerLimitsFollowNumericLimitsShape) {
using limits_t = algorithms::limits<int>;
static_assert(limits_t::enabled);
static_assert(limits_t::is_specialized);
static_assert(std::same_as<typename limits_t::rep_type, int>);
static_assert(limits_t::kind == underlying::category::integer);
static_assert(limits_t::digits == std::numeric_limits<int>::digits);
static_assert(limits_t::radix == std::numeric_limits<int>::radix);
static_assert(algorithms::limited_type<int>);
EXPECT_EQ(limits_t::lowest(), std::numeric_limits<int>::lowest());
EXPECT_EQ(limits_t::max(), std::numeric_limits<int>::max());
EXPECT_EQ(algorithms::min_value<int>(), std::numeric_limits<int>::min());
}
TEST(AlgorithmLimitsTest, BuiltinFloatingLimitsExposeSpecialValues) {
using limits_t = algorithms::limits<double>;
static_assert(limits_t::enabled);
static_assert(limits_t::has_quiet_nan);
static_assert(limits_t::has_infinity);
static_assert(limits_t::kind == underlying::category::floating);
static_assert(limits_t::is_iec559);
EXPECT_EQ(algorithms::epsilon_value<double>(),
std::numeric_limits<double>::epsilon());
EXPECT_EQ(algorithms::infinity_value<double>(),
std::numeric_limits<double>::infinity());
EXPECT_TRUE(std::isnan(algorithms::quiet_nan_value<double>()));
}
TEST(AlgorithmLimitsTest, CustomUnderlyingUsesRepBackedLimits) {
using limits_t = algorithms::limits<UserInteger>;
static_assert(limits_t::enabled);
static_assert(std::same_as<typename limits_t::rep_type, int>);
static_assert(limits_t::kind == underlying::category::integer);
EXPECT_EQ(underlying::traits<UserInteger>::to_rep(limits_t::lowest()),
std::numeric_limits<int>::lowest());
EXPECT_EQ(underlying::traits<UserInteger>::to_rep(limits_t::max()),
std::numeric_limits<int>::max());
}
TEST(AlgorithmLimitsTest, SelfRepresentedCustomRepNeedsExplicitLimitsSpecialization) {
static_assert(!algorithms::limits<BigIntLike>::enabled);
SUCCEED();
}