Skip to content

Commit ae0792c

Browse files
committed
added last tests, removed Makefile
1 parent ca91057 commit ae0792c

File tree

6 files changed

+78
-125
lines changed

6 files changed

+78
-125
lines changed

Makefile

-27
This file was deleted.

TestTreeList.cpp

-67
This file was deleted.

tests/CMakeLists.txt

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
set (CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -std=c++11")
2+
13
add_executable(
24
basics
35
basics.cpp
@@ -30,8 +32,30 @@ target_link_libraries(
3032
GTest::gmock_main
3133
)
3234

35+
add_executable(
36+
largeData
37+
largeData.cpp
38+
)
39+
target_link_libraries(
40+
largeData
41+
GTest::gtest_main
42+
GTest::gmock_main
43+
)
44+
45+
add_executable(
46+
treeList
47+
treeList.cpp
48+
)
49+
target_link_libraries(
50+
treeList
51+
GTest::gtest_main
52+
GTest::gmock_main
53+
)
54+
3355
include(GoogleTest)
3456
gtest_discover_tests(basics)
3557
gtest_discover_tests(memory)
3658
gtest_discover_tests(badData)
59+
gtest_discover_tests(largeData)
60+
gtest_discover_tests(treeList)
3761

tests/basics.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ TEST(BasicTests, BasicTests) {
4949
ASSERT_EQ(nhits, 2);
5050

5151
std::vector<Rect> collectedRects = std::vector<Rect>();
52+
std::vector<ValueType> collectedValues = std::vector<ValueType>();
5253

5354
// Iterator test
54-
int itIndex = 0;
5555
MyTree::Iterator it;
5656
for (tree.GetFirst(it); !tree.IsNull(it); tree.GetNext(it)) {
5757
int value = tree.GetAt(it);
@@ -61,14 +61,15 @@ TEST(BasicTests, BasicTests) {
6161
it.GetBounds(boundsMin, boundsMax);
6262
collectedRects.push_back(
6363
Rect(boundsMin[0], boundsMin[1], boundsMax[0], boundsMax[1]));
64+
collectedValues.push_back(value);
6465
}
6566

6667
EXPECT_THAT(rects, UnorderedElementsAreArray(collectedRects));
68+
EXPECT_THAT(values, UnorderedElementsAreArray(collectedValues));
69+
collectedValues.clear();
6770

68-
std::vector<ValueType> collectedValues = std::vector<ValueType>();
6971

7072
// Iterator test, alternate syntax
71-
itIndex = 0;
7273
tree.GetFirst(it);
7374
while (!it.IsNull()) {
7475
int value = *it;
@@ -82,9 +83,9 @@ TEST(BasicTests, BasicTests) {
8283
MyTree copy = tree;
8384

8485
collectedRects.clear();
86+
collectedValues.clear();
8587

8688
// Iterator test
87-
itIndex = 0;
8889
for (copy.GetFirst(it); !copy.IsNull(it); copy.GetNext(it)) {
8990
int value = copy.GetAt(it);
9091

@@ -93,14 +94,15 @@ TEST(BasicTests, BasicTests) {
9394
it.GetBounds(boundsMin, boundsMax);
9495
collectedRects.push_back(
9596
Rect(boundsMin[0], boundsMin[1], boundsMax[0], boundsMax[1]));
97+
collectedValues.push_back(value);
9698
}
99+
EXPECT_THAT(values, UnorderedElementsAreArray(collectedValues));
97100

98101
EXPECT_THAT(rects, UnorderedElementsAreArray(collectedRects));
99102

100103
collectedValues.clear();
101104

102105
// Iterator test, alternate syntax
103-
itIndex = 0;
104106
copy.GetFirst(it);
105107
while (!it.IsNull()) {
106108
int value = *it;
+11-26
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
1-
//
2-
// TestLargeData.cpp
3-
//
1+
#include "../RTree.h"
2+
#include "util.hpp"
3+
#include <gmock/gmock.h>
4+
#include <gtest/gtest-matchers.h>
5+
#include <gtest/gtest.h>
46

5-
#include "RTree.h"
7+
using namespace ::testing;
68

7-
struct Rect
8-
{
9-
Rect() {}
10-
11-
Rect(float a_minX, float a_minY, float a_maxX, float a_maxY)
12-
{
13-
min[0] = a_minX;
14-
min[1] = a_minY;
15-
16-
max[0] = a_maxX;
17-
max[1] = a_maxY;
18-
}
9+
typedef RectTemplate<float> Rect;
1910

20-
21-
float min[2];
22-
float max[2];
23-
};
24-
25-
struct Rect rects1[] =
11+
Rect rects1[] =
2612
{
2713
Rect(-165504234584830402149438989055033344.0f,0,0,0),
2814
Rect(0,0,0,0),
@@ -35,7 +21,7 @@ struct Rect rects1[] =
3521
Rect(-169908473233881734291078144928254001152.0f,0,0,-148873525386705775939391178777772949504.0f),
3622
};
3723

38-
struct Rect rects2[] =
24+
Rect rects2[] =
3925
{
4026
Rect(-0.000487f,311158685411645789022377876652032.0f,0,0),
4127
Rect(-151115727451828646838272.0f,0,0,0),
@@ -48,8 +34,7 @@ struct Rect rects2[] =
4834
Rect(-0.453835f,303590248839277909200780151226368.0f,12.07855f,0),
4935
};
5036

51-
int main()
52-
{
37+
TEST(LargeData, LargeData) {
5338
RTree<int, float, 2> tree;
5439

5540
int data = 0;
@@ -60,5 +45,5 @@ int main()
6045
tree.Insert(rect.min, rect.max, data++);
6146
}
6247

63-
return 0;
48+
SUCCEED();
6449
}

tests/treeList.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "../RTree.h"
2+
#include "util.hpp"
3+
#include <gmock/gmock.h>
4+
#include <gtest/gtest-matchers.h>
5+
#include <gtest/gtest.h>
6+
#include <iostream>
7+
#include <limits>
8+
9+
using namespace ::testing;
10+
11+
typedef int ValueType;
12+
13+
typedef RectTemplate<int> Rect;
14+
15+
Rect rects[] = {
16+
Rect(0, 0, 0, 0), Rect(1, 1, 1, 1), Rect(2, 2, 2, 2), Rect(3, 3, 3, 3),
17+
Rect(4, 4, 4, 4), Rect(5, 5, 5, 5), Rect(6, 6, 6, 6), Rect(7, 7, 7, 7),
18+
Rect(8, 8, 8, 8), Rect(9, 9, 9, 9),
19+
};
20+
21+
int nrects = sizeof(rects) / sizeof(rects[0]);
22+
23+
TEST(TreeList, TreeList) {
24+
typedef RTree<ValueType, int, 2, float, 4> MyTree;
25+
MyTree tree;
26+
27+
for (int i = 0; i < nrects; i++) {
28+
tree.Insert(rects[i].min, rects[i].max, i);
29+
}
30+
31+
auto list = tree.ListTree();
32+
33+
// there are at least nrects internal rectangles, because we use at most 4
34+
// items per node
35+
EXPECT_GT(list.size(), nrects);
36+
}

0 commit comments

Comments
 (0)