@@ -29,6 +29,21 @@ final class CorrectnessTests: XCTestCase {
2929 XCTAssertEqual ( Geohash . adjacent ( hash: Fixture . hash11, direction: . west) , Fixture . west)
3030 }
3131
32+ func testGeohashAdjacentHandlesWorldBoundaryHashes( ) {
33+ let cases : [ ( hash: String , direction: Geohash . Direction , expected: String ) ] = [
34+ ( " bpbpbp " , . north, " 000000 " ) ,
35+ ( " zzzzzz " , . east, " bpbpbp " ) ,
36+ ( " 000000 " , . south, " bpbpbp " ) ,
37+ ( " 000000 " , . west, " pbpbpb " )
38+ ]
39+
40+ for testCase in cases {
41+ let adjacent = Geohash . adjacent ( hash: testCase. hash, direction: testCase. direction)
42+
43+ XCTAssertEqual ( adjacent, testCase. expected)
44+ }
45+ }
46+
3247 func testGeohashNeighborsAndNeighborSets( ) {
3348 let neighbors = Geohash . neighbors ( hash: Fixture . hash11)
3449
@@ -47,6 +62,24 @@ final class CorrectnessTests: XCTestCase {
4762 )
4863 }
4964
65+ func testGeohashNeighborsHandlesOriginAdjacentGeneratedHashes( ) {
66+ let originAdjacentHashes = Geohash . hashesForRegion (
67+ centerCoordinate: . init( latitude: 0 , longitude: 0 ) ,
68+ latitudeDelta: 0.01 ,
69+ longitudeDelta: 0.01 ,
70+ length: 6
71+ )
72+
73+ XCTAssertEqual ( Set ( originAdjacentHashes) , Set ( [ " 7zzzzz " , " ebpbpb " , " kpbpbp " , " s00000 " ] ) )
74+
75+ for hash in originAdjacentHashes {
76+ let neighbors = Geohash . neighbors ( hash: hash)
77+
78+ XCTAssertTrue ( neighbors. allNeighbors. allSatisfy { $0. count == hash. count } )
79+ XCTAssertTrue ( neighbors. allNeighbors. allSatisfy { !$0. isEmpty } )
80+ }
81+ }
82+
5083 func testGeohashHashesForRegion( ) {
5184 let hashes = Geohash . hashesForRegion (
5285 centerCoordinate: Fixture . coordinate,
0 commit comments