aboutsummaryrefslogtreecommitdiff
path: root/CST 126/LinkedListUnitTests
diff options
context:
space:
mode:
authorWesleyR <[email protected]>2024-06-09 23:09:50 -0700
committerWesleyR <[email protected]>2024-06-09 23:09:50 -0700
commitcb041a37b810a5dfa04c1c7f4315f9c3bbc8df0c (patch)
tree61b0d3d555e1596b5156e2d18e015497b438c2e4 /CST 126/LinkedListUnitTests
parentUpdating before template node branch (diff)
downloadhomework-1-wesleyr23-Template_Node.tar.xz
homework-1-wesleyr23-Template_Node.zip
Submission for HW 3, In-Class Exercise 3, and In-Class Exercise 4HEADdevelopTemplate_Node
Diffstat (limited to 'CST 126/LinkedListUnitTests')
-rw-r--r--CST 126/LinkedListUnitTests/LinkedListUnitTests.cpp25
-rw-r--r--CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj2
-rw-r--r--CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj.filters6
-rw-r--r--CST 126/LinkedListUnitTests/NodeUnitTests.cpp37
-rw-r--r--CST 126/LinkedListUnitTests/crt_check_memory.hpp40
5 files changed, 109 insertions, 1 deletions
diff --git a/CST 126/LinkedListUnitTests/LinkedListUnitTests.cpp b/CST 126/LinkedListUnitTests/LinkedListUnitTests.cpp
index 15defc0..a58290e 100644
--- a/CST 126/LinkedListUnitTests/LinkedListUnitTests.cpp
+++ b/CST 126/LinkedListUnitTests/LinkedListUnitTests.cpp
@@ -1,11 +1,14 @@
+
#include "pch.h"
#include "CppUnitTest.h"
-
#include <list>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
#include "SinglyLinkedList.hpp";
+#include "crt_check_memory.hpp";
+
+#pragma once
namespace LinkedListUnitTests
{
@@ -17,6 +20,7 @@ namespace LinkedListUnitTests
//Empty
TEST_METHOD(EmptyListHasZeroSize)
{
+ const CrtCheckMemory check;
//Arrange
SinglyLinkedList linkedList{};
@@ -27,6 +31,7 @@ namespace LinkedListUnitTests
//Append
TEST_METHOD(AppendingLinkedList)
{
+ const CrtCheckMemory check;
//Arrange
struct SinglyLinkedList linkedList = {};
@@ -44,6 +49,7 @@ namespace LinkedListUnitTests
TEST_METHOD(MultipleAppend_LinkedList_Success)
{
+ const CrtCheckMemory check;
//Arrange
struct SinglyLinkedList linkedList = {};
@@ -76,6 +82,7 @@ namespace LinkedListUnitTests
//Prepend
TEST_METHOD(OnePrependLinkedList)
{
+ const CrtCheckMemory check;
//Arrange
struct SinglyLinkedList linkedList = {};
@@ -93,6 +100,7 @@ namespace LinkedListUnitTests
TEST_METHOD(MultiplePrepend_LinkedList_Success)
{
+ const CrtCheckMemory check;
//Arrange
struct SinglyLinkedList linkedList = {};
@@ -125,6 +133,7 @@ namespace LinkedListUnitTests
//RemoveFirst
TEST_METHOD(RemoveFirstNode_LinkedList_Success)
{
+ const CrtCheckMemory check;
struct SinglyLinkedList linkedList = {};
ListNode node1 = { 1, nullptr };
@@ -154,6 +163,7 @@ namespace LinkedListUnitTests
TEST_METHOD(RemoveFirstNodeWithOneNode_LinkedList_Success)
{
+ const CrtCheckMemory check;
struct SinglyLinkedList linkedList = {};
ListNode node1 = { 1, nullptr };
@@ -169,6 +179,7 @@ namespace LinkedListUnitTests
//RemoveLast
TEST_METHOD(RemoveLastNode_LinkedList_Success)
{
+ const CrtCheckMemory check;
struct SinglyLinkedList linkedList = {};
ListNode node1 = { 1, nullptr };
@@ -198,6 +209,7 @@ namespace LinkedListUnitTests
TEST_METHOD(RemoveLastNodeWithOneNode_LinkedList_Success)
{
+ const CrtCheckMemory check;
struct SinglyLinkedList linkedList = {};
ListNode node1 = { 1, nullptr };
@@ -213,6 +225,7 @@ namespace LinkedListUnitTests
//InsertAfter
TEST_METHOD(Single_InserterAfter_LinkedList_Success)
{
+ const CrtCheckMemory check;
//Arrange
struct SinglyLinkedList newList = {};
//Append Nodes
@@ -245,6 +258,7 @@ namespace LinkedListUnitTests
TEST_METHOD(Single_InserterAfterEnd_LinkedList_Success)
{
+ const CrtCheckMemory check;
//Arrange
struct SinglyLinkedList newList = {};
//Append Nodes
@@ -278,6 +292,7 @@ namespace LinkedListUnitTests
//InsertBefore
TEST_METHOD(Single_InserterBefore_LinkedList_Success)
{
+ const CrtCheckMemory check;
//Arrange
struct SinglyLinkedList newList = {};
//Append Nodes
@@ -310,6 +325,7 @@ namespace LinkedListUnitTests
TEST_METHOD(Single_InserterBeforeHead_LinkedList_Success)
{
+ const CrtCheckMemory check;
//Arrange
struct SinglyLinkedList newList = {};
//Append Nodes
@@ -343,6 +359,7 @@ namespace LinkedListUnitTests
//Clear
TEST_METHOD(OneAppend_Clear_LinkedList_Success)
{
+ const CrtCheckMemory check;
//Arrange
struct SinglyLinkedList linkedList = {};
ListNode node1 = { 1, nullptr };
@@ -359,6 +376,7 @@ namespace LinkedListUnitTests
TEST_METHOD(MultipleAppend_Clear_LinkedList_Success)
{
+ const CrtCheckMemory check;
//Arrange
struct SinglyLinkedList linkedList = {};
@@ -392,6 +410,7 @@ namespace LinkedListUnitTests
//Extract
TEST_METHOD(ExtractFirst_LinkedList_Success)
{
+ const CrtCheckMemory check;
//Arrange
struct SinglyLinkedList newList = {};
//Append Nodes
@@ -422,6 +441,7 @@ namespace LinkedListUnitTests
TEST_METHOD(ExtractLast_LinkedList_Success)
{
+ const CrtCheckMemory check;
//Arrange
struct SinglyLinkedList newList = {};
//Append Nodes
@@ -447,6 +467,7 @@ namespace LinkedListUnitTests
TEST_METHOD(ExtractMiddle_LinkedList_Success)
{
+ const CrtCheckMemory check;
//Arrange
struct SinglyLinkedList newList = {};
//Append Nodes
@@ -473,6 +494,7 @@ namespace LinkedListUnitTests
//Remove
TEST_METHOD(RemoveNode_LinkedList_Success)
{
+ const CrtCheckMemory check;
struct SinglyLinkedList linkedList = {};
ListNode node1 = { 1, nullptr };
@@ -503,6 +525,7 @@ namespace LinkedListUnitTests
}
TEST_METHOD(RemoveNodeWithOneNode_Linked_List_Success) {
+ const CrtCheckMemory check;
struct SinglyLinkedList linkedList = {};
ListNode node1 = { 1, nullptr };
diff --git a/CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj b/CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj
index 25b18fa..f4504d5 100644
--- a/CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj
+++ b/CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj
@@ -158,6 +158,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="LinkedListUnitTests.cpp" />
+ <ClCompile Include="NodeUnitTests.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
@@ -166,6 +167,7 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
+ <ClInclude Include="crt_check_memory.hpp" />
<ClInclude Include="pch.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
diff --git a/CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj.filters b/CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj.filters
index ed7bc9d..2f1732f 100644
--- a/CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj.filters
+++ b/CST 126/LinkedListUnitTests/LinkedListUnitTests.vcxproj.filters
@@ -21,10 +21,16 @@
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="NodeUnitTests.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/LinkedListUnitTests/NodeUnitTests.cpp b/CST 126/LinkedListUnitTests/NodeUnitTests.cpp
new file mode 100644
index 0000000..39228ed
--- /dev/null
+++ b/CST 126/LinkedListUnitTests/NodeUnitTests.cpp
@@ -0,0 +1,37 @@
+#include "pch.h"
+#include "CppUnitTest.h"
+
+#include <list>
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
+#include "crt_check_memory.hpp"
+#include "node.hpp";
+
+using namespace CST126;
+
+namespace LinkedListUnitTests
+{
+ TEST_CLASS(NodeUnitTests)
+ {
+ public:
+
+ //Empty
+ TEST_METHOD(NodeEmptyConstructor_Success)
+ {
+ const CrtCheckMemory check;
+ //Arrange
+ Node<int>* newNode = new Node<int>(5);
+
+
+ //Act
+
+
+ //Assert
+ Assert::IsNotNull(newNode);
+ Assert::AreEqual(5, newNode->Data());
+
+ delete newNode;
+ }
+ };
+} \ No newline at end of file
diff --git a/CST 126/LinkedListUnitTests/crt_check_memory.hpp b/CST 126/LinkedListUnitTests/crt_check_memory.hpp
new file mode 100644
index 0000000..9cb4ab2
--- /dev/null
+++ b/CST 126/LinkedListUnitTests/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