Skip to content

Commit c67e5e6

Browse files
authored
Get test coverage to 100% (#66)
* Rename regions spec. * Add comment to inform why these lines won't ever get executed currently. * Cover missing case for geo json. * Remove deprecated methods.
1 parent 46d1f4b commit c67e5e6

File tree

9 files changed

+11
-171
lines changed

9 files changed

+11
-171
lines changed

lib/h3/hierarchy.rb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ module Hierarchy
1919
# @return [Integer] H3 index of parent hexagon.
2020
attach_function :parent, :h3ToParent, [:h3_index, Resolution], :h3_index
2121

22-
# @deprecated Please use {#parent} instead.
23-
def h3_to_parent(h3_index, resolution)
24-
parent(h3_index, resolution)
25-
end
26-
deprecate :h3_to_parent, :parent, 2020, 1
27-
2822
# @!method max_children(h3_index, child_resolution)
2923
#
3024
# Derive maximum number of child hexagons possible at given resolution.
@@ -54,12 +48,6 @@ def h3_to_parent(h3_index, resolution)
5448
# @return [Integer] H3 index of center child hexagon.
5549
attach_function :center_child, :h3ToCenterChild, [:h3_index, Resolution], :h3_index
5650

57-
# @deprecated Please use {#max_children} instead.
58-
def max_h3_to_children_size(h3_index, resolution)
59-
max_children(h3_index, resolution)
60-
end
61-
deprecate :max_h3_to_children_size, :max_children, 2020, 1
62-
6351
# Derive child hexagons contained within the hexagon at the given H3 index.
6452
#
6553
# @param [Integer] h3_index A valid H3 index.
@@ -80,12 +68,6 @@ def children(h3_index, child_resolution)
8068
out.read
8169
end
8270

83-
# @deprecated Please use {#children} instead.
84-
def h3_to_children(h3_index, resolution)
85-
children(h3_index, resolution)
86-
end
87-
deprecate :h3_to_children, :children, 2020, 1
88-
8971
# Find the maximum uncompacted size of the given set of H3 indexes.
9072
#
9173
# @param [Array<Integer>] compacted_set An array of valid H3 indexes.

lib/h3/indexing.rb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ def from_geo_coordinates(coords, resolution)
3535
Bindings::Private.geo_to_h3(coords, resolution)
3636
end
3737

38-
# @deprecated Please use {#from_geo_coordinates} instead.
39-
def geo_to_h3(coords, resolution)
40-
from_geo_coordinates(coords, resolution)
41-
end
42-
deprecate :geo_to_h3, :from_geo_coordinates, 2020, 1
43-
4438
# Derive coordinates for a given H3 index.
4539
#
4640
# The coordinates map to the centre of the hexagon at the given index.
@@ -58,12 +52,6 @@ def to_geo_coordinates(h3_index)
5852
[rads_to_degs(coords[:lat]), rads_to_degs(coords[:lon])]
5953
end
6054

61-
# @deprecated Please use {#to_geo_coordinates} instead.
62-
def h3_to_geo(h3_index)
63-
to_geo_coordinates(h3_index)
64-
end
65-
deprecate :h3_to_geo, :to_geo_coordinates, 2020, 1
66-
6755
# Derive the geographical boundary as coordinates for a given H3 index.
6856
#
6957
# This will be a set of 6 coordinate pairs matching the vertexes of the
@@ -89,11 +77,5 @@ def to_boundary(h3_index)
8977
[rads_to_degs(d[:lat]), rads_to_degs(d[:lon])]
9078
end
9179
end
92-
93-
# @deprecated Please use {#to_boundary} instead.
94-
def h3_to_geo_boundary(h3_index)
95-
to_boundary(h3_index)
96-
end
97-
deprecate :h3_to_geo_boundary, :to_boundary, 2020, 1
9880
end
9981
end

lib/h3/inspection.rb

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ module Inspection
2121
# @return [Integer] Resolution of H3 index
2222
attach_function :resolution, :h3GetResolution, %i[h3_index], Resolution
2323

24-
# @deprecated Please use {#resolution} instead.
25-
def h3_resolution(h3_index)
26-
resolution(h3_index)
27-
end
28-
deprecate :h3_resolution, :resolution, 2020, 1
29-
3024
# @!method base_cell(h3_index)
3125
#
3226
# Derives the base cell number of the given H3 index
@@ -40,12 +34,6 @@ def h3_resolution(h3_index)
4034
# @return [Integer] Base cell number
4135
attach_function :base_cell, :h3GetBaseCell, %i[h3_index], :int
4236

43-
# @deprecated Please use {#base_cell} instead.
44-
def h3_base_cell(h3_index)
45-
base_cell(h3_index)
46-
end
47-
deprecate :h3_base_cell, :base_cell, 2020, 1
48-
4937
# @!method from_string(h3_string)
5038
#
5139
# Derives the H3 index for a given hexadecimal string representation.
@@ -59,12 +47,6 @@ def h3_base_cell(h3_index)
5947
# @return [Integer] H3 index
6048
attach_function :from_string, :stringToH3, %i[string], :h3_index
6149

62-
# @deprecated Please use {#from_string} instead.
63-
def string_to_h3(string)
64-
from_string(string)
65-
end
66-
deprecate :string_to_h3, :from_string, 2020, 1
67-
6850
# @!method pentagon?(h3_index)
6951
#
7052
# Determine whether the given H3 index is a pentagon.
@@ -78,12 +60,6 @@ def string_to_h3(string)
7860
# @return [Boolean] True if the H3 index is a pentagon.
7961
attach_predicate_function :pentagon?, :h3IsPentagon, %i[h3_index], :bool
8062

81-
# @deprecated Please use {#pentagon?} instead.
82-
def h3_pentagon?(h3_index)
83-
pentagon?(h3_index)
84-
end
85-
deprecate :h3_pentagon?, :pentagon?, 2020, 1
86-
8763
# @!method class_3_resolution?(h3_index)
8864
#
8965
# Determine whether the given H3 index has a resolution with
@@ -98,12 +74,6 @@ def h3_pentagon?(h3_index)
9874
# @return [Boolean] True if the H3 index has a class III resolution.
9975
attach_predicate_function :class_3_resolution?, :h3IsResClassIII, %i[h3_index], :bool
10076

101-
# @deprecated Please use {#class_3_resolution?} instead.
102-
def h3_res_class_3?(h3_index)
103-
class_3_resolution?(h3_index)
104-
end
105-
deprecate :h3_res_class_3?, :class_3_resolution?, 2020, 1
106-
10777
# @!method valid?(h3_index)
10878
#
10979
# Determine whether the given H3 index is valid.
@@ -117,12 +87,6 @@ def h3_res_class_3?(h3_index)
11787
# @return [Boolean] True if the H3 index is valid.
11888
attach_predicate_function :valid?, :h3IsValid, %i[h3_index], :bool
11989

120-
# @deprecated Please use {#valid?} instead.
121-
def h3_valid?(h3_index)
122-
valid?(h3_index)
123-
end
124-
deprecate :h3_valid?, :valid?, 2020, 1
125-
12690
# Derives the hexadecimal string representation for a given H3 index.
12791
#
12892
# @param [Integer] h3_index A valid H3 index.
@@ -138,12 +102,6 @@ def to_string(h3_index)
138102
h3_str.read_string
139103
end
140104

141-
# @deprecated Please use {#to_string} instead.
142-
def h3_to_string(h3_index)
143-
to_string(h3_index)
144-
end
145-
deprecate :h3_to_string, :to_strings, 2020, 1
146-
147105
# @!method max_face_count(h3_index)
148106
#
149107
# Returns the maximum number of icosahedron faces the given H3 index may intersect.
@@ -173,11 +131,5 @@ def faces(h3_index)
173131
# The C function returns a sparse array whose holes are represented by -1.
174132
out.read_array_of_int(max_faces).reject(&:negative?).sort
175133
end
176-
177-
# @deprecated Please use {#faces} instead.
178-
def h3_faces(h3_index)
179-
faces(h3_index)
180-
end
181-
deprecate :h3_faces, :faces, 2020, 1
182134
end
183135
end

lib/h3/miscellaneous.rb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ module Miscellaneous
8383
# @return [Integer] Number of unique hexagons
8484
attach_function :hexagon_count, :numHexagons, [Resolution], :ulong_long
8585

86-
# @deprecated Please use {#hexagon_count} instead.
87-
def num_hexagons(resolution)
88-
hexagon_count(resolution)
89-
end
90-
deprecate :num_hexagons, :hexagon_count, 2020, 1
91-
9286
# @!method rads_to_degs(rads)
9387
#
9488
# Convert a number expressed in radians to its equivalent in degrees.
@@ -125,12 +119,6 @@ def num_hexagons(resolution)
125119
# @return [Integer] The number of pentagons per resolution.
126120
attach_function :pentagon_count, :pentagonIndexCount, [], :int
127121

128-
# @deprecated Please use {#base_cell_count} instead.
129-
def res_0_index_count
130-
base_cell_count
131-
end
132-
deprecate :res_0_index_count, :base_cell_count, 2020, 1
133-
134122
# Returns all resolution 0 hexagons (base cells).
135123
#
136124
# @example Return all base cells.
@@ -156,11 +144,5 @@ def pentagons(resolution)
156144
Bindings::Private.get_pentagon_indexes(resolution, out)
157145
out.read
158146
end
159-
160-
# @deprecated Please use {#base_cells} instead.
161-
def res_0_indexes
162-
base_cells
163-
end
164-
deprecate :res_0_indexes, :base_cells, 2020, 1
165147
end
166148
end

lib/h3/regions.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def h3_set_to_linked_geo(h3_indexes)
141141
linked_geo_polygon = LinkedGeoPolygon.new
142142
Bindings::Private.h3_set_to_linked_geo(h3_set, h3_indexes.size, linked_geo_polygon)
143143

144+
# The algorithm in h3 currently only handles 1 polygon
144145
extract_linked_geo_polygon(linked_geo_polygon).first
145146
ensure
146147
Bindings::Private.destroy_linked_polygon(linked_geo_polygon)
@@ -154,6 +155,8 @@ def extract_linked_geo_polygon(linked_geo_polygon)
154155
geo_polygons = [linked_geo_polygon]
155156

156157
until linked_geo_polygon[:next].null?
158+
# Until the h3 algorithm is updated to handle multiple polygons,
159+
# this block will never run.
157160
geo_polygons << linked_geo_polygon[:next]
158161
linked_geo_polygon = linked_geo_polygon[:next]
159162
end

lib/h3/traversal.rb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ module Traversal
3232
# @return [Integer] Distance between indexes.
3333
attach_function :distance, :h3Distance, %i[h3_index h3_index], :k_distance
3434

35-
# @deprecated Please use {#distance} instead.
36-
def h3_distance(origin, destination)
37-
distance(origin, destination)
38-
end
39-
deprecate :h3_distance, :distance, 2020, 1
40-
4135
# @!method line_size(origin, destination)
4236
#
4337
# Derive the number of hexagons present in a line between two H3 indexes.
@@ -57,12 +51,6 @@ def h3_distance(origin, destination)
5751
# @return [Integer] Number of hexagons found between indexes.
5852
attach_function :line_size, :h3LineSize, %i[h3_index h3_index], :int
5953

60-
# @deprecated Please use {#line_size} instead.
61-
def h3_line_size(origin, destination)
62-
line_size(origin, destination)
63-
end
64-
deprecate :h3_line_size, :line_size, 2020, 1
65-
6654
# Derives H3 indexes within k distance of the origin H3 index.
6755
#
6856
# Similar to {k_ring}, except that an error is raised when one of the indexes
@@ -317,12 +305,6 @@ def line(origin, destination)
317305
hexagons.read
318306
end
319307

320-
# @deprecated Please use {#line} instead.
321-
def h3_line(origin, destination)
322-
line(origin, destination)
323-
end
324-
deprecate :h3_line, :line, 2020, 1
325-
326308
private
327309

328310
def k_rings_for_hex_range(indexes, k)

lib/h3/unidirectional_edges.rb

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ module UnidirectionalEdges
1919
# @return [Boolean] True if indexes are neighbors
2020
attach_predicate_function :neighbors?, :h3IndexesAreNeighbors, %i[h3_index h3_index], :bool
2121

22-
# @deprecated Please use {#neighbors?} instead.
23-
def h3_indexes_neighbors?(origin, destination)
24-
neighbors?(origin, destination)
25-
end
26-
27-
deprecate :h3_indexes_neighbors?, :neighbors?, 2020, 1
28-
2922
# @!method unidirectional_edge_valid?(h3_index)
3023
#
3124
# Determine whether the given H3 index represents an edge.
@@ -42,13 +35,6 @@ def h3_indexes_neighbors?(origin, destination)
4235
%i[h3_index],
4336
:bool
4437

45-
# @deprecated Please use {#unidirectional_edge_valid?} instead.
46-
def h3_unidirectional_edge_valid?(h3_index)
47-
unidirectional_edge_valid?(h3_index)
48-
end
49-
50-
deprecate :h3_unidirectional_edge_valid?, :unidirectional_edge_valid?, 2020, 1
51-
5238
# @!method unidirectional_edge(origin, destination)
5339
#
5440
# Derives the H3 index of the edge from the given H3 indexes.
@@ -66,13 +52,6 @@ def h3_unidirectional_edge_valid?(h3_index)
6652
%i[h3_index h3_index],
6753
:h3_index
6854

69-
# @deprecated Please use {#unidirectional_edge} instead.
70-
def h3_unidirectional_edge(origin, destination)
71-
unidirectional_edge(origin, destination)
72-
end
73-
74-
deprecate :h3_unidirectional_edge, :unidirectional_edge, 2020, 1
75-
7655
# @!method destination_from_unidirectional_edge(edge)
7756
#
7857
# Derive destination H3 index from edge.
@@ -125,16 +104,6 @@ def origin_and_destination_from_unidirectional_edge(edge)
125104
out.read
126105
end
127106

128-
# @deprecated Please use {#origin_and_destination_from_unidirectional_edge} instead.
129-
def h3_indexes_from_unidirectional_edge(edge)
130-
origin_and_destination_from_unidirectional_edge(edge)
131-
end
132-
133-
deprecate :h3_indexes_from_unidirectional_edge,
134-
:origin_and_destination_from_unidirectional_edge,
135-
2020,
136-
1
137-
138107
# Derive unidirectional edges for a H3 index.
139108
#
140109
# @param [Integer] origin H3 index
@@ -154,16 +123,6 @@ def unidirectional_edges_from_hexagon(origin)
154123
out.read
155124
end
156125

157-
# @deprecated Please use {#unidirectional_edges_from_hexagon} instead.
158-
def h3_unidirectional_edges_from_hexagon(origin)
159-
unidirectional_edges_from_hexagon(origin)
160-
end
161-
162-
deprecate :h3_unidirectional_edges_from_hexagon,
163-
:unidirectional_edges_from_hexagon,
164-
2020,
165-
1
166-
167126
# Derive coordinates for edge boundary.
168127
#
169128
# @param [Integer] edge H3 edge index
@@ -184,15 +143,5 @@ def unidirectional_edge_boundary(edge)
184143
[rads_to_degs(d[:lat]), rads_to_degs(d[:lon])]
185144
end
186145
end
187-
188-
# @deprecated Please use {#unidirectional_edge_boundary} instead.
189-
def h3_unidirectional_edge_boundary(edge)
190-
unidirectional_edge_boundary(edge)
191-
end
192-
193-
deprecate :h3_unidirectional_edge_boundary,
194-
:unidirectional_edge_boundary,
195-
2020,
196-
1
197146
end
198147
end

spec/geo_json_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@
6060
expect { geo_json_to_coordinates }.to raise_error(ArgumentError)
6161
end
6262
end
63+
64+
context "when given JSON with the wrong structure" do
65+
let(:input) { { blah: "blah" }.to_json }
66+
67+
it "raises an error" do
68+
expect { geo_json_to_coordinates }.to raise_error(ArgumentError)
69+
end
70+
end
6371
end
6472

6573
describe ".coordinates_to_geo_json" do

0 commit comments

Comments
 (0)