| 8 | class TestNode : public LinkedListNode {}; |
| 9 | |
| 10 | TEST(LinkedList, canInsertAtBeginning) { |
| 11 | LinkedList<TestNode> list; |
| 12 | |
| 13 | auto node1 = makeShared<TestNode>(); |
| 14 | auto node2 = makeShared<TestNode>(); |
| 15 | auto node3 = makeShared<TestNode>(); |
| 16 | |
| 17 | ASSERT_TRUE(list.empty()); |
| 18 | ASSERT_TRUE(list.head() == nullptr); |
| 19 | ASSERT_TRUE(list.tail() == nullptr); |
| 20 | |
| 21 | list.insert(list.begin(), node1); |
| 22 | |
| 23 | ASSERT_FALSE(list.empty()); |
| 24 | ASSERT_EQ(node1, list.head()); |
| 25 | ASSERT_EQ(node1, list.tail()); |
| 26 | ASSERT_EQ(nullptr, node1->prev()); |
| 27 | ASSERT_EQ(nullptr, node1->prev()); |
| 28 | |
| 29 | list.insert(list.begin(), node2); |
| 30 | |
| 31 | ASSERT_FALSE(list.empty()); |
| 32 | ASSERT_EQ(node2, list.head()); |
| 33 | ASSERT_EQ(node1, list.tail()); |
| 34 | ASSERT_EQ(nullptr, node2->prev()); |
| 35 | ASSERT_EQ(node1.get(), node2->next()); |
| 36 | ASSERT_EQ(node2.get(), node1->prev()); |
| 37 | ASSERT_EQ(nullptr, node1->next()); |
| 38 | |
| 39 | list.insert(list.begin(), node3); |
| 40 | |
| 41 | ASSERT_FALSE(list.empty()); |
| 42 | ASSERT_EQ(node3, list.head()); |
| 43 | ASSERT_EQ(node1, list.tail()); |
| 44 | ASSERT_EQ(nullptr, node3->prev()); |
| 45 | ASSERT_EQ(node2.get(), node3->next()); |
| 46 | ASSERT_EQ(node3.get(), node2->prev()); |
| 47 | ASSERT_EQ(node1.get(), node2->next()); |
| 48 | ASSERT_EQ(node2.get(), node1->prev()); |
| 49 | ASSERT_EQ(nullptr, node1->next()); |
| 50 | } |
| 51 | |
| 52 | TEST(LinkedList, canInsertAtEnd) { |
| 53 | LinkedList<TestNode> list; |