xref: /llvm-project/libc/test/src/stdlib/DivTest.h (revision b6bc9d72f65a5086f310f321e969d96e9a559e75)
174670e79SSiva Chandra Reddy //===-- A template class for testing div functions --------------*- C++ -*-===//
274670e79SSiva Chandra Reddy //
374670e79SSiva Chandra Reddy // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
474670e79SSiva Chandra Reddy // See https://llvm.org/LICENSE.txt for license information.
574670e79SSiva Chandra Reddy // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
674670e79SSiva Chandra Reddy //
774670e79SSiva Chandra Reddy //===----------------------------------------------------------------------===//
874670e79SSiva Chandra Reddy 
9af1315c2SSiva Chandra Reddy #include "test/UnitTest/Test.h"
1074670e79SSiva Chandra Reddy 
1174670e79SSiva Chandra Reddy template <typename IntType, typename ReturnType>
12*b6bc9d72SGuillaume Chatelet class DivTest : public LIBC_NAMESPACE::testing::Test {
1374670e79SSiva Chandra Reddy public:
1474670e79SSiva Chandra Reddy   using DivFunc = ReturnType(IntType, IntType);
1574670e79SSiva Chandra Reddy 
simpleTest(DivFunc func)1674670e79SSiva Chandra Reddy   void simpleTest(DivFunc func) {
1774670e79SSiva Chandra Reddy     auto result = func(10, 3);
1874670e79SSiva Chandra Reddy     EXPECT_EQ(result.quot, IntType(3));
1974670e79SSiva Chandra Reddy     EXPECT_EQ(result.rem, IntType(1));
2074670e79SSiva Chandra Reddy 
2174670e79SSiva Chandra Reddy     result = func(-10, 3);
2274670e79SSiva Chandra Reddy     EXPECT_EQ(result.quot, IntType(-3));
2374670e79SSiva Chandra Reddy     EXPECT_EQ(result.rem, IntType(-1));
2474670e79SSiva Chandra Reddy 
2574670e79SSiva Chandra Reddy     result = func(-10, -3);
2674670e79SSiva Chandra Reddy     EXPECT_EQ(result.quot, IntType(3));
2774670e79SSiva Chandra Reddy     EXPECT_EQ(result.rem, IntType(-1));
2874670e79SSiva Chandra Reddy 
2974670e79SSiva Chandra Reddy     result = func(10, -3);
3074670e79SSiva Chandra Reddy     EXPECT_EQ(result.quot, IntType(-3));
3174670e79SSiva Chandra Reddy     EXPECT_EQ(result.rem, IntType(1));
3274670e79SSiva Chandra Reddy   }
3374670e79SSiva Chandra Reddy };
3474670e79SSiva Chandra Reddy 
3574670e79SSiva Chandra Reddy #define LIST_DIV_TESTS(IntType, ReturnType, func)                              \
3674670e79SSiva Chandra Reddy   using LlvmLibcDivTest = DivTest<IntType, ReturnType>;                        \
37a442c628SAlex Brachet   TEST_F(LlvmLibcDivTest, SimpleTest##ReturnType) { simpleTest(func); }
38