1 | //===-- Utility class to test the isnan macro [f|l] -------------*- 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 nanormation. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLVM_LIBC_TEST_INCLUDE_MATH_ISNAN_H |
10 | #define LLVM_LIBC_TEST_INCLUDE_MATH_ISNAN_H |
11 | |
12 | #include "test/UnitTest/FPMatcher.h" |
13 | #include "test/UnitTest/Test.h" |
14 | |
15 | #include "include/llvm-libc-macros/math-function-macros.h" |
16 | |
17 | template <typename T> class IsNanTest : public LIBC_NAMESPACE::testing::Test { |
18 | |
19 | DECLARE_SPECIAL_CONSTANTS(T) |
20 | |
21 | public: |
22 | typedef int (*IsNanFunc)(T); |
23 | |
24 | void testSpecialNumbers(IsNanFunc func) { |
25 | EXPECT_EQ(func(zero), 0); |
26 | EXPECT_EQ(func(neg_zero), 0); |
27 | EXPECT_EQ(func(aNaN), 1); |
28 | EXPECT_EQ(func(sNaN), 1); |
29 | } |
30 | }; |
31 | |
32 | #define LIST_ISNAN_TESTS(T, func) \ |
33 | using LlvmLibcIsNanTest = IsNanTest<T>; \ |
34 | TEST_F(LlvmLibcIsNanTest, SpecialNumbers) { \ |
35 | auto isnan_func = [](T x) { return func(x); }; \ |
36 | testSpecialNumbers(isnan_func); \ |
37 | } |
38 | |
39 | #endif // LLVM_LIBC_TEST_INCLUDE_MATH_ISNAN_H |
40 |