diff options
| author | reecepwarner <[email protected]> | 2024-05-29 12:44:24 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-05-29 12:44:24 -0700 |
| commit | a94e681196881e3f8fb18ecfd760ed3f59fa8ca1 (patch) | |
| tree | 46158946d1c7aa12c44acc6043bcc595523a0c88 | |
| parent | homework2 completed (diff) | |
| download | homework-1-reecepwarner-a94e681196881e3f8fb18ecfd760ed3f59fa8ca1.tar.xz homework-1-reecepwarner-a94e681196881e3f8fb18ecfd760ed3f59fa8ca1.zip | |
Template node branch to Develop Branch (#3)
* init
* changes
* changes
* created insert and deletion functions
* unit testing homework3
* more unit tests
* unit tests added
* unit test and memory check added
* Template node
* essentially completed
---------
Co-authored-by: rPatrickWarner <[email protected]>
| -rw-r--r-- | CST 126/CST_126.sln | 10 | ||||
| -rw-r--r-- | CST 126/Homework3/Homework3.vcxproj | 7 | ||||
| -rw-r--r-- | CST 126/Homework3/Homework3.vcxproj.filters | 8 | ||||
| -rw-r--r-- | CST 126/Homework3/Node.hpp | 53 | ||||
| -rw-r--r-- | CST 126/Homework3/SinglyLinkedList.hpp | 240 | ||||
| -rw-r--r-- | CST 126/Homework3/main.cpp | 9 | ||||
| -rw-r--r-- | CST 126/UnitTest2/UnitTest2.cpp | 39 | ||||
| -rw-r--r-- | CST 126/UnitTest2/UnitTest2.vcxproj | 174 | ||||
| -rw-r--r-- | CST 126/UnitTest2/UnitTest2.vcxproj.filters | 30 | ||||
| -rw-r--r-- | CST 126/UnitTest2/pch.cpp | 5 | ||||
| -rw-r--r-- | CST 126/UnitTest2/pch.h | 12 | ||||
| -rw-r--r-- | CST 126/UnitTester/UnitTester.cpp | 364 | ||||
| -rw-r--r-- | CST 126/UnitTester/UnitTester.vcxproj | 175 | ||||
| -rw-r--r-- | CST 126/UnitTester/UnitTester.vcxproj.filters | 33 | ||||
| -rw-r--r-- | CST 126/UnitTester/crt_check_memory.hpp | 40 | ||||
| -rw-r--r-- | CST 126/UnitTester/pch.cpp | 5 | ||||
| -rw-r--r-- | CST 126/UnitTester/pch.h | 12 |
17 files changed, 1208 insertions, 8 deletions
diff --git a/CST 126/CST_126.sln b/CST 126/CST_126.sln index dfd6a7e..f2e1baf 100644 --- a/CST 126/CST_126.sln +++ b/CST 126/CST_126.sln @@ -11,6 +11,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Homework2", "Homework2\Home EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Homework3", "Homework3\Homework3.vcxproj", "{AE105706-54B6-43BA-A937-A16C59A2A261}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTester", "UnitTester\UnitTester.vcxproj", "{EAE78C46-5B7C-4F8C-A266-B5D4E3A762D1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -51,6 +53,14 @@ Global {AE105706-54B6-43BA-A937-A16C59A2A261}.Release|x64.Build.0 = Release|x64 {AE105706-54B6-43BA-A937-A16C59A2A261}.Release|x86.ActiveCfg = Release|Win32 {AE105706-54B6-43BA-A937-A16C59A2A261}.Release|x86.Build.0 = Release|Win32 + {EAE78C46-5B7C-4F8C-A266-B5D4E3A762D1}.Debug|x64.ActiveCfg = Debug|x64 + {EAE78C46-5B7C-4F8C-A266-B5D4E3A762D1}.Debug|x64.Build.0 = Debug|x64 + {EAE78C46-5B7C-4F8C-A266-B5D4E3A762D1}.Debug|x86.ActiveCfg = Debug|Win32 + {EAE78C46-5B7C-4F8C-A266-B5D4E3A762D1}.Debug|x86.Build.0 = Debug|Win32 + {EAE78C46-5B7C-4F8C-A266-B5D4E3A762D1}.Release|x64.ActiveCfg = Release|x64 + {EAE78C46-5B7C-4F8C-A266-B5D4E3A762D1}.Release|x64.Build.0 = Release|x64 + {EAE78C46-5B7C-4F8C-A266-B5D4E3A762D1}.Release|x86.ActiveCfg = Release|Win32 + {EAE78C46-5B7C-4F8C-A266-B5D4E3A762D1}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CST 126/Homework3/Homework3.vcxproj b/CST 126/Homework3/Homework3.vcxproj index 34e042a..0625066 100644 --- a/CST 126/Homework3/Homework3.vcxproj +++ b/CST 126/Homework3/Homework3.vcxproj @@ -70,6 +70,9 @@ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> </ImportGroup> <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <IncludePath>C:\Users\rpwar\source\repos\CST126\homework-1-reecepwarner\CST 126\UnitTest1;$(IncludePath)</IncludePath> + </PropertyGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ClCompile> <WarningLevel>Level3</WarningLevel> @@ -129,6 +132,10 @@ <ItemGroup> <ClCompile Include="main.cpp" /> </ItemGroup> + <ItemGroup> + <ClInclude Include="Node.hpp" /> + <ClInclude Include="SinglyLinkedList.hpp" /> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> diff --git a/CST 126/Homework3/Homework3.vcxproj.filters b/CST 126/Homework3/Homework3.vcxproj.filters index ce0c35c..6f86576 100644 --- a/CST 126/Homework3/Homework3.vcxproj.filters +++ b/CST 126/Homework3/Homework3.vcxproj.filters @@ -19,4 +19,12 @@ <Filter>Source Files</Filter> </ClCompile> </ItemGroup> + <ItemGroup> + <ClInclude Include="SinglyLinkedList.hpp"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="Node.hpp"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> </Project>
\ No newline at end of file diff --git a/CST 126/Homework3/Node.hpp b/CST 126/Homework3/Node.hpp new file mode 100644 index 0000000..1bfbff2 --- /dev/null +++ b/CST 126/Homework3/Node.hpp @@ -0,0 +1,53 @@ +#ifndef NODE_HPP +#define NODE_HPP + +namespace CST_126 +{ + template<typename T> + class Node + { + public: + Node() = default; + Node(const T& Data); + + ~Node() = default; + + + T& Data(); + T Data() const; + void Data(const T& Data); + + + private: + + T _data{ 0 }; + + }; + + template<typename T> + Node<T>::Node(const T& Data) : _data(Data) {}; + + template<typename T> + inline T& Node<T>::Data() + { + return _data; + } + + template<typename T> + inline T Node<T>::Data() const + { + return _data; + } + + template<typename T> + inline void Node<T>::Data(const T& Data) + { + _data = Data; + } + +} + + + + +#endif
\ No newline at end of file diff --git a/CST 126/Homework3/SinglyLinkedList.hpp b/CST 126/Homework3/SinglyLinkedList.hpp new file mode 100644 index 0000000..92f4a1f --- /dev/null +++ b/CST 126/Homework3/SinglyLinkedList.hpp @@ -0,0 +1,240 @@ +#ifndef SINGLY_LINKED_LIST_HPP +#define SINGLY_LINKED_LIST_HPP +#include <iostream> +#include "Node.hpp" +template<typename T> + struct ListNode + { + T _data{0}; + ListNode* _next {nullptr}; + }; + +template<typename T> +struct SinglyLinkedList +{ + size_t _size {0}; + + ListNode<T>* _head{ nullptr }; + +}; + + +template<typename T> +inline bool Append(SinglyLinkedList<T>* list, ListNode<T>* node) +{ + if (list->_size == 0) + { + list->_head = node; + list->_size++; + return true; + } + ListNode<T>* TraverseNode = nullptr; + for (TraverseNode = list->_head; TraverseNode->_next != nullptr;) + { + TraverseNode = TraverseNode->_next; + } + + TraverseNode->_next = node; + list->_size++; + return true; +} + +template<typename T> +inline bool Prepend(SinglyLinkedList<T>* list, ListNode<T>* node) +{ + if (list->_size == 0) + { + list->_head = node; + list->_size++; + return true; + } + node->_next = list->_head; + list->_head = node; + list->_size++; + return true; +} + +template<typename T> +inline bool RemoveFirst(SinglyLinkedList<T>* list) +{ + if (list->_size == 0) + { + std::cout << "Empty list... there is nothing to delete!" << std::endl; + return true; + } + if (list->_size == 1) + { + list->_head =nullptr; + } + else + { + ListNode<T>* Temp = list->_head; + list->_head = list->_head->_next; + Temp->_next = nullptr; + list->_size--; + } + + return true; +} + +template<typename T> +inline bool RemoveLast(SinglyLinkedList<T>* list) +{ + if (list->_size == 0) + { + std::cout << "Empty list... there is nothing to delete!" << std::endl; + return true; + } + if (list->_size == 1) + { + list->_head = nullptr; + list->_size--; + return true; + } + ListNode<T>* TraverseNode = list->_head; + while (TraverseNode->_next->_next != nullptr) + { + TraverseNode = TraverseNode->_next; + } + TraverseNode->_next = nullptr; + list->_size--; + return true; +} + +template <typename T> +inline bool InsertAfter(SinglyLinkedList<T>* List, const int Data, ListNode<T>* node) +{ + if (List->_head == nullptr) + { + Append(List, node); + return true; + } + ListNode<T>* Traverse = List->_head; + for (auto i = 1; i < Data && Traverse != nullptr; i++) + { + Traverse = Traverse->_next; + } + node->_next = Traverse->_next; + + Traverse->_next = node; + List->_size++; + + return true; +} + +template <typename T> +inline bool InsertBefore(SinglyLinkedList<T>* List, const int Data, ListNode<T>* node) +{ + if (List->_head == nullptr) + { + Append(List, node); + return true; + } + ListNode<T>* Traverse = List->_head; + ListNode<T>* Follower = nullptr; + for (auto i = 1; i < Data && Traverse != nullptr; i++) + { + Follower = Traverse; + Traverse = Traverse->_next; + } + node->_next = Follower->_next; + Follower->_next = node; + List->_size++; + return true; +} + +template <typename T> +inline bool Clear(SinglyLinkedList<T>* List) +{ + if (List->_size == 0) + { + return true; + } + if (List->_size == 1) + { + List->_head = nullptr; + List->_size--; + return true; + } + ListNode<T>* Traverse = List->_head; + ListNode<T>* TempNode = Traverse; + + do + { + TempNode = Traverse; + Traverse = Traverse->_next; + TempNode->_data = 0; + TempNode->_next = nullptr; + } while (Traverse->_next != nullptr); + + List->_size = 0; + List->_head = nullptr; + return true; +} + +template <typename T> +inline bool Empty(SinglyLinkedList<T>* List) +{ + return (List->_size == 0 && List->_head == nullptr); +} + +template <typename T> +inline bool Remove(SinglyLinkedList<T>* List, ListNode<T>* node) +{ + + ListNode<T>* Traverse = List->_head; + ListNode<T>* Previous = nullptr; + while (Traverse != node) + { + Previous = Traverse; + Traverse = Traverse->_next; + } + if (Traverse == List->_head) + { + return RemoveFirst(List); + } + if (Traverse->_next == nullptr) + { + return RemoveLast(List); + } + + Previous->_next = Traverse->_next; + + Traverse->_next = nullptr; + Traverse->_data = 0; + List->_size--; + + return true; +} + + + +template <typename T> +inline ListNode<T>* Extract(SinglyLinkedList<T>* List, const int Data) +{ + ListNode<T>* Temp = new ListNode<T>{ 0, nullptr }; + + ListNode<T>* Travel = nullptr; + + if (Empty(List)) + { + std::cout << "Empty list, nothing to extract!" << std::endl; + return Temp; + + } + for (Travel = List->_head; Travel->_data != Data && Travel->_next != nullptr;) + { + Travel = Travel->_next; + } + Temp->_data = Travel->_data; + + if (Remove<T>(List, Travel)) + { + return Temp; + } + + return nullptr; +} + + +#endif
\ No newline at end of file diff --git a/CST 126/Homework3/main.cpp b/CST 126/Homework3/main.cpp index 6771ba7..fb631b8 100644 --- a/CST 126/Homework3/main.cpp +++ b/CST 126/Homework3/main.cpp @@ -2,18 +2,11 @@ //Date:5/8/24 //Assignment:Homework3 - +#include "SinglyLinkedList.hpp" int main(const int argc, char* argv[]) { - - - - - - - return 0; }
\ No newline at end of file diff --git a/CST 126/UnitTest2/UnitTest2.cpp b/CST 126/UnitTest2/UnitTest2.cpp new file mode 100644 index 0000000..6cbd9a5 --- /dev/null +++ b/CST 126/UnitTest2/UnitTest2.cpp @@ -0,0 +1,39 @@ +#include "pch.h" +#include "CppUnitTest.h" +#include "SinglyLinkedList.hpp" +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace UnitTest2 +{ + { + TEST_CLASS(LinkedListUnitTests) + { + public: + + + TEST_METHOD(EmptyListHasZeroSize) + { + SinglyLinkedList linkedList{}; + + + + Assert::AreEqual(0ull, linkedlist._size); + } + + + + TEST_METHOD(AppendingLinkedList) + { + SinglyLinkedList linkedList{}; + ListNode* node = { + }; + node->_data = 5; + + bool success = Append(&linkedlist, node); + + Assert::AreEqual(5, linkedlist._head->_data); + } + }; + } + +} diff --git a/CST 126/UnitTest2/UnitTest2.vcxproj b/CST 126/UnitTest2/UnitTest2.vcxproj new file mode 100644 index 0000000..b58d943 --- /dev/null +++ b/CST 126/UnitTest2/UnitTest2.vcxproj @@ -0,0 +1,174 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <VCProjectVersion>17.0</VCProjectVersion> + <ProjectGuid>{630E30B6-C93A-4D5D-8FCF-00E41C10EC6F}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <RootNamespace>UnitTest2</RootNamespace> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + <ProjectSubType>NativeUnitTestProject</ProjectSubType> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + <UseOfMfc>false</UseOfMfc> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + <UseOfMfc>false</UseOfMfc> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + <UseOfMfc>false</UseOfMfc> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + <UseOfMfc>false</UseOfMfc> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + <IncludePath>C:\Users\rpwar\source\repos\CST126\homework-1-reecepwarner\CST 126\Homework3;$(IncludePath)</IncludePath> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PrecompiledHeader>Use</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <UseFullPaths>true</UseFullPaths> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PrecompiledHeader>Use</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <UseFullPaths>true</UseFullPaths> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <PrecompiledHeader>Use</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <UseFullPaths>true</UseFullPaths> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <PrecompiledHeader>Use</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <UseFullPaths>true</UseFullPaths> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="pch.cpp"> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> + </ClCompile> + <ClCompile Include="UnitTest2.cpp" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="pch.h" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/CST 126/UnitTest2/UnitTest2.vcxproj.filters b/CST 126/UnitTest2/UnitTest2.vcxproj.filters new file mode 100644 index 0000000..34345cd --- /dev/null +++ b/CST 126/UnitTest2/UnitTest2.vcxproj.filters @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> + <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> + </Filter> + <Filter Include="Resource Files"> + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> + <ClCompile Include="UnitTest2.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="pch.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <ClInclude Include="pch.h"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/CST 126/UnitTest2/pch.cpp b/CST 126/UnitTest2/pch.cpp new file mode 100644 index 0000000..64b7eef --- /dev/null +++ b/CST 126/UnitTest2/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/UnitTest2/pch.h b/CST 126/UnitTest2/pch.h new file mode 100644 index 0000000..9d715b0 --- /dev/null +++ b/CST 126/UnitTest2/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 diff --git a/CST 126/UnitTester/UnitTester.cpp b/CST 126/UnitTester/UnitTester.cpp new file mode 100644 index 0000000..83b51d9 --- /dev/null +++ b/CST 126/UnitTester/UnitTester.cpp @@ -0,0 +1,364 @@ +#include "pch.h" +#include "CppUnitTest.h" +#include "SinglyLinkedList.hpp" +#include "crt_check_memory.hpp" + +using namespace Microsoft::VisualStudio::CppUnitTestFramework; +using namespace CST_126; + +namespace LinkedListUnitTests +{ + TEST_CLASS(LinkedListUnitTests) + { + public: + + TEST_METHOD(EmptyListHasZeroSize) + { + SinglyLinkedList<int> LinkedList{}; + Assert::AreEqual(0ull, LinkedList._size); + } + + TEST_METHOD(AppendingLinkedListWith1Item) + { + SinglyLinkedList<int> LinkedList{}; + ListNode<int>* node = new ListNode<int>{ 5, nullptr }; + + + bool Success = Append(&LinkedList, node); + Assert::AreEqual(5, LinkedList._head->_data); + delete node; + } + TEST_METHOD(AppendingLinkedListWith5Items) + { + struct SinglyLinkedList<int> LinkedList = {}; + ListNode<int>Node1 ={ 1,nullptr }; + ListNode<int>Node2 ={ 2,nullptr }; + ListNode<int>Node3 ={ 3,nullptr }; + ListNode<int>Node4 ={ 4,nullptr }; + ListNode<int>Node5 = { 5, nullptr }; + + + 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<int>* TraverseNode = LinkedList._head; + + for (auto i = 1; i <= 5; i++) + { + Assert::AreEqual(i, TraverseNode->_data); + TraverseNode = TraverseNode->_next; + } + + } + + TEST_METHOD(One_Append_Clear_LinkedList_Success) + { + struct SinglyLinkedList<int> LinkedList = {}; + ListNode<int>Node1 = { 1,nullptr }; + + bool success = Append(&LinkedList, &Node1); + + Clear(&LinkedList); + + Assert::AreEqual(0ull, LinkedList._size); + Assert::IsNull(LinkedList._head); + + } + + + TEST_METHOD(Multiple_Append_Clear_LinkedList_Success) + { + struct SinglyLinkedList<int> LinkedList = {}; + ListNode<int>Node1 = { 1,nullptr }; + ListNode<int>Node2 = { 2,nullptr }; + ListNode<int>Node3 = { 3,nullptr }; + ListNode<int>Node4 = { 4,nullptr }; + ListNode<int>Node5 = { 5,nullptr }; + + bool success = Append(&LinkedList, &Node1); + success = Append(&LinkedList, &Node2); + success = Append(&LinkedList, &Node3); + success = Append(&LinkedList, &Node4); + success = Append(&LinkedList, &Node5); + + + Clear(&LinkedList); + + 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); + } + + TEST_METHOD(Insert_After_Single_LinkedList_Success) + { + //Arrange + struct SinglyLinkedList<int> NewList{}; + ListNode<int> Node1 = { 1,nullptr }; + ListNode<int>Node2 = { 2,nullptr }; + ListNode<int>Node3 = { 3,nullptr }; + ListNode<int>Node4 = { 4,nullptr }; + ListNode<int>Node5 = { 5,nullptr }; + //Act + bool Success = Append(&NewList, &Node1); + Success = Append(&NewList, &Node2); + Success = Append(&NewList, &Node3); + Success = Append(&NewList, &Node5); + + InsertAfter(&NewList, 3, &Node4); + + ListNode<int>* TraverseNode = NewList._head; + + for (auto i = 1; i < 5; i++) + { + Assert::AreEqual(i, TraverseNode->_data); + TraverseNode = TraverseNode->_next; + } + } + + TEST_METHOD(Insert_Before_UNO_List) + { + struct SinglyLinkedList<int> NewList{}; + ListNode<int> Node1 = { 1, nullptr }; + ListNode<int> Node2 = { 2, nullptr }; + bool Success = InsertBefore(&NewList, 1, &Node2); + + Assert::AreEqual(2, NewList._head->_data); + } + + TEST_METHOD(Insert_Before_5_List) + { + struct SinglyLinkedList<int> NewList {}; + ListNode<int> Node1 = { 1,nullptr }; + ListNode<int>Node2 = { 2,nullptr }; + ListNode<int>Node3 = { 3,nullptr }; + ListNode<int>Node4 = { 4,nullptr }; + ListNode<int>Node5 = { 5,nullptr }; + + bool Success = Append(&NewList, &Node1); + Success = Append(&NewList, &Node2); + Success = Append(&NewList, &Node3); + Success = Append(&NewList, &Node5); + InsertBefore(&NewList, 5, &Node4); + + ListNode<int>* Traverse = NewList._head; + for (auto i = 1; i < 5; i++) + { + Traverse = Traverse->_next; + } + + Assert::AreEqual(4, Traverse->_data); + } + + TEST_METHOD(DeleteFirstLinkWith0) + { + SinglyLinkedList<int> LinkedList{}; + ListNode<int>* node = new ListNode<int>{}; + bool Success = RemoveFirst(&LinkedList); + Assert::AreEqual(1, static_cast<int>(Success)); + delete node; + } + + TEST_METHOD(Prepend_LinkedList_With_1) + { + struct SinglyLinkedList<int> NewList {}; + ListNode<int> Node1 = { 1,nullptr }; + + Prepend(&NewList, &Node1); + + Assert::AreEqual(1, NewList._head->_data); + Assert::AreEqual(1ull, NewList._size); + } + + TEST_METHOD(Prepend_LinkedList_With_5) + { + struct SinglyLinkedList<int> NewList {}; + ListNode<int> Node1 = { 1,nullptr }; + ListNode<int>Node2 = { 2,nullptr }; + ListNode<int>Node3 = { 3,nullptr }; + ListNode<int>Node4 = { 4,nullptr }; + ListNode<int>Node5 = { 5,nullptr }; + + bool Success = Append(&NewList, &Node2); + Success = Append(&NewList, &Node3); + Success = Append(&NewList, &Node4); + Success = Append(&NewList, &Node5); + + Prepend(&NewList, &Node1); + + Assert::AreEqual(1, NewList._head->_data); + Assert::AreEqual(5ull, NewList._size); + } + + TEST_METHOD(ExtractFirst_LinkedList_Success) + { + struct SinglyLinkedList<int> NewList {}; + ListNode<int> Node1 = { 1,nullptr }; + ListNode<int>Node2 = { 2,nullptr }; + ListNode<int>Node3 = { 3,nullptr }; + ListNode<int>Node4 = { 4,nullptr }; + ListNode<int>Node5 = { 5,nullptr }; + + + bool Success = Append(&NewList, &Node1); + Success = Append(&NewList, &Node2); + Success = Append(&NewList, &Node3); + Success = Append(&NewList, &Node4); + Success = Append(&NewList, &Node5); + + + ListNode<int>* Temp = Extract(&NewList, Node1._data); + ListNode<int>* NullCheck = &Node1; + + Assert::AreEqual(1, Temp->_data); + Assert::IsNull(NullCheck->_next); + + delete Temp; + + } + + TEST_METHOD(Extract_Last_LinkedList_Success) + { + struct SinglyLinkedList<int> NewList {}; + ListNode<int> Node1 = { 1,nullptr }; + ListNode<int>Node2 = { 2,nullptr }; + ListNode<int>Node3 = { 3,nullptr }; + ListNode<int>Node4 = { 4,nullptr }; + ListNode<int>Node5 = { 5,nullptr }; + + bool Success = Append(&NewList, &Node1); + Success = Append(&NewList, &Node2); + Success = Append(&NewList, &Node3); + Success = Append(&NewList, &Node4); + Success = Append(&NewList, &Node5); + + ListNode<int>* Temp = Extract(&NewList, Node5._data); + ListNode<int>* NullCheck = &Node4; + + Assert::AreEqual(5, Temp->_data); + Assert::IsNull(NullCheck->_next); + + delete Temp; + } + + TEST_METHOD(Extract_Middle_LinkedList_Success) + { + struct SinglyLinkedList<int> NewList {}; + ListNode<int> Node1 = { 1,nullptr }; + ListNode<int>Node2 = { 2,nullptr }; + ListNode<int>Node3 = { 3,nullptr }; + ListNode<int>Node4 = { 4,nullptr }; + ListNode<int>Node5 = { 5,nullptr }; + + + + bool Success = Append(&NewList, &Node1); + Success = Append(&NewList, &Node2); + Success = Append(&NewList, &Node3); + Success = Append(&NewList, &Node4); + Success = Append(&NewList, &Node5); + + + ListNode<int>* Temp = Extract(&NewList, Node3._data); + ListNode<int>* NullCheck = &Node3; + + Assert::AreEqual(3, Temp->_data); + Assert::IsNull(Node3._next); + delete Temp; + + } + + + TEST_METHOD(Clear_LinkedList_Full) + { + struct SinglyLinkedList<int> NewList {}; + ListNode<int> Node1 = { 1,nullptr }; + ListNode<int>Node2 = { 2,nullptr }; + ListNode<int>Node3 = { 3,nullptr }; + ListNode<int>Node4 = { 4,nullptr }; + ListNode<int>Node5 = { 5,nullptr }; + + + + bool Success = Append(&NewList, &Node1); + Success = Append(&NewList, &Node2); + Success = Append(&NewList, &Node3); + Success = Append(&NewList, &Node4); + Success = Append(&NewList, &Node5); + Clear(&NewList); + + Assert::AreEqual(0ull, NewList._size); + + } + + TEST_METHOD(Clear_LinkedList_Empty) + { + struct SinglyLinkedList<int> NewList {}; + + Clear(&NewList); + + Assert::AreEqual(0ull, NewList._size); + + } + + TEST_METHOD(Clear_LinkedList_1) + { + struct SinglyLinkedList<int> NewList {}; + ListNode<int> Node1 = { 1,nullptr }; + + bool Success = Append(&NewList, &Node1); + + Clear(&NewList); + + Assert::AreEqual(0ull, NewList._size); + + } + }; + + + + + + TEST_CLASS(NodeUnitTests) + { + public: + const CrtCheckMemory Check; + + + TEST_METHOD(NodeConstructor_Success) + { + Node<int>* NewNode = new Node<int>(); + + Assert::IsNotNull(NewNode); + + + delete NewNode; + } + + + + TEST_METHOD(NodeLoadedConstructor_Success) + { + const CrtCheckMemory Check; + + Node<int>* NewNode = new Node<int>(5); + + Assert::IsNotNull(NewNode); + + Assert::AreEqual(5, NewNode->Data()); + + delete NewNode; + } + + + }; + +}; diff --git a/CST 126/UnitTester/UnitTester.vcxproj b/CST 126/UnitTester/UnitTester.vcxproj new file mode 100644 index 0000000..1c29209 --- /dev/null +++ b/CST 126/UnitTester/UnitTester.vcxproj @@ -0,0 +1,175 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <VCProjectVersion>17.0</VCProjectVersion> + <ProjectGuid>{EAE78C46-5B7C-4F8C-A266-B5D4E3A762D1}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <RootNamespace>UnitTester</RootNamespace> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + <ProjectSubType>NativeUnitTestProject</ProjectSubType> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + <UseOfMfc>false</UseOfMfc> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + <UseOfMfc>false</UseOfMfc> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + <UseOfMfc>false</UseOfMfc> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + <UseOfMfc>false</UseOfMfc> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + <IncludePath>C:\Users\rpwar\source\repos\CST126\homework-1-reecepwarner\CST 126\Homework3;$(IncludePath)</IncludePath> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PrecompiledHeader>Use</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <UseFullPaths>true</UseFullPaths> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PrecompiledHeader>Use</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <UseFullPaths>true</UseFullPaths> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <PrecompiledHeader>Use</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <UseFullPaths>true</UseFullPaths> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <PrecompiledHeader>Use</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <UseFullPaths>true</UseFullPaths> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="pch.cpp"> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> + </ClCompile> + <ClCompile Include="UnitTester.cpp" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="crt_check_memory.hpp" /> + <ClInclude Include="pch.h" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/CST 126/UnitTester/UnitTester.vcxproj.filters b/CST 126/UnitTester/UnitTester.vcxproj.filters new file mode 100644 index 0000000..a210b65 --- /dev/null +++ b/CST 126/UnitTester/UnitTester.vcxproj.filters @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> + <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> + </Filter> + <Filter Include="Resource Files"> + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> + <ClCompile Include="UnitTester.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="pch.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <ClInclude Include="pch.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="crt_check_memory.hpp"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/CST 126/UnitTester/crt_check_memory.hpp b/CST 126/UnitTester/crt_check_memory.hpp new file mode 100644 index 0000000..9cb4ab2 --- /dev/null +++ b/CST 126/UnitTester/crt_check_memory.hpp @@ -0,0 +1,40 @@ +#ifndef CRTCHECKMEMORY_H +#define CRTCHECKMEMORY_H + +#include "pch.h" +#include "CppUnitTest.h" +#include "crtdbg.h" + +#define _CRTDBG_MAP_ALLOC + +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace LinkedListUnitTests +{ + struct CrtCheckMemory + { + _CrtMemState state1{}; + _CrtMemState state2{}; + _CrtMemState state3{}; + CrtCheckMemory() + { + _CrtMemCheckpoint(&state1); + } + + CrtCheckMemory(const CrtCheckMemory& copy) = delete; + CrtCheckMemory& operator=(const CrtCheckMemory& copy) = delete; + CrtCheckMemory(CrtCheckMemory&& copy) = delete; + CrtCheckMemory& operator=(CrtCheckMemory&& copy) = delete; + + ~CrtCheckMemory() + { + _CrtMemCheckpoint(&state2); + + if (_CrtMemDifference(&state3, &state1, &state2) != 0) + { + Assert::Fail(L"Detected memory leaks!"); + } + } + }; +} +#endif
\ No newline at end of file diff --git a/CST 126/UnitTester/pch.cpp b/CST 126/UnitTester/pch.cpp new file mode 100644 index 0000000..64b7eef --- /dev/null +++ b/CST 126/UnitTester/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/UnitTester/pch.h b/CST 126/UnitTester/pch.h new file mode 100644 index 0000000..9d715b0 --- /dev/null +++ b/CST 126/UnitTester/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 |