-
Notifications
You must be signed in to change notification settings - Fork 0
/
divide-two-integers-test.cpp
99 lines (86 loc) · 2.42 KB
/
divide-two-integers-test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Copyright (c) 2018 Christopher Friedt
*
* SPDX-License-Identifier: MIT
*/
#include <gtest/gtest.h>
#include "divide-two-integers.cpp"
TEST(DivideTwoIntegers, Test_10_3) {
int dividend = 10;
int divisor = 3;
int expected_int = 3;
int actual_int = Solution().divide(dividend, divisor);
EXPECT_EQ(actual_int, expected_int);
}
TEST(DivideTwoIntegers, Test_7_n3) {
int dividend = 7;
int divisor = -3;
int expected_int = -2;
int actual_int = Solution().divide(dividend, divisor);
EXPECT_EQ(actual_int, expected_int);
}
TEST(DivideTwoIntegers, Test_1_0) {
// positive saturation
int dividend = 1;
int divisor = 0;
int expected_int = INT_MAX;
int actual_int = Solution().divide(dividend, divisor);
EXPECT_EQ(actual_int, expected_int);
}
TEST(DivideTwoIntegers, Test_n1_0) {
// negative saturation
int dividend = -1;
int divisor = 0;
int expected_int = INT_MIN;
int actual_int = Solution().divide(dividend, divisor);
EXPECT_EQ(actual_int, expected_int);
}
TEST(DivideTwoIntegers, Test_500_1) {
int dividend = 500;
int divisor = 1;
int expected_int = 500;
int actual_int = Solution().divide(dividend, divisor);
EXPECT_EQ(actual_int, expected_int);
}
TEST(DivideTwoIntegers, Test_INTMIN_n1) {
int dividend = INT_MIN;
int divisor = -1;
int expected_int = INT_MAX;
int actual_int = Solution().divide(dividend, divisor);
EXPECT_EQ(actual_int, expected_int);
}
TEST(DivideTwoIntegers, Test_500_n1) {
int dividend = 500;
int divisor = -1;
int expected_int = -500;
int actual_int = Solution().divide(dividend, divisor);
EXPECT_EQ(actual_int, expected_int);
}
TEST(DivideTwoIntegers, Test_INTMIN_INTMIN) {
int dividend = INT_MIN;
int divisor = INT_MIN;
int expected_int = 1;
int actual_int = Solution().divide(dividend, divisor);
EXPECT_EQ(actual_int, expected_int);
}
TEST(DivideTwoIntegers, Test_INTMIN_5) {
int dividend = INT_MIN;
int divisor = INT_MAX / 2;
int expected_int = -2;
int actual_int = Solution().divide(dividend, divisor);
EXPECT_EQ(actual_int, expected_int);
}
TEST(DivideTwoIntegers, Test_5_INTMIN) {
int dividend = 5;
int divisor = INT_MIN;
int expected_int = 0;
int actual_int = Solution().divide(dividend, divisor);
EXPECT_EQ(actual_int, expected_int);
}
TEST(DivideTwoIntegers, Test_10_5) {
int dividend = 10;
int divisor = 5;
int expected_int = 2;
int actual_int = Solution().divide(dividend, divisor);
EXPECT_EQ(actual_int, expected_int);
}