1 | //===-- Utility class to test different flavors of nextup -------*- C++ -*-===// |
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLVM_LIBC_TEST_SRC_MATH_NEXTUPTEST_H |
10 | #define LLVM_LIBC_TEST_SRC_MATH_NEXTUPTEST_H |
11 | |
12 | #include "test/UnitTest/FEnvSafeTest.h" |
13 | #include "test/UnitTest/FPMatcher.h" |
14 | #include "test/UnitTest/Test.h" |
15 | |
16 | template <typename T> |
17 | class NextUpTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest { |
18 | |
19 | DECLARE_SPECIAL_CONSTANTS(T) |
20 | |
21 | public: |
22 | typedef T (*NextUpFunc)(T); |
23 | |
24 | void testNaN(NextUpFunc func) { ASSERT_FP_EQ(func(aNaN), aNaN); } |
25 | |
26 | void testBoundaries(NextUpFunc func) { |
27 | ASSERT_FP_EQ(neg_zero, func(neg_min_denormal)); |
28 | |
29 | ASSERT_FP_EQ(min_denormal, func(zero)); |
30 | ASSERT_FP_EQ(min_denormal, func(neg_zero)); |
31 | |
32 | ASSERT_FP_EQ(max_normal, func(max_normal)); |
33 | ASSERT_FP_EQ(inf, func(inf)); |
34 | |
35 | ASSERT_FP_EQ(neg_max_normal, func(neg_inf)); |
36 | } |
37 | }; |
38 | |
39 | #define LIST_NEXTUP_TESTS(T, func) \ |
40 | using LlvmLibcNextUpTest = NextUpTestTemplate<T>; \ |
41 | TEST_F(LlvmLibcNextUpTest, TestNaN) { testNaN(&func); } \ |
42 | TEST_F(LlvmLibcNextUpTest, TestBoundaries) { testBoundaries(&func); } |
43 | |
44 | #endif // LLVM_LIBC_TEST_SRC_MATH_NEXTUPTEST_H |
45 | |