-
Notifications
You must be signed in to change notification settings - Fork 523
Expand file tree
/
Copy pathcodearea_test.cc
More file actions
59 lines (53 loc) · 2.14 KB
/
codearea_test.cc
File metadata and controls
59 lines (53 loc) · 2.14 KB
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
#include "codearea.h"
#include "gtest/gtest.h"
namespace openlocationcode {
namespace {
TEST(CodeAreaChecks, Accessors) {
const CodeArea area(1.0, 2.0, 3.0, 4.0, 6);
// Check accessor methods return what we expect.
EXPECT_EQ(area.GetLatitudeLo(), 1.0);
EXPECT_EQ(area.GetLongitudeLo(), 2.0);
EXPECT_EQ(area.GetLatitudeHi(), 3.0);
EXPECT_EQ(area.GetLongitudeHi(), 4.0);
EXPECT_EQ(area.GetCodeLength(), 6);
}
TEST(CodeAreaChecks, GetCenter) {
// Simple case.
const CodeArea area1(0.0, 0.0, 1.0, 2.0, 8);
EXPECT_EQ(area1.GetCenter().latitude, 0.5);
EXPECT_EQ(area1.GetCenter().longitude, 1.0);
// Negative latitudes & longitudes.
const CodeArea area2(-10.0, -30.0, -24.0, -84.0, 4);
EXPECT_EQ(area2.GetCenter().latitude, -17.0);
EXPECT_EQ(area2.GetCenter().longitude, -57.0);
// Latitude & longitude ranges crossing zero.
const CodeArea area3(-30.0, -17.0, 5.0, 21.0, 4);
EXPECT_EQ(area3.GetCenter().latitude, -12.5);
EXPECT_EQ(area3.GetCenter().longitude, 2.0);
// Zero-sized area (not strictly valid, but center is still well-defined).
const CodeArea area4(-65.0, 117.0, -65.0, 117.0, 2);
EXPECT_EQ(area4.GetCenter().latitude, -65.0);
EXPECT_EQ(area4.GetCenter().longitude, 117.0);
}
TEST(CodeAreaChecks, IsValid) {
// All zeroes: invalid.
EXPECT_FALSE(CodeArea(0.0, 0.0, 0.0, 0.0, 0).IsValid());
// Whole-world area: valid.
EXPECT_TRUE(CodeArea(-90.0, -180.0, 90.0, 180.0, 1).IsValid());
// Typical area: valid.
EXPECT_TRUE(CodeArea(-1.0, -1.0, 1.0, 1.0, 10).IsValid());
// Zero code length: invalid.
EXPECT_FALSE(CodeArea(-1.0, -1.0, 1.0, 1.0, 0).IsValid());
// Low latitude >= high latitude: invalid.
EXPECT_FALSE(CodeArea(1.0, -1.0, 1.0, 1.0, 10).IsValid());
EXPECT_FALSE(CodeArea(2.0, -1.0, 1.0, 1.0, 10).IsValid());
// Low longitude >= high longitude: invalid.
EXPECT_FALSE(CodeArea(-1.0, 1.0, 1.0, 1.0, 10).IsValid());
EXPECT_FALSE(CodeArea(-1.0, 2.0, 1.0, 1.0, 10).IsValid());
}
TEST(CodeAreaChecks, InvalidCodeArea) {
// CodeArea::InvalideCodeArea() must return an invalid code area, obviously.
EXPECT_FALSE(CodeArea::InvalidCodeArea().IsValid());
}
} // namespace
} // namespace openlocationcode