Skip to content

Commit dce0a8f

Browse files
committed
added tests
1 parent 4f24d54 commit dce0a8f

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# BUILD FOLDER
2-
/build
2+
/build
3+
4+
# LINE COUNT FILE
5+
line-count.txt

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ ctest --preset default
3535
```bash
3636

3737
# GET LINE COUNT (REQUIRES CLOC TO BE INSTALLED)
38-
cloc --include-lang=C++,"C/C++ Header",CMake --exclude-dir=build,vcpkg .
38+
cloc --include-lang=C++,"C/C++ Header",CMake --exclude-dir=build,vcpkg --out=line-count.txt .
3939

4040
```
4141

4242
| Language | Files | Blank | Comment | Code |
4343
|:-----------------|:-----:|:-----:|:-------:|:----:|
44-
| **C++** | 15 | 287 | 150 | 890 |
45-
| **C/C++ Header** | 11 | 80 | 1 | 156 |
44+
| **C++** | 17 | 336 | 182 | 1018 |
45+
| **C/C++ Header** | 12 | 92 | 1 | 171 |
4646
| **CMake** | 4 | 24 | 19 | 63 |
4747
| |
48-
| **Total** | 30 | 391 | 170 | 1109 |
48+
| **Total** | 33 | 452 | 202 | 1252 |
4949

5050
</details>

core/include/sorts/QuickSort.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
namespace QuickSort {
1010

11-
rgb_color GetRectangleColor(bool isPivot, bool isSelected);
11+
rgb_color GetRectangleColor(bool isOrdered, bool isPivot, bool isSelected);
1212

1313
int GetPartitionCount(Rectangle* array, int low, int high, int* stepCount);
1414

1515
void GetQuickSortCount(Rectangle* array, int low, int high, int* stepCount);
1616

1717
int GetStepCount(Rectangle* items);
1818

19-
int Partition(Rectangle* array, int low, int high);
19+
int Partition(Rectangle* array, int low, int high, int* currentStep, SortSequence sort);
2020

2121
void QuickSort(Rectangle* array, int low, int high, int* currentStep, SortSequence sort);
2222

test/sorts/QuickSort.cc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <gtest/gtest.h>
2+
#include <SDL3/SDL.h>
3+
4+
#include <TestUtils.hpp>
5+
6+
#include <QuickSort.hpp>
7+
#include <List.hpp>
8+
#include <Rect.hpp>
9+
10+
using namespace QuickSort;
11+
12+
TEST(QuickSort_Test, GetStepCount_GreaterThanOne) {
13+
// ARRANGE
14+
SDL_Renderer* renderer = (SDL_Renderer*) malloc(sizeof(Rectangle));
15+
Rectangle* items = (Rectangle*) malloc(LIST_SIZE * sizeof(Rectangle));
16+
17+
CreateList(renderer, items, WINDOW_WIDTH, WINDOW_HEIGHT);
18+
ShuffleList(items);
19+
20+
// ACT
21+
int stepCount = GetStepCount(items);
22+
23+
// ASSERT
24+
EXPECT_TRUE(stepCount > 1);
25+
}
26+
27+
TEST(QuickSort_Test, GetSequence_CorrectOrder) {
28+
// ARRANGE
29+
SDL_Renderer* renderer = (SDL_Renderer*) malloc(sizeof(Rectangle));
30+
Rectangle* items = (Rectangle*) malloc(LIST_SIZE * sizeof(Rectangle));
31+
32+
CreateList(renderer, items, WINDOW_WIDTH, WINDOW_HEIGHT);
33+
ShuffleList(items);
34+
35+
// ACT
36+
SortSequence sequence = GetSequence(items);
37+
38+
// ASSERT
39+
EXPECT_TRUE(sequence.stepCount > 0);
40+
41+
int lastStep = sequence.stepCount - 1;
42+
int offset;
43+
for (int i = 0; i < LIST_SIZE; i++) {
44+
offset = (lastStep * LIST_SIZE) + i;
45+
EXPECT_EQ(sequence.steps[offset].value, (i + 1));
46+
}
47+
}

0 commit comments

Comments
 (0)