-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring-to-integer-atoi-test.cpp
93 lines (80 loc) · 2.42 KB
/
string-to-integer-atoi-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
/*
* Copyright (c) 2018 Christopher Friedt
*
* SPDX-License-Identifier: MIT
*/
#include <gtest/gtest.h>
#include "string-to-integer-atoi.cpp"
TEST(StringToIntegerAtoi, Test_empty) {
string str("");
int expected_int = 0;
int actual_int = Solution().myAtoi(str);
EXPECT_EQ(actual_int, expected_int);
}
TEST(StringToIntegerAtoi, Test_preceeding_zeros) {
// preceeding zeros should not add to the full amount in decimal, but should
// in hex. It isn't really common notation to have preceeding zeros in any
// case.
string str("010");
int expected_int = 10;
int actual_int = Solution().myAtoi(str);
EXPECT_EQ(actual_int, expected_int);
}
TEST(StringToIntegerAtoi, Test_42) {
string str("42");
int expected_int = 42;
int actual_int = Solution().myAtoi(str);
EXPECT_EQ(actual_int, expected_int);
}
TEST(StringToIntegerAtoi, Test_____n42) {
string str(" -42");
int expected_int = -42;
int actual_int = Solution().myAtoi(str);
EXPECT_EQ(actual_int, expected_int);
}
TEST(StringToIntegerAtoi, Test_41983_with_words) {
string str("41983 with words");
int expected_int = 41983;
int actual_int = Solution().myAtoi(str);
EXPECT_EQ(actual_int, expected_int);
}
TEST(StringToIntegerAtoi, Test_words_and_987) {
string str("words_and_987");
int expected_int = 0;
int actual_int = Solution().myAtoi(str);
EXPECT_EQ(actual_int, expected_int);
}
TEST(StringToIntegerAtoi, Test_n91283472332) {
string str("-91283472332");
int expected_int = INT_MIN;
int actual_int = Solution().myAtoi(str);
EXPECT_EQ(actual_int, expected_int);
}
TEST(StringToIntegerAtoi, Test_n946384712) {
// ok reverse, but not forward
string str("-9463847412");
int expected_int = INT_MIN;
int actual_int = Solution().myAtoi(str);
EXPECT_EQ(actual_int, expected_int);
}
TEST(StringToIntegerAtoi, Test_8463847412) {
// ok reverse, but not forward
string str("8463847412");
int expected_int = INT_MAX;
int actual_int = Solution().myAtoi(str);
EXPECT_EQ(actual_int, expected_int);
}
TEST(StringToIntegerAtoi, Test_n9128347233250) {
// too many decimal digits
string str("-9128347233250");
int expected_int = INT_MIN;
int actual_int = Solution().myAtoi(str);
EXPECT_EQ(actual_int, expected_int);
}
TEST(StringToIntegerAtoi, Test_9128347233250) {
// too many decimal digits
string str("9128347233250");
int expected_int = INT_MAX;
int actual_int = Solution().myAtoi(str);
EXPECT_EQ(actual_int, expected_int);
}