| 1 | //===-- Utility class to test fixed-point abs -------------------*- 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 | #include "test/UnitTest/Test.h" |
| 10 | |
| 11 | #include "src/__support/fixed_point/fx_rep.h" |
| 12 | |
| 13 | template <typename T> class AbsTest : public LIBC_NAMESPACE::testing::Test { |
| 14 | |
| 15 | using FXRep = LIBC_NAMESPACE::fixed_point::FXRep<T>; |
| 16 | static constexpr T zero = FXRep::ZERO(); |
| 17 | static constexpr T min = FXRep::MIN(); |
| 18 | static constexpr T max = FXRep::MAX(); |
| 19 | static constexpr T half = static_cast<T>(0.5); |
| 20 | static constexpr T neg_half = static_cast<T>(-0.5); |
| 21 | |
| 22 | public: |
| 23 | typedef T (*AbsFunc)(T); |
| 24 | |
| 25 | void testSpecialNumbers(AbsFunc func) { |
| 26 | EXPECT_EQ(zero, func(zero)); |
| 27 | EXPECT_EQ(max, func(min)); |
| 28 | EXPECT_EQ(max, func(max)); |
| 29 | EXPECT_EQ(half, func(half)); |
| 30 | EXPECT_EQ(half, func(neg_half)); |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | #define LIST_ABS_TESTS(T, func) \ |
| 35 | using LlvmLibcAbsTest = AbsTest<T>; \ |
| 36 | TEST_F(LlvmLibcAbsTest, SpecialNumbers) { testSpecialNumbers(&func); } \ |
| 37 | static_assert(true, "Require semicolon.") |
| 38 | |