1 /*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "gtest/gtest.h"
18
19 #include <inttypes.h>
20
TEST(Div,Div)21 TEST(Div, Div) {
22 int numerator = 5;
23 int denominator = 2;
24 div_t res = div(numerator, denominator);
25 EXPECT_EQ(2, res.quot);
26 EXPECT_EQ(1, res.rem);
27 }
28
TEST(Div,LDiv)29 TEST(Div, LDiv) {
30 long numerator = 5; // NOLINT(runtime/int)
31 long denominator = 2; // NOLINT(runtime/int)
32 ldiv_t res = ldiv(numerator, denominator);
33 EXPECT_EQ(2, res.quot);
34 EXPECT_EQ(1, res.rem);
35 }
36
TEST(Div,LLDiv)37 TEST(Div, LLDiv) {
38 long long numerator = 5; // NOLINT(runtime/int)
39 long long denominator = 2; // NOLINT(runtime/int)
40 lldiv_t res = lldiv(numerator, denominator);
41 EXPECT_EQ(2, res.quot);
42 EXPECT_EQ(1, res.rem);
43 }
44
TEST(Div,IMaxDiv)45 TEST(Div, IMaxDiv) {
46 intmax_t numerator = 5;
47 intmax_t denominator = 2;
48 imaxdiv_t res = imaxdiv(numerator, denominator);
49 EXPECT_EQ(2, res.quot);
50 EXPECT_EQ(1, res.rem);
51 }
52