From c96bc9a10c216dbaee41b247c0fafe4ea497337d Mon Sep 17 00:00:00 2001 From: WesleyR Date: Sun, 9 Jun 2024 22:26:59 -0700 Subject: Updating before template node branch --- CST 126/CST_126.sln | 10 + CST 126/Homework 3/Homework 3.vcxproj | 41 +- CST 126/Homework 3/Homework 3.vcxproj.filters | 13 + CST 126/Homework 3/SinglyLinkedList.hpp | 256 ++++++++++ CST 126/Homework 3/node.hpp | 42 ++ CST 126/Homework 3/program.cpp | 10 + .../LinkedListUnitTests/LinkedListUnitTests.cpp | 519 +++++++++++++++++++++ .../LinkedListUnitTests.vcxproj | 174 +++++++ .../LinkedListUnitTests.vcxproj.filters | 30 ++ CST 126/LinkedListUnitTests/pch.cpp | 5 + CST 126/LinkedListUnitTests/pch.h | 12 + 11 files changed, 1092 insertions(+), 20 deletions(-) create mode 100644 CST 126/Homework 3/SinglyLinkedList.hpp create mode 100644 CST 126/Homework 3/node.hpp create mode 100644 CST 126/Homework 3/program.cpp create mode 100644 CST 126/LinkedListUnitTests/LinkedListUnitTests.cpp create mode 100644 CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj create mode 100644 CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj.filters create mode 100644 CST 126/LinkedListUnitTests/pch.cpp create mode 100644 CST 126/LinkedListUnitTests/pch.h diff --git a/CST 126/CST_126.sln b/CST 126/CST_126.sln index 060ef9f..cc4f241 100644 --- a/CST 126/CST_126.sln +++ b/CST 126/CST_126.sln @@ -9,6 +9,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Homework2", "Homework2\Home EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Homework 3", "Homework 3\Homework 3.vcxproj", "{9605D423-3B58-499C-9944-5C5D3CEA87AA}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LinkedListUnitTests", "LinkedListUnitTests\LinkedListUnitTests.vcxproj", "{764A846B-5FB7-4C7A-8D47-9CC204AEEE15}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -41,6 +43,14 @@ Global {9605D423-3B58-499C-9944-5C5D3CEA87AA}.Release|x64.Build.0 = Release|x64 {9605D423-3B58-499C-9944-5C5D3CEA87AA}.Release|x86.ActiveCfg = Release|Win32 {9605D423-3B58-499C-9944-5C5D3CEA87AA}.Release|x86.Build.0 = Release|Win32 + {764A846B-5FB7-4C7A-8D47-9CC204AEEE15}.Debug|x64.ActiveCfg = Debug|x64 + {764A846B-5FB7-4C7A-8D47-9CC204AEEE15}.Debug|x64.Build.0 = Debug|x64 + {764A846B-5FB7-4C7A-8D47-9CC204AEEE15}.Debug|x86.ActiveCfg = Debug|Win32 + {764A846B-5FB7-4C7A-8D47-9CC204AEEE15}.Debug|x86.Build.0 = Debug|Win32 + {764A846B-5FB7-4C7A-8D47-9CC204AEEE15}.Release|x64.ActiveCfg = Release|x64 + {764A846B-5FB7-4C7A-8D47-9CC204AEEE15}.Release|x64.Build.0 = Release|x64 + {764A846B-5FB7-4C7A-8D47-9CC204AEEE15}.Release|x86.ActiveCfg = Release|Win32 + {764A846B-5FB7-4C7A-8D47-9CC204AEEE15}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CST 126/Homework 3/Homework 3.vcxproj b/CST 126/Homework 3/Homework 3.vcxproj index 21ecb73..e0dff7d 100644 --- a/CST 126/Homework 3/Homework 3.vcxproj +++ b/CST 126/Homework 3/Homework 3.vcxproj @@ -17,7 +17,6 @@ Release x64 - 17.0 @@ -53,27 +52,24 @@ true Unicode - - + + + + + + + + + + + + + - - - - - - - - - - - - - - Level3 @@ -130,9 +126,14 @@ true - - + + + + + + + - + \ No newline at end of file diff --git a/CST 126/Homework 3/Homework 3.vcxproj.filters b/CST 126/Homework 3/Homework 3.vcxproj.filters index a8a6563..b27b6ea 100644 --- a/CST 126/Homework 3/Homework 3.vcxproj.filters +++ b/CST 126/Homework 3/Homework 3.vcxproj.filters @@ -14,4 +14,17 @@ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + Header Files + + + Header Files + + + + + Source Files + + \ No newline at end of file diff --git a/CST 126/Homework 3/SinglyLinkedList.hpp b/CST 126/Homework 3/SinglyLinkedList.hpp new file mode 100644 index 0000000..e28c142 --- /dev/null +++ b/CST 126/Homework 3/SinglyLinkedList.hpp @@ -0,0 +1,256 @@ +#ifndef SINGLY_LINKED_LIST_HPP +#define SINGLY_LINKED_LIST_HPP + +struct ListNode +{ + int _data{ 0 }; + ListNode* _next{ nullptr }; +}; + +struct SinglyLinkedList +{ + size_t _size{ 0 }; + ListNode* _head{ nullptr }; +}; + +bool Append(SinglyLinkedList* list, ListNode* node); +bool Prepend(SinglyLinkedList* list, ListNode* node); +bool RemoveFirst(SinglyLinkedList* list); +bool RemoveLast(SinglyLinkedList* list); +bool InsertAfter(SinglyLinkedList* list, const int data, ListNode* node); +bool InsertBefore(SinglyLinkedList* list, const int data, ListNode* node); +bool Clear(SinglyLinkedList* list); +ListNode* Extract(SinglyLinkedList* list, const int data); +bool Empty(SinglyLinkedList* list); +bool Remove(SinglyLinkedList* list, ListNode* node); + +//code +bool Append(SinglyLinkedList* list, ListNode* node ) +{ + //we have a list + //we need to add a node to the end of the list + + //empty + if (Empty(list)) + { + list->_head = node; + list->_size++; + return true; + } + //Append head + if(list->_size == 1) + { + list->_head->_next = node; + list->_size++; + return true; + } + //Down the list + ListNode* travel = nullptr; + for(travel = list->_head; travel->_next != nullptr;) + { + travel = travel->_next; + } + travel->_next = node; + list->_size++; + return true; +} + +bool Prepend(SinglyLinkedList* list, ListNode* node) +{ + if (Empty(list)) + { + list->_head = node; + list->_size++; + return true; + } + + node->_next = list->_head; + list->_head = node; + + list->_size++; + return true; +} + +bool RemoveFirst(SinglyLinkedList* list) +{ + //check if zero size + if (Empty(list)) return true; + + if(list->_size == 1) + { + + list->_head = nullptr; + } + else + { + ListNode* prev = list->_head; + list->_head = list->_head->_next; + prev->_next = nullptr; + } + + list->_size--; + + return true; +} + +bool RemoveLast(SinglyLinkedList* list) +{ + if (Empty(list)) return true; + + if (list->_size == 1) + { + list->_head = nullptr; + return true; + } + + ListNode* travel = list->_head; + while(travel->_next->_next != nullptr) + { + travel = travel->_next; + } + travel->_next = nullptr; + list->_size--; + return true; + +} + +bool InsertAfter(SinglyLinkedList* list, const int data, ListNode* node) +{ + //first to find data + //thoughts? What if we are inserting at after end. + ListNode* travel; + for (travel = list->_head; travel->_data != data && travel->_next != nullptr; ) + { + travel = travel->_next; + } + + if (travel->_next == nullptr) + { + return Append(list, node); + } + + node->_next = travel->_next; + travel->_next = node; + list->_size++; + + //then insert after data + return true; +} + +bool InsertBefore(SinglyLinkedList* list, const int data, ListNode* node) +{ + if (list->_head->_data == data) + return Prepend(list, node); + + ListNode* travel; + for (travel = list->_head; travel->_next->_data != data;) + { + travel = travel->_next; + } + + node->_next = travel->_next; + travel->_next = node; + list->_size++; + + return true; + +} + +bool Clear(SinglyLinkedList* list) +{ + //consider the head + //consider the size + //We have to detach every node from each other + //start at the head + //use a node* to track our position + + if (list->_size == 0) return true; + + ListNode* travel = list->_head; + ListNode* prev = travel; + + do + { + prev = travel; + travel = travel->_next; + prev->_data = 0; + prev->_next = nullptr; + + } while (travel != nullptr && travel->_next != nullptr); + + list->_size = 0; + list->_head = nullptr; + + return true; +} + +ListNode* Extract(SinglyLinkedList* list, const int data) +{ + //check if empty, shortcut return + ListNode* temp = new ListNode{0, nullptr}; + ListNode* travel = nullptr; + + if (Empty(list)) + { + return temp; + } + //Read through list + for (travel = list->_head; travel->_data != data && travel->_next != nullptr; ) + { + travel = travel->_next; + } + //find the data + //pointer to the node + temp->_data = travel->_data; + //remove node from list + if(Remove(list, travel)) + { + return temp; + } + //or don't find data + + return nullptr; +} + +bool Remove(SinglyLinkedList* list, ListNode* node) +{ + //find the node + //Read through list + ListNode* travel = list->_head; + ListNode* prev = travel; + + while(travel != node) + { + prev = travel; + + travel = travel->_next; + } + //if first, remove first + if(travel == list->_head) + { + return RemoveFirst(list); + } + //if last, remove last + if(travel->_next == nullptr) + { + return RemoveLast(list); + } + //else in middle + //remove travel's node + //will need previous node + //to set previous's next to travel's next + prev->_next = travel->_next; //fixing pointer between nodes + //removes dangling pointer from prev to travel + + //delete travel + travel->_next = nullptr; + travel->_data = 0; + list->_size--; +} + +bool Empty(SinglyLinkedList* list) +{ + return (list->_size == 0 && list->_head == nullptr); +} + +#endif // !SINGLY_LINKED_LIST_HPP \ No newline at end of file diff --git a/CST 126/Homework 3/node.hpp b/CST 126/Homework 3/node.hpp new file mode 100644 index 0000000..ac89141 --- /dev/null +++ b/CST 126/Homework 3/node.hpp @@ -0,0 +1,42 @@ +#ifndef NODE_HPP +#define NODE_HPP + + + + +namespace CST126 +{ + template + class Node + { + public: + Node() = default; + Node(const T& data); + + ~Node() = default; + + T& Data(); + T Value() const; + void Data(const T& data); + + + + private: + T _data; + }; + + + + + template + T Node::Data() + { + return T(); + } + + template + void Node::Data(T data) + { + _data = data; + } +} \ No newline at end of file diff --git a/CST 126/Homework 3/program.cpp b/CST 126/Homework 3/program.cpp new file mode 100644 index 0000000..4d6c025 --- /dev/null +++ b/CST 126/Homework 3/program.cpp @@ -0,0 +1,10 @@ + + + + +void main() +{ + + + +} \ No newline at end of file diff --git a/CST 126/LinkedListUnitTests/LinkedListUnitTests.cpp b/CST 126/LinkedListUnitTests/LinkedListUnitTests.cpp new file mode 100644 index 0000000..15defc0 --- /dev/null +++ b/CST 126/LinkedListUnitTests/LinkedListUnitTests.cpp @@ -0,0 +1,519 @@ +#include "pch.h" +#include "CppUnitTest.h" + +#include + +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +#include "SinglyLinkedList.hpp"; + +namespace LinkedListUnitTests +{ + TEST_CLASS(LinkedListUnitTests) + { + public: + std::list my_list{1, 5, 6, 7 ,9, 10}; + + //Empty + TEST_METHOD(EmptyListHasZeroSize) + { + //Arrange + SinglyLinkedList linkedList{}; + + //Assert + Assert::AreEqual(0ull, linkedList._size); + } + + //Append + TEST_METHOD(AppendingLinkedList) + { + //Arrange + struct SinglyLinkedList linkedList = {}; + + ListNode node = {5, nullptr}; + + //Act + bool success = Append(&linkedList, &node); + + //Assert + Assert::AreEqual(5, linkedList._head->_data); + Assert::AreEqual(1ull, linkedList._size); + + + } + + TEST_METHOD(MultipleAppend_LinkedList_Success) + { + //Arrange + struct SinglyLinkedList linkedList = {}; + + ListNode node1 = { 1, nullptr }; + ListNode node2 = { 2, nullptr }; + ListNode node3 = { 3, nullptr }; + ListNode node4 = { 4, nullptr }; + ListNode node5 = { 5, nullptr }; + + //Act + bool success = Append(&linkedList, &node1); + success = Append(&linkedList, &node2); + success = Append(&linkedList, &node3); + success = Append(&linkedList, &node4); + success = Append(&linkedList, &node5); + + Assert::AreEqual(node1._data, linkedList._head->_data); + + ListNode* travel = linkedList._head; + //Assert + for (auto i = 1; i <= 5; i++) + { + Assert::AreEqual(i, travel->_data); + travel = travel->_next; + + } + + } + + //Prepend + TEST_METHOD(OnePrependLinkedList) + { + //Arrange + struct SinglyLinkedList linkedList = {}; + + ListNode node = { 5, nullptr }; + + //Act + bool success = Prepend(&linkedList, &node); + + //Assert + Assert::AreEqual(5, linkedList._head->_data); + Assert::AreEqual(1ull, linkedList._size); + + + } + + TEST_METHOD(MultiplePrepend_LinkedList_Success) + { + //Arrange + struct SinglyLinkedList linkedList = {}; + + ListNode node1 = { 1, nullptr }; + ListNode node2 = { 2, nullptr }; + ListNode node3 = { 3, nullptr }; + ListNode node4 = { 4, nullptr }; + ListNode node5 = { 5, nullptr }; + + //Act + bool success = Prepend(&linkedList, &node1); + success = Prepend(&linkedList, &node2); + success = Prepend(&linkedList, &node3); + success = Prepend(&linkedList, &node4); + success = Prepend(&linkedList, &node5); + + Assert::AreEqual(node5._data, linkedList._head->_data); + + ListNode* travel = linkedList._head; + //Assert + for (auto i = 5; i >= 1; i--) + { + Assert::AreEqual(i, travel->_data); + travel = travel->_next; + + } + + } + + //RemoveFirst + TEST_METHOD(RemoveFirstNode_LinkedList_Success) + { + struct SinglyLinkedList linkedList = {}; + + ListNode node1 = { 1, nullptr }; + ListNode node2 = { 2, nullptr }; + ListNode node3 = { 3, nullptr }; + ListNode node4 = { 4, nullptr }; + ListNode node5 = { 5, nullptr }; + + //Act + bool success = Append(&linkedList, &node1); + success = Append(&linkedList, &node2); + success = Append(&linkedList, &node3); + success = Append(&linkedList, &node4); + success = Append(&linkedList, &node5); + + RemoveFirst(&linkedList); + + ListNode* travel = linkedList._head; + for (auto i = 2; i <= 5; i++) + { + Assert::AreEqual(i, travel->_data); + travel = travel->_next; + + } + + } + + TEST_METHOD(RemoveFirstNodeWithOneNode_LinkedList_Success) + { + struct SinglyLinkedList linkedList = {}; + + ListNode node1 = { 1, nullptr }; + + //Act + bool success = Append(&linkedList, &node1); + + RemoveFirst(&linkedList); + + Assert::IsNull(linkedList._head); + } + + //RemoveLast + TEST_METHOD(RemoveLastNode_LinkedList_Success) + { + struct SinglyLinkedList linkedList = {}; + + ListNode node1 = { 1, nullptr }; + ListNode node2 = { 2, nullptr }; + ListNode node3 = { 3, nullptr }; + ListNode node4 = { 4, nullptr }; + ListNode node5 = { 5, nullptr }; + + //Act + bool success = Append(&linkedList, &node1); + success = Append(&linkedList, &node2); + success = Append(&linkedList, &node3); + success = Append(&linkedList, &node4); + success = Append(&linkedList, &node5); + + RemoveLast(&linkedList); + + ListNode* travel = linkedList._head; + for (auto i = 1; i <= 4; i++) + { + Assert::AreEqual(i, travel->_data); + travel = travel->_next; + + } + + } + + TEST_METHOD(RemoveLastNodeWithOneNode_LinkedList_Success) + { + struct SinglyLinkedList linkedList = {}; + + ListNode node1 = { 1, nullptr }; + + //Act + bool success = Append(&linkedList, &node1); + + RemoveLast(&linkedList); + + Assert::IsNull(linkedList._head); + } + + //InsertAfter + TEST_METHOD(Single_InserterAfter_LinkedList_Success) + { + //Arrange + struct SinglyLinkedList newList = {}; + //Append Nodes + ListNode node1 = { 1, nullptr }; + ListNode node2 = { 2, nullptr }; + ListNode node4 = { 4, nullptr }; + ListNode node5 = { 5, nullptr }; + + bool success = Append(&newList, &node1); + success = Append(&newList, &node2); + success = Append(&newList, &node4); + success = Append(&newList, &node5); + + //Act + //Insert After a node + ListNode node3 = { 3, nullptr }; + InsertAfter(&newList, 2, &node3); + + //Assert + //Assert that list is correct, one node at a time + + ListNode* travel = newList._head; + for (auto i = 1; i <= 5; i++) + { + Assert::AreEqual(i, travel->_data); + travel = travel->_next; + + } + } + + TEST_METHOD(Single_InserterAfterEnd_LinkedList_Success) + { + //Arrange + struct SinglyLinkedList newList = {}; + //Append Nodes + ListNode node1 = { 1, nullptr }; + ListNode node2 = { 2, nullptr }; + ListNode node3 = { 3, nullptr }; + ListNode node4 = { 4, nullptr }; + + bool success = Append(&newList, &node1); + success = Append(&newList, &node2); + success = Append(&newList, &node3); + success = Append(&newList, &node4); + + //Act + //Insert After a node + ListNode node5 = { 5, nullptr }; + InsertAfter(&newList, 4, &node5); + + //Assert + //Assert that list is correct, one node at a time + + ListNode* travel = newList._head; + for (auto i = 1; i <= 5; i++) + { + Assert::AreEqual(i, travel->_data); + travel = travel->_next; + + } + } + + //InsertBefore + TEST_METHOD(Single_InserterBefore_LinkedList_Success) + { + //Arrange + struct SinglyLinkedList newList = {}; + //Append Nodes + ListNode node1 = { 1, nullptr }; + ListNode node2 = { 2, nullptr }; + ListNode node4 = { 4, nullptr }; + ListNode node5 = { 5, nullptr }; + + bool success = Append(&newList, &node1); + success = Append(&newList, &node2); + success = Append(&newList, &node4); + success = Append(&newList, &node5); + + //Act + //Insert After a node + ListNode node3 = { 3, nullptr }; + InsertBefore(&newList, 4, &node3); + + //Assert + //Assert that list is correct, one node at a time + + ListNode* travel = newList._head; + for (auto i = 1; i <= 5; i++) + { + Assert::AreEqual(i, travel->_data); + travel = travel->_next; + + } + } + + TEST_METHOD(Single_InserterBeforeHead_LinkedList_Success) + { + //Arrange + struct SinglyLinkedList newList = {}; + //Append Nodes + ListNode node2 = { 2, nullptr }; + ListNode node3 = { 3, nullptr }; + ListNode node4 = { 4, nullptr }; + ListNode node5 = { 5, nullptr }; + + bool success = Append(&newList, &node2); + success = Append(&newList, &node3); + success = Append(&newList, &node4); + success = Append(&newList, &node5); + + //Act + //Insert After a node + ListNode node1 = { 1, nullptr }; + InsertBefore(&newList, 2, &node1); + + //Assert + //Assert that list is correct, one node at a time + + ListNode* travel = newList._head; + for (auto i = 1; i <= 5; i++) + { + Assert::AreEqual(i, travel->_data); + travel = travel->_next; + + } + } + + //Clear + TEST_METHOD(OneAppend_Clear_LinkedList_Success) + { + //Arrange + struct SinglyLinkedList linkedList = {}; + ListNode node1 = { 1, nullptr }; + bool success = Append(&linkedList, &node1); + + //Act + //Clearing the list + Clear(&linkedList); + + //Assert + Assert::AreEqual(0ull, linkedList._size); + Assert::IsNull(linkedList._head); + } + + TEST_METHOD(MultipleAppend_Clear_LinkedList_Success) + { + //Arrange + struct SinglyLinkedList linkedList = {}; + + ListNode node1 = { 1, nullptr }; + ListNode node2 = { 2, nullptr }; + ListNode node3 = { 3, nullptr }; + ListNode node4 = { 4, nullptr }; + ListNode node5 = { 5, nullptr }; + + bool success = Append(&linkedList, &node1); + success = Append(&linkedList, &node2); + success = Append(&linkedList, &node3); + success = Append(&linkedList, &node4); + success = Append(&linkedList, &node5); + + //Act + //Clearing the list + Clear(&linkedList); + + //Assert + Assert::AreEqual(0ull, linkedList._size); + Assert::IsNull(linkedList._head); + + Assert::IsNull(node1._next); + Assert::IsNull(node2._next); + Assert::IsNull(node3._next); + Assert::IsNull(node4._next); + Assert::IsNull(node5._next); + } + + //Extract + TEST_METHOD(ExtractFirst_LinkedList_Success) + { + //Arrange + struct SinglyLinkedList newList = {}; + //Append Nodes + ListNode node1 = { 1, nullptr }; + ListNode node2 = { 2, nullptr }; + ListNode node3 = { 3, nullptr }; + ListNode node4 = { 4, nullptr }; + ListNode node5 = { 5, nullptr }; + + ListNode nodeArray[] = { node1, node2, node3, node4, node5 }; + + for (auto& node : nodeArray) + { + Assert::IsTrue(Append(&newList, &node)); + } + + ListNode* temp = Extract(&newList, node1._data); + + /*size_t nodeAddress = reinterpret_cast(&node1); + size_t tempAddress = reinterpret_cast(temp); + + Assert::AreEqual(nodeAddress, tempAddress);*/ + + Assert::AreEqual(4ull, newList._size); + + delete temp; + } + + TEST_METHOD(ExtractLast_LinkedList_Success) + { + //Arrange + struct SinglyLinkedList newList = {}; + //Append Nodes + ListNode node1 = { 1, nullptr }; + ListNode node2 = { 2, nullptr }; + ListNode node3 = { 3, nullptr }; + ListNode node4 = { 4, nullptr }; + ListNode node5 = { 5, nullptr }; + + ListNode nodeArray[] = { node1, node2, node3, node4, node5 }; + + for (auto& node : nodeArray) + { + Assert::IsTrue(Append(&newList, &node)); + } + + ListNode* temp = Extract(&newList, node5._data); + + Assert::AreEqual(4ull, newList._size); + + delete temp; + } + + TEST_METHOD(ExtractMiddle_LinkedList_Success) + { + //Arrange + struct SinglyLinkedList newList = {}; + //Append Nodes + ListNode node1 = { 1, nullptr }; + ListNode node2 = { 2, nullptr }; + ListNode node3 = { 3, nullptr }; + ListNode node4 = { 4, nullptr }; + ListNode node5 = { 5, nullptr }; + + ListNode nodeArray[] = { node1, node2, node3, node4, node5 }; + + for (auto& node : nodeArray) + { + Assert::IsTrue(Append(&newList, &node)); + } + + ListNode* temp = Extract(&newList, node3._data); + + Assert::AreEqual(4ull, newList._size); + + delete temp; + } + + //Remove + TEST_METHOD(RemoveNode_LinkedList_Success) + { + struct SinglyLinkedList linkedList = {}; + + ListNode node1 = { 1, nullptr }; + ListNode node2 = { 2, nullptr }; + ListNode node3 = { 3, nullptr }; + ListNode node4 = { 4, nullptr }; + ListNode node5 = { 5, nullptr }; + + //Act + bool success = Append(&linkedList, &node1); + success = Append(&linkedList, &node2); + success = Append(&linkedList, &node3); + success = Append(&linkedList, &node4); + success = Append(&linkedList, &node5); + + Remove(&linkedList, &node3); + + ListNode* travel = linkedList._head; + for (auto i = 1; i <= 5; i++) + { + if (i == 3) + i++; + Assert::AreEqual(i, travel->_data); + travel = travel->_next; + + } + + } + + TEST_METHOD(RemoveNodeWithOneNode_Linked_List_Success) { + struct SinglyLinkedList linkedList = {}; + + ListNode node1 = { 1, nullptr }; + + //Act + bool success = Append(&linkedList, &node1); + + Remove(&linkedList, &node1); + + Assert::IsNull(linkedList._head); + } + + }; +} diff --git a/CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj b/CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj new file mode 100644 index 0000000..25b18fa --- /dev/null +++ b/CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj @@ -0,0 +1,174 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + {764A846B-5FB7-4C7A-8D47-9CC204AEEE15} + Win32Proj + LinkedListUnitTests + 10.0 + NativeUnitTestProject + + + + DynamicLibrary + true + v143 + Unicode + false + + + DynamicLibrary + false + v143 + true + Unicode + false + + + DynamicLibrary + true + v143 + Unicode + false + + + DynamicLibrary + false + v143 + true + Unicode + false + + + + + + + + + + + + + + + + + + + + + true + ..\Homework 3;$(IncludePath) + + + true + + + false + + + false + + + + Use + Level3 + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Use + Level3 + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Use + Level3 + true + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Use + Level3 + true + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj.filters b/CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj.filters new file mode 100644 index 0000000..ed7bc9d --- /dev/null +++ b/CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/CST 126/LinkedListUnitTests/pch.cpp b/CST 126/LinkedListUnitTests/pch.cpp new file mode 100644 index 0000000..64b7eef --- /dev/null +++ b/CST 126/LinkedListUnitTests/pch.cpp @@ -0,0 +1,5 @@ +// pch.cpp: source file corresponding to the pre-compiled header + +#include "pch.h" + +// When you are using pre-compiled headers, this source file is necessary for compilation to succeed. diff --git a/CST 126/LinkedListUnitTests/pch.h b/CST 126/LinkedListUnitTests/pch.h new file mode 100644 index 0000000..9d715b0 --- /dev/null +++ b/CST 126/LinkedListUnitTests/pch.h @@ -0,0 +1,12 @@ +// pch.h: This is a precompiled header file. +// Files listed below are compiled only once, improving build performance for future builds. +// This also affects IntelliSense performance, including code completion and many code browsing features. +// However, files listed here are ALL re-compiled if any one of them is updated between builds. +// Do not add files here that you will be updating frequently as this negates the performance advantage. + +#ifndef PCH_H +#define PCH_H + +// add headers that you want to pre-compile here + +#endif //PCH_H -- cgit v1.2.3