77 lines · c
1//===-- Utility class to test floor[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 information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_FLOORTEST_H10#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_FLOORTEST_H11 12#include "test/UnitTest/FEnvSafeTest.h"13#include "test/UnitTest/FPMatcher.h"14#include "test/UnitTest/Test.h"15 16#include "hdr/math_macros.h"17 18template <typename T>19class FloorTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {20 21 DECLARE_SPECIAL_CONSTANTS(T)22 23public:24 typedef T (*FloorFunc)(T);25 26 void testSpecialNumbers(FloorFunc func) {27 EXPECT_FP_EQ(zero, func(zero));28 EXPECT_FP_EQ(neg_zero, func(neg_zero));29 30 EXPECT_FP_EQ(inf, func(inf));31 EXPECT_FP_EQ(neg_inf, func(neg_inf));32 33 EXPECT_FP_EQ(aNaN, func(aNaN));34 }35 36 void testRoundedNumbers(FloorFunc func) {37 EXPECT_FP_EQ(T(1.0), func(T(1.0)));38 EXPECT_FP_EQ(T(-1.0), func(T(-1.0)));39 EXPECT_FP_EQ(T(10.0), func(T(10.0)));40 EXPECT_FP_EQ(T(-10.0), func(T(-10.0)));41 EXPECT_FP_EQ(T(1234.0), func(T(1234.0)));42 EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0)));43 }44 45 void testFractions(FloorFunc func) {46 EXPECT_FP_EQ(T(0.0), func(T(0.5)));47 EXPECT_FP_EQ(T(-1.0), func(T(-0.5)));48 EXPECT_FP_EQ(T(0.0), func(T(0.115)));49 EXPECT_FP_EQ(T(-1.0), func(T(-0.115)));50 EXPECT_FP_EQ(T(0.0), func(T(0.715)));51 EXPECT_FP_EQ(T(-1.0), func(T(-0.715)));52 EXPECT_FP_EQ(T(1.0), func(T(1.3)));53 EXPECT_FP_EQ(T(-2.0), func(T(-1.3)));54 EXPECT_FP_EQ(T(1.0), func(T(1.5)));55 EXPECT_FP_EQ(T(-2.0), func(T(-1.5)));56 EXPECT_FP_EQ(T(1.0), func(T(1.75)));57 EXPECT_FP_EQ(T(-2.0), func(T(-1.75)));58 EXPECT_FP_EQ(T(10.0), func(T(10.32)));59 EXPECT_FP_EQ(T(-11.0), func(T(-10.32)));60 EXPECT_FP_EQ(T(10.0), func(T(10.65)));61 EXPECT_FP_EQ(T(-11.0), func(T(-10.65)));62 EXPECT_FP_EQ(T(50.0), func(T(50.31)));63 EXPECT_FP_EQ(T(-50.0), func(T(-49.63)));64 EXPECT_FP_EQ(T(123.0), func(T(123.38)));65 EXPECT_FP_EQ(T(-124.0), func(T(-123.38)));66 EXPECT_FP_EQ(T(-124.0), func(T(-123.5)));67 }68};69 70#define LIST_FLOOR_TESTS(T, func) \71 using LlvmLibcFloorTest = FloorTest<T>; \72 TEST_F(LlvmLibcFloorTest, SpecialNumbers) { testSpecialNumbers(&func); } \73 TEST_F(LlvmLibcFloorTest, RoundedNubmers) { testRoundedNumbers(&func); } \74 TEST_F(LlvmLibcFloorTest, Fractions) { testFractions(&func); }75 76#endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_FLOORTEST_H77