2022-03-12 03:04:49 +00:00
|
|
|
#include "s0002_add_two_numbers.hpp"
|
2022-03-10 12:25:55 +00:00
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
TEST(Problem2, Case1) {
|
|
|
|
ListNode *l1 =
|
|
|
|
new ListNode(2,
|
|
|
|
new ListNode(4,
|
|
|
|
new ListNode(3)));
|
|
|
|
ListNode *l2 =
|
|
|
|
new ListNode(5,
|
|
|
|
new ListNode(6,
|
|
|
|
new ListNode(4)));
|
2022-11-30 10:20:36 +00:00
|
|
|
S0002 solution;
|
2022-03-10 12:25:55 +00:00
|
|
|
ListNode *l = solution.addTwoNumbers(l1, l2);
|
|
|
|
EXPECT_EQ(l->val, 7);
|
|
|
|
EXPECT_EQ(l->next->val, 0);
|
|
|
|
EXPECT_EQ(l->next->next->val, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Problem2, Case2) {
|
|
|
|
ListNode *l1 = new ListNode(0);
|
|
|
|
ListNode *l2 = new ListNode(0);
|
2022-11-30 10:20:36 +00:00
|
|
|
S0002 solution;
|
2022-03-10 12:25:55 +00:00
|
|
|
ListNode *l = solution.addTwoNumbers(l1, l2);
|
|
|
|
EXPECT_EQ(l->val, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Problem2, Case3) {
|
|
|
|
ListNode *l1 =
|
|
|
|
new ListNode(9,
|
|
|
|
new ListNode(9,
|
|
|
|
new ListNode(9,
|
|
|
|
new ListNode(9,
|
|
|
|
new ListNode(9,
|
|
|
|
new ListNode(9,
|
|
|
|
new ListNode(9)))))));
|
|
|
|
ListNode *l2 =
|
|
|
|
new ListNode(9,
|
|
|
|
new ListNode(9,
|
|
|
|
new ListNode(9,
|
|
|
|
new ListNode(9))));
|
2022-11-30 10:20:36 +00:00
|
|
|
S0002 solution;
|
2022-03-10 12:25:55 +00:00
|
|
|
ListNode *l = solution.addTwoNumbers(l1, l2);
|
|
|
|
EXPECT_EQ(l->val, 8);
|
|
|
|
EXPECT_EQ(l->next->val, 9);
|
|
|
|
EXPECT_EQ(l->next->next->val, 9);
|
|
|
|
EXPECT_EQ(l->next->next->next->val, 9);
|
|
|
|
EXPECT_EQ(l->next->next->next->next->val, 0);
|
|
|
|
EXPECT_EQ(l->next->next->next->next->next->val, 0);
|
|
|
|
EXPECT_EQ(l->next->next->next->next->next->next->val, 0);
|
|
|
|
EXPECT_EQ(l->next->next->next->next->next->next->next->val, 1);
|
|
|
|
}
|