Repository navigation
Expand file tree
/
Copy pathsets_test.go
More file actions
129 lines (106 loc) · 3.26 KB
/
Copy pathsets_test.go
File metadata and controls
129 lines (106 loc) · 3.26 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright 2026 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package h3
import "testing"
// TestSetH3IndexValue checks that setH3Index assembles the expected index.
func TestSetH3IndexValue(t *testing.T) {
t.Parallel()
h := setH3Index(5, 12, 1)
if h.Resolution() != 5 {
t.Fatalf("resolution = %d, want 5", h.Resolution())
}
if h.BaseCellNumber() != 12 {
t.Fatalf("base cell = %d, want 12", h.BaseCellNumber())
}
if modeOf(h) != cellMode {
t.Fatalf("mode = %d, want %d", modeOf(h), cellMode)
}
for r := 1; r <= 5; r++ {
if indexDigit(h, r) != 1 {
t.Fatalf("digit %d = %d, want 1", r, indexDigit(h, r))
}
}
for r := 6; r <= MaxResolution; r++ {
if indexDigit(h, r) != numDigits {
t.Fatalf("digit %d = %d, want %d", r, indexDigit(h, r), numDigits)
}
}
if uint64(h) != 0x85184927fffffff {
t.Fatalf("index = %015x, want %015x", uint64(h), 0x85184927fffffff)
}
}
// TestRes0Cells checks that Res0Cells returns every base cell as a valid res-0
// index.
func TestRes0Cells(t *testing.T) {
t.Parallel()
cells, err := Res0Cells()
if err != nil {
t.Fatalf("Res0Cells: %v", err)
}
if len(cells) != NumBaseCells {
t.Fatalf("Res0Cells: got %d cells, want %d", len(cells), NumBaseCells)
}
for _, c := range cells {
if !c.IsValid() || c.Resolution() != 0 {
t.Fatalf("Res0Cells: %015x is not a valid res-0 cell", uint64(c))
}
}
// testBaseCells.c getRes0Cells regression: the first and last base cells.
if cells[0] != 0x8001fffffffffff {
t.Fatalf("first base cell: got %015x, want 8001fffffffffff", uint64(cells[0]))
}
if cells[121] != 0x80f3fffffffffff {
t.Fatalf("last base cell: got %015x, want 80f3fffffffffff", uint64(cells[121]))
}
}
// TestPentagons checks that Pentagons returns the 12 pentagons at each
// resolution.
func TestPentagons(t *testing.T) {
t.Parallel()
for res := 0; res <= MaxResolution; res++ {
pents, err := Pentagons(res)
if err != nil {
t.Fatalf("Pentagons(%d): %v", res, err)
}
if len(pents) != NumPentagons {
t.Fatalf("Pentagons(%d): got %d, want %d", res, len(pents), NumPentagons)
}
for _, p := range pents {
if !p.IsPentagon() || p.Resolution() != res {
t.Fatalf("Pentagons(%d): %015x is not a valid pentagon", res, uint64(p))
}
}
}
}
// TestPentagonsInvalid checks that Pentagons rejects out-of-range resolutions.
func TestPentagonsInvalid(t *testing.T) {
t.Parallel()
tests := map[string]struct {
giveRes int
}{
"too_high_resolution": {giveRes: 16},
"absurd_resolution": {giveRes: 100},
"negative_resolution": {giveRes: -1},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()
if _, err := Pentagons(tt.giveRes); err == nil {
t.Fatalf("Pentagons(%d): expected error", tt.giveRes)
}
})
}
}