leetcode/tests/s0002_add_two_numbers.cpp
2022-03-12 11:04:49 +08:00

54 lines
1.4 KiB
C++

#include "s0002_add_two_numbers.hpp"
#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)));
Solution solution;
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);
Solution solution;
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))));
Solution solution;
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);
}