-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for DynamicArray, DoubleLinkedList, MaxHeap
- Loading branch information
Showing
9 changed files
with
185 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
project(tests) | ||
add_subdirectory(googletest-1.13.0) | ||
|
||
add_executable(test_run DynamicArrayTests.cpp) | ||
add_executable(test_run DynamicArrayTests.cpp DoubleLinkedListTest.cpp MaxHeapTest.cpp) | ||
target_link_libraries(test_run SDIZO_PROJ_1) | ||
target_link_libraries(test_run gtest gtest_main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include "gtest/gtest.h" | ||
#include "double_linked_list/DoubleLinkedList.h" | ||
|
||
|
||
class DoubleLinkedListTest : public ::testing::Test { | ||
|
||
}; | ||
|
||
TEST_F(DoubleLinkedListTest, PushAndPop) { | ||
DoubleLinkedList list; | ||
list.push(1); | ||
list.push(2); | ||
list.push(3); | ||
|
||
ASSERT_EQ(list.pop(), 3); | ||
ASSERT_EQ(list.pop(), 2); | ||
ASSERT_EQ(list.pop(), 1); | ||
} | ||
|
||
TEST_F(DoubleLinkedListTest, UnshiftAndShift) { | ||
DoubleLinkedList list; | ||
list.unshift(1); | ||
list.unshift(2); | ||
list.unshift(3); | ||
|
||
ASSERT_EQ(list.shift(), 3); | ||
ASSERT_EQ(list.shift(), 2); | ||
ASSERT_EQ(list.shift(), 1); | ||
} | ||
|
||
TEST_F(DoubleLinkedListTest, AddAtAndRemoveAt) { | ||
DoubleLinkedList list; | ||
list.addAt(0, 1); | ||
list.addAt(1, 3); | ||
list.addAt(1, 2); | ||
|
||
ASSERT_EQ(list.removeAt(1), 2); | ||
ASSERT_EQ(list.removeAt(1), 3); | ||
ASSERT_EQ(list.removeAt(0), 1); | ||
} | ||
|
||
TEST_F(DoubleLinkedListTest, Get) { | ||
DoubleLinkedList list; | ||
list.push(1); | ||
list.push(2); | ||
list.push(3); | ||
|
||
ASSERT_EQ(list.get(0), 1); | ||
ASSERT_EQ(list.get(1), 2); | ||
ASSERT_EQ(list.get(2), 3); | ||
} | ||
|
||
TEST_F(DoubleLinkedListTest, ListEmptyException) { | ||
DoubleLinkedList list; | ||
|
||
ASSERT_THROW(list.pop(), std::logic_error); | ||
ASSERT_THROW(list.shift(), std::invalid_argument); | ||
} | ||
|
||
TEST_F(DoubleLinkedListTest, IndexOutOfBoundsException) { | ||
DoubleLinkedList list; | ||
list.push(1); | ||
list.push(2); | ||
list.push(3); | ||
|
||
ASSERT_THROW(list.get(3), std::invalid_argument); | ||
ASSERT_THROW(list.addAt(4, 4), std::invalid_argument); | ||
ASSERT_THROW(list.removeAt(3), std::invalid_argument); | ||
} | ||
|
||
TEST_F(DoubleLinkedListTest, PrintListAndPrintReversed) { | ||
DoubleLinkedList list; | ||
list.push(1); | ||
list.push(2); | ||
list.push(3); | ||
|
||
testing::internal::CaptureStdout(); | ||
list.printList(); | ||
std::string output = testing::internal::GetCapturedStdout(); | ||
ASSERT_EQ(output, "1 2 3 \n"); | ||
|
||
testing::internal::CaptureStdout(); | ||
list.printReversed(); | ||
output = testing::internal::GetCapturedStdout(); | ||
ASSERT_EQ(output, "3 2 1 \n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "gtest/gtest.h" | ||
#include "heap/MaxHeap.h" | ||
|
||
class MaxHeapTest : public ::testing::Test { | ||
|
||
}; | ||
|
||
TEST_F(MaxHeapTest, EmptyHeap) { | ||
MaxHeap heap; | ||
ASSERT_THROW(heap.removeMax(), std::logic_error); | ||
ASSERT_EQ(heap.getSize(), 0); | ||
} | ||
|
||
TEST_F(MaxHeapTest, InsertAndRemoveMax) { | ||
MaxHeap heap; | ||
heap.insert(3); | ||
ASSERT_EQ(heap.getMax(), 3); | ||
heap.insert(5); | ||
ASSERT_EQ(heap.getMax(), 5); | ||
heap.insert(1); | ||
ASSERT_EQ(heap.getMax(), 5); | ||
ASSERT_EQ(heap.removeMax(), 5); | ||
ASSERT_EQ(heap.getMax(), 3); | ||
} | ||
|
||
TEST_F(MaxHeapTest, HeapifyArray) { | ||
int n = 7; | ||
int *inputArray = new int[n]{1, 2, 3, 4, 5, 6, 7}; | ||
MaxHeap heap(inputArray, n); | ||
|
||
ASSERT_EQ(heap.getMax(), 7); | ||
ASSERT_EQ(heap.removeMax(), 7); | ||
ASSERT_EQ(heap.getMax(), 6); | ||
} | ||
|
||
TEST_F(MaxHeapTest, HeapifyArrayAndInsert) { | ||
int n = 7; | ||
int *inputArray = new int[n]{1, 2, 3, 4, 5, 6, 7}; | ||
MaxHeap heap(inputArray, n); | ||
ASSERT_EQ(heap.getMax(), 7); | ||
ASSERT_EQ(heap.removeMax(), 7); | ||
ASSERT_EQ(heap.getMax(), 6); | ||
|
||
heap.insert(8); | ||
ASSERT_EQ(heap.getMax(), 8); | ||
ASSERT_EQ(heap.removeMax(), 8); | ||
ASSERT_EQ(heap.getMax(), 6); | ||
} | ||
|
||
TEST_F(MaxHeapTest, ReallocationAndSize) { | ||
MaxHeap heap; | ||
heap.insert(1); | ||
heap.insert(2); | ||
heap.insert(3); | ||
heap.insert(4); | ||
heap.insert(5); | ||
ASSERT_EQ(heap.getSize(), 5); | ||
ASSERT_EQ(heap.getMax(), 5); | ||
ASSERT_EQ(heap.removeMax(), 5); | ||
ASSERT_EQ(heap.getSize(), 4); | ||
ASSERT_EQ(heap.removeMax(), 4); | ||
ASSERT_EQ(heap.getSize(), 3); | ||
} | ||
|
||
|