58 lines
1.3 KiB
C++
58 lines
1.3 KiB
C++
#include "s0142_linked_list_cycle.hpp"
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
TEST(Problem142, Case1) {
|
|
ListNode node1 = ListNode(3);
|
|
ListNode node2 = ListNode(2);
|
|
ListNode node3 = ListNode(0);
|
|
ListNode node4 = ListNode(-4);
|
|
node1.next = &node2;
|
|
node2.next = &node3;
|
|
node3.next = &node4;
|
|
node4.next = &node2;
|
|
S0142 solution;
|
|
EXPECT_EQ(solution.detectCycle(&node1), &node2);
|
|
}
|
|
|
|
TEST(Problem142, Case2) {
|
|
ListNode node1 = ListNode(3);
|
|
ListNode node2 = ListNode(2);
|
|
ListNode node3 = ListNode(0);
|
|
ListNode node4 = ListNode(-4);
|
|
node1.next = &node2;
|
|
node2.next = &node3;
|
|
node3.next = &node4;
|
|
node4.next = &node1;
|
|
S0142 solution;
|
|
EXPECT_EQ(solution.detectCycle(&node1), &node1);
|
|
}
|
|
|
|
TEST(Problem142, Case3) {
|
|
ListNode node1 = ListNode(3);
|
|
ListNode node2 = ListNode(2);
|
|
ListNode node3 = ListNode(0);
|
|
ListNode node4 = ListNode(-4);
|
|
node1.next = &node2;
|
|
node2.next = &node3;
|
|
node3.next = &node4;
|
|
S0142 solution;
|
|
EXPECT_EQ(solution.detectCycle(&node1), nullptr);
|
|
}
|
|
|
|
TEST(Problem142, Case4) {
|
|
ListNode node1 = ListNode(1);
|
|
ListNode node2 = ListNode(2);
|
|
node1.next = &node2;
|
|
node2.next = &node1;
|
|
S0142 solution;
|
|
EXPECT_EQ(solution.detectCycle(&node1), &node1);
|
|
}
|
|
|
|
TEST(Problem142, Case5) {
|
|
ListNode node1 = ListNode(1);
|
|
node1.next = &node1;
|
|
S0142 solution;
|
|
EXPECT_EQ(solution.detectCycle(&node1), &node1);
|
|
}
|