-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-two-numbers-test.cpp
78 lines (63 loc) · 1.67 KB
/
add-two-numbers-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
/*
* Copyright (c) 2018 Christopher Friedt
*
* SPDX-License-Identifier: MIT
*/
#include <array>
using namespace std;
#include <gtest/gtest.h>
#include "util/ListNode.cpp"
#include "add-two-numbers.cpp"
class AddTwoNumbers : public ::testing::Test {
public:
AddTwoNumbers() : l1(nullptr), l2(nullptr), output(nullptr) {}
string l1_str;
string l2_str;
ListNode *l1;
ListNode *l2;
ListNode *output;
string expected_string;
string actual_string;
Solution soln;
void mSetUp() {
// needs to be called from within test case
l1 = ListNode_from_string(l1_str);
l2 = ListNode_from_string(l2_str);
}
void doTest() {
output = soln.addTwoNumbers(l1, l2);
actual_string = ListNode_to_string(output);
EXPECT_EQ(actual_string, expected_string);
}
virtual void TearDown() override {
ListNode_cleanup(&l1);
ListNode_cleanup(&l2);
ListNode_cleanup(&output);
}
};
TEST_F(AddTwoNumbers, Test__2_4_3__5_6_4) {
// 342 + 465 = 807
l1_str = "2->4->3";
l2_str = "5->6->4";
expected_string = "7->0->8";
mSetUp();
doTest();
}
TEST_F(AddTwoNumbers, Test__9__1_9_9_9_9_9_9_9_9_9) {
l1_str = "9";
l2_str = "1->9->9->9->9->9->9->9->9->9";
expected_string = "0->0->0->0->0->0->0->0->0->0->1";
mSetUp();
doTest();
}
TEST_F(
AddTwoNumbers,
Test__1_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_1__5_6_4) {
l1_str = "1->0->0->0->0->0->0->0->0->0->0->0->0->0->0->0->0->0->0->0->0->0->"
"0->0->0->0->0->0->0->0->1";
l2_str = "5->6->4";
expected_string = "6->6->4->0->0->0->0->0->0->0->0->0->0->0->0->0->0->0->0->"
"0->0->0->0->0->0->0->0->0->0->0->1";
mSetUp();
doTest();
}