1 //===-- Unittests for Limits ----------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/__support/CPP/limits.h"
10 #include "src/__support/UInt.h"
11 #include "test/UnitTest/Test.h"
13 namespace LIBC_NAMESPACE
{
15 // This just checks against the C spec, almost all implementations will surpass
17 TEST(LlvmLibcLimitsTest
, LimitsFollowSpec
) {
18 ASSERT_EQ(cpp::numeric_limits
<int>::max(), INT_MAX
);
19 ASSERT_EQ(cpp::numeric_limits
<int>::min(), INT_MIN
);
21 ASSERT_EQ(cpp::numeric_limits
<unsigned int>::max(), UINT_MAX
);
23 ASSERT_EQ(cpp::numeric_limits
<long>::max(), LONG_MAX
);
24 ASSERT_EQ(cpp::numeric_limits
<long>::min(), LONG_MIN
);
26 ASSERT_EQ(cpp::numeric_limits
<unsigned long>::max(), ULONG_MAX
);
28 ASSERT_EQ(cpp::numeric_limits
<long long>::max(), LLONG_MAX
);
29 ASSERT_EQ(cpp::numeric_limits
<long long>::min(), LLONG_MIN
);
31 ASSERT_EQ(cpp::numeric_limits
<unsigned long long>::max(), ULLONG_MAX
);
34 TEST(LlvmLibcLimitsTest
, UInt128Limits
) {
35 auto umax128
= cpp::numeric_limits
<LIBC_NAMESPACE::cpp::UInt
<128>>::max();
37 LIBC_NAMESPACE::cpp::UInt
<128>(cpp::numeric_limits
<uint64_t>::max());
38 EXPECT_GT(umax128
, umax64
);
39 ASSERT_EQ(~LIBC_NAMESPACE::cpp::UInt
<128>(0), umax128
);
40 #ifdef __SIZEOF_INT128__
41 ASSERT_EQ(~__uint128_t(0), cpp::numeric_limits
<__uint128_t
>::max());
45 } // namespace LIBC_NAMESPACE