-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommonTest.cpp
97 lines (71 loc) · 2.64 KB
/
CommonTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "gtest/gtest.h"
#include "Common.hpp"
#include <algorithm>
#include <vector>
#include "BasicGeometry.hpp"
namespace geoIndex {
TEST(IndexAndGeometry, SortByGeometry) {
const IndexAndGeometry<Point> first{4, 1.0}; // Index intentionally out of order, to ensure sorting is on distance.
const IndexAndGeometry<Point> second{56, 2.0};
const IndexAndGeometry<Point> third{2, 3.0};
std::vector<IndexAndGeometry<Point> > pointsToSort;
pointsToSort.push_back(third);
pointsToSort.push_back(second);
pointsToSort.push_back(first);
std::sort(begin(pointsToSort), end(pointsToSort), SortByGeometry<Point>);
ASSERT_EQ(4, pointsToSort.at(0).pointIndex);
ASSERT_EQ(56, pointsToSort.at(1).pointIndex);
ASSERT_EQ(2, pointsToSort.at(2).pointIndex);
}
TEST(IndexAndGeometry, SortByPointIndex) {
const IndexAndGeometry<Point> first{4, 10000.0}; // Geometry intentionally out of order, to ensure sorting is on distance.
const IndexAndGeometry<Point> second{56, 2.0};
const IndexAndGeometry<Point> third{200, -3.0};
std::vector<IndexAndGeometry<Point> > pointsToSort;
pointsToSort.push_back(third);
pointsToSort.push_back(second);
pointsToSort.push_back(first);
std::sort(begin(pointsToSort), end(pointsToSort), SortByPointIndex<Point>);
ASSERT_EQ(4, pointsToSort.at(0).pointIndex);
ASSERT_EQ(56, pointsToSort.at(1).pointIndex);
ASSERT_EQ(200, pointsToSort.at(2).pointIndex);
}
#ifdef GEO_INDEX_SAFETY_CHECKS
TEST(CheckOverflow, NoOverflow) {
ASSERT_NO_THROW(CheckOverflow<double>(29));
}
TEST(CheckOverflow, Overflow) {
ASSERT_ANY_THROW(CheckOverflow<double>(1.0 / 0.0));
}
TEST(CheckMeaningfulDistance, correct) {
ASSERT_NO_THROW(CheckMeaningfulDistance<float>(29));
}
TEST(CheckMeaningfulDistance, notADistance) {
ASSERT_ANY_THROW(CheckMeaningfulDistance<float>(-29));
}
TEST(CheckMeaningfulDistance, insane) {
ASSERT_ANY_THROW(CheckMeaningfulDistance<float>(0.0 / 0.0));
}
TEST(CheckMeaningfulDistance, unlimited) {
ASSERT_ANY_THROW(CheckMeaningfulDistance<float>(1.0 / 0.0));
}
TEST(StopSumOverflow, NoOverflow) {
ASSERT_NO_THROW(StopSumOverflow<int>(1, 1));
}
TEST(StopSumOverflow, YesOverflow) {
ASSERT_ANY_THROW(StopSumOverflow<uint8_t>(254, 10));
}
TEST(StopSumOverflow, Negatives) {
ASSERT_NO_THROW(StopSumOverflow<int8_t>(127, -1));
}
TEST(StopDifferenceUnderflow, Ok) {
ASSERT_NO_THROW(StopDifferenceUnderflow<int>(1, 1));
}
TEST(StopDifferenceUnderflow, BelowMin) {
ASSERT_ANY_THROW(StopDifferenceUnderflow<uint8_t>(10, 11));
}
TEST(StopDifferenceUnderflow, Negatives) {
ASSERT_NO_THROW(StopDifferenceUnderflow<int8_t>(1, -2));
}
#endif
}