1 | //===-- A template class for testing div functions --------------*- 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 | template <typename IntType, typename ReturnType> |
12 | class DivTest : public LIBC_NAMESPACE::testing::Test { |
13 | public: |
14 | using DivFunc = ReturnType(IntType, IntType); |
15 | |
16 | void simpleTest(DivFunc func) { |
17 | auto result = func(10, 3); |
18 | EXPECT_EQ(result.quot, IntType(3)); |
19 | EXPECT_EQ(result.rem, IntType(1)); |
20 | |
21 | result = func(-10, 3); |
22 | EXPECT_EQ(result.quot, IntType(-3)); |
23 | EXPECT_EQ(result.rem, IntType(-1)); |
24 | |
25 | result = func(-10, -3); |
26 | EXPECT_EQ(result.quot, IntType(3)); |
27 | EXPECT_EQ(result.rem, IntType(-1)); |
28 | |
29 | result = func(10, -3); |
30 | EXPECT_EQ(result.quot, IntType(-3)); |
31 | EXPECT_EQ(result.rem, IntType(1)); |
32 | } |
33 | }; |
34 | |
35 | #define LIST_DIV_TESTS(IntType, ReturnType, func) \ |
36 | using LlvmLibcDivTest = DivTest<IntType, ReturnType>; \ |
37 | TEST_F(LlvmLibcDivTest, SimpleTest##ReturnType) { simpleTest(func); } |
38 | |