Repository Public BSD-3-Clause
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Maps9// File : Infrastructure/geocoder-builder/Tests/GeocoderBuilderTests/GeocoderBuilderTests.swift10// Module : GeocoderBuilderTests11// Repository : https://git.spboucher.ai/orix-maps12// Created : 2026-11-2513// Last Modified : 2026-11-2514//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author : Simon-Pierre Boucher20// Position : Professor of Finance21// Institution : Université du Québec en Outaouais (UQO)22// Department : Département des sciences administratives23// Organization : SP Boucher24//25// Website : https://spboucher.ai26// Git : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General : info@spboucher.ai33// Professional : contact@spboucher.ai34// Direct : simon@spboucher.ai35// Research : research@spboucher.ai36// Development : dev@spboucher.ai37// Support : support@spboucher.ai38// Security/Admin : admin@spboucher.ai39// Notifications : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification : Public66// Distribution : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License : Proprietary, all rights reserved (see license file)80// License File : LICENSE81// Maintainer : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import Foundation89import ORIXGeoCore90import ORIXOSM91import ORIXSearch92import Testing93@testable import GeocoderBuilder9495@Suite struct NodeStoreTests {96 @Test func collectsOnlyWantedNodes() {97 var store = NodeStore(wanted: [30, 10, 20, 10, 40])98 #expect(store.count == 4)99 store.offer(id: 5, latitude: 1, longitude: 1)100 store.offer(id: 10, latitude: 45.5, longitude: -73.5)101 store.offer(id: 15, latitude: 2, longitude: 2)102 store.offer(id: 30, latitude: 46.25, longitude: -71.125)103 // Out of order: falls back to a binary search.104 store.offer(id: 20, latitude: 45.0000001, longitude: -73.0000001)105 store.offer(id: 99, latitude: 3, longitude: 3)106 #expect(store.filled == 3)107 #expect(store.coordinate(10) == Coordinate(latitude: 45.5, longitude: -73.5))108 #expect(store.coordinate(20) == Coordinate(latE7: 450_000_001, lonE7: -730_000_001))109 #expect(store.coordinate(40) == nil) // wanted but absent from the extract110 #expect(store.coordinate(5) == nil)111 #expect(store.contains(40) && !store.contains(5))112 #expect(store.coordinates([10, 40, 30, 7]).count == 2)113 #expect(NodeStore(wanted: []).coordinate(1) == nil)114 }115116 @Test func parallelMapKeepsOrder() {117 #expect(parallelMap(10_000) { $0 * 2 } == (0..<10_000).map { $0 * 2 })118 #expect(parallelMap(0) { $0 }.isEmpty)119 }120}121122@Suite struct AdminTests {123 @Test func ringsAreStitchedFromWays() {124 // A square cut in three ways, one of them reversed, plus a closed inner ring.125 let rings = RingAssembly.assemble([126 .init(nodes: [1, 2], isInner: false), .init(nodes: [4, 3, 2], isInner: false), .init(nodes: [4, 1], isInner: false),127 .init(nodes: [10, 11, 12, 10], isInner: true),128 ])129 #expect(rings?.count == 2)130 #expect(rings?.contains { $0.first == $0.last && Set($0) == [1, 2, 3, 4] } == true)131 #expect(rings?.contains([10, 11, 12, 10]) == true)132 // A boundary cut by the edge of the extract cannot be closed: it is dropped, not guessed.133 #expect(RingAssembly.assemble([.init(nodes: [1, 2], isInner: false), .init(nodes: [2, 3], isInner: false)]) == nil)134 #expect(RingAssembly.assemble([]) == nil)135 }136137 @Test func gridLookupEqualsRayCasting() {138 // An L-shaped municipality with an enclave (inner ring), a borough inside it, and a second municipality.139 let l: [Coordinate] = [(45.0, -74.0), (45.0, -73.0), (45.4, -73.0), (45.4, -73.6), (45.9, -73.6), (45.9, -74.0)].map { Coordinate(latitude: $0.0, longitude: $0.1) }140 let enclave: [Coordinate] = [(45.10, -73.50), (45.10, -73.30), (45.25, -73.30), (45.25, -73.50)].map { Coordinate(latitude: $0.0, longitude: $0.1) }141 let borough: [Coordinate] = [(45.50, -73.95), (45.50, -73.70), (45.80, -73.70), (45.80, -73.95)].map { Coordinate(latitude: $0.0, longitude: $0.1) }142 func polygon(_ id: Int64, _ name: String, _ level: Int, _ rings: [[Coordinate]]) -> AdminPolygon {143 AdminPolygon(relationID: id, name: name, level: level, rings: rings, bbox: BoundingBox(enclosing: rings.joined())!)144 }145 let polygons = [polygon(1, "L", 8, [l, enclave]), polygon(2, "Enclave", 8, [enclave]), polygon(3, "Borough", 9, [borough])]146 let index = AdminIndex(polygons: polygons)147 var generator = SystemRandomNumberGenerator()148 for _ in 0..<20_000 {149 let c = Coordinate(latitude: Double.random(in: 44.9...46.0, using: &generator), longitude: Double.random(in: -74.1 ... -72.9, using: &generator))150 let expected = polygons.indices.filter { polygons[$0].contains(c) }151 #expect(index.polygons(containing: c).sorted() == expected)152 }153 #expect(index.locality(of: Coordinate(latitude: 45.6, longitude: -73.8)).city == 0)154 #expect(index.locality(of: Coordinate(latitude: 45.6, longitude: -73.8)).district == 2)155 #expect(index.locality(of: Coordinate(latitude: 45.2, longitude: -73.4)).city == 1)156 #expect(index.locality(of: Coordinate(latitude: 45.2, longitude: -73.1)).district == nil)157 #expect(index.locality(of: Coordinate(latitude: 45.7, longitude: -73.3)).city == nil)158 #expect(AdminIndex(polygons: []).polygons(containing: Coordinate(latitude: 45, longitude: -73)).isEmpty)159 }160}161162@Suite struct FeatureExtractionTests {163 private func tags(_ d: [(String, String)]) -> [OSMTag] { d.map { OSMTag($0.0, $0.1) } }164165 @Test func namesAndVariants() {166 let (names, brand) = FeatureExtraction.names(tags([("name", "Stade olympique"), ("name:en", "Olympic Stadium"), ("alt_name", "Big O; Le Stade"), ("old_name", "Stade olympique")]))167 #expect(names.primary == "Stade olympique")168 #expect(names.variants == ["Olympic Stadium", "Big O", "Le Stade"])169 #expect(!brand)170 #expect(FeatureExtraction.names(tags([("brand", "SAQ")])).names.primary == "SAQ")171 #expect(FeatureExtraction.names(tags([("highway", "residential")])).names.primary == nil)172 }173174 @Test func whatIsKept() {175 #expect(FeatureExtraction.feature(tags([("amenity", "cafe"), ("name", "Café X")]))?.category == .cafe)176 #expect(FeatureExtraction.feature(tags([("amenity", "cafe")])) == nil) // a café without a name is not searchable177 #expect(FeatureExtraction.feature(tags([("amenity", "toilets")]))?.category == .toilets)178 #expect(FeatureExtraction.feature(tags([("amenity", "toilets"), ("access", "private")])) == nil)179 #expect(FeatureExtraction.feature(tags([("amenity", "parking"), ("access", "private"), ("name", "P1")])) == nil)180 #expect(FeatureExtraction.feature(tags([("amenity", "parking"), ("access", "customers")]))?.category == .parking)181 #expect(FeatureExtraction.feature(tags([("amenity", "bench"), ("name", "Banc")])) == nil)182 #expect(FeatureExtraction.feature(tags([("building", "yes"), ("name", "Tour de la Bourse")]))?.category == .other)183 #expect(FeatureExtraction.feature(tags([("building", "yes")])) == nil)184 let place = FeatureExtraction.feature(tags([("place", "city"), ("name", "Montréal"), ("population", "1 762 949"), ("wikidata", "Q340")]))185 #expect(place?.place == .city && place?.population == 1_762_949 && place?.hasWikidata == true && place?.category == nil)186 #expect(FeatureExtraction.feature(tags([("place", "city")])) == nil)187 let address = FeatureExtraction.feature(tags([("addr:housenumber", " 1000 "), ("addr:street", "Rue Sherbrooke Ouest"), ("addr:city", "Montréal")]))188 #expect(address?.isAddress == true && address?.houseNumber == "1000" && address?.addrCity == "Montréal" && address?.isIndexedFeature == false)189 #expect(FeatureExtraction.feature(tags([("addr:housenumber", "12")]))?.isAddress == false)190 #expect(FeatureExtraction.feature(tags([("source", "survey")])) == nil)191 #expect(FeatureExtraction.feature([]) == nil)192 }193194 @Test func representativePoints() {195 let square: [Coordinate] = [(0.0, 0.0), (0.0, 2.0), (2.0, 2.0), (2.0, 0.0), (0.0, 0.0)].map { Coordinate(latitude: $0.0, longitude: $0.1) }196 let c = FeatureExtraction.representativePoint(square)197 #expect(abs(c!.latitude - 1) < 1e-9 && abs(c!.longitude - 1) < 1e-9)198 #expect(FeatureExtraction.representativePoint([]) == nil)199 #expect(FeatureExtraction.representativePoint([Coordinate(latitude: 1, longitude: 2)]) == Coordinate(latitude: 1, longitude: 2))200 #expect(FeatureExtraction.representativePoint([Coordinate(latitude: 0, longitude: 0), Coordinate(latitude: 2, longitude: 4)]) == Coordinate(latitude: 1, longitude: 2))201 }202}203204/// A miniature extract fed through the same three steps as a PBF: relations, ways, nodes.205@Suite struct BuildTests {206 private func t(_ d: [(String, String)]) -> [OSMTag] { d.map { OSMTag($0.0, $0.1) } }207208 private func build(boundingBox: BoundingBox? = nil) throws -> (URL, GeocoderBuild, SearchIndexSummary) {209 let b = GeocoderBuild(configuration: .init(regionID: "mini", boundingBox: boundingBox, source: "test"))210 // Relations: the municipality "Villeneuve" (square 45.00–45.10 × -73.10–-73.00), a borough in its west half,211 // a boundary cut by the extract, and a lake as a multipolygon.212 b.addRelation(id: 1, tags: t([("type", "boundary"), ("boundary", "administrative"), ("admin_level", "8"), ("name", "Villeneuve")]),213 members: [.init(type: .way, ref: 101, role: "outer"), .init(type: .way, ref: 102, role: "outer"), .init(type: .node, ref: 900, role: "admin_centre")])214 b.addRelation(id: 2, tags: t([("type", "boundary"), ("boundary", "administrative"), ("admin_level", "9"), ("name", "Vieux-Villeneuve")]),215 members: [.init(type: .way, ref: 103, role: "outer")])216 b.addRelation(id: 3, tags: t([("type", "boundary"), ("boundary", "administrative"), ("admin_level", "8"), ("name", "Coupée")]),217 members: [.init(type: .way, ref: 104, role: "outer"), .init(type: .way, ref: 999, role: "outer")])218 b.addRelation(id: 4, tags: t([("type", "multipolygon"), ("natural", "water"), ("name", "Lac Miroir")]), members: [.init(type: .way, ref: 105, role: "outer")])219 b.addRelation(id: 5, tags: t([("type", "route"), ("name", "Bus 10")]), members: [.init(type: .way, ref: 201, role: "")])220221 // Ways.222 b.addWay(id: 101, nodeRefs: [1, 2, 3], tags: []) // boundary south + east223 b.addWay(id: 102, nodeRefs: [3, 4, 1], tags: []) // boundary north + west224 b.addWay(id: 103, nodeRefs: [1, 5, 6, 4, 1], tags: []) // borough ring225 b.addWay(id: 104, nodeRefs: [2, 7], tags: []) // half of a cut boundary226 b.addWay(id: 105, nodeRefs: [20, 21, 22, 23, 20], tags: []) // lake ring227 b.addWay(id: 201, nodeRefs: [30, 31], tags: t([("highway", "residential"), ("name", "Rue des Érables")]))228 b.addWay(id: 202, nodeRefs: [31, 32], tags: t([("highway", "residential"), ("name", "Rue des Érables"), ("alt_name", "Maple Street")]))229 b.addWay(id: 203, nodeRefs: [30, 32], tags: t([("highway", "footway"), ("footway", "sidewalk"), ("name", "Rue des Érables")]))230 b.addWay(id: 204, nodeRefs: [40, 41], tags: t([("highway", "motorway"), ("ref", "40"), ("name", "Autoroute Félix-Leclerc")]))231 b.addWay(id: 205, nodeRefs: [42, 43], tags: t([("highway", "primary"), ("ref", "132")])) // numbered road without a name232 b.addWay(id: 206, nodeRefs: [44, 45], tags: t([("highway", "proposed"), ("name", "Rue Future")])) // not a street yet233 b.addWay(id: 207, nodeRefs: [46, 47], tags: t([("highway", "residential"), ("name", "Rue des Érables")])) // same name outside the municipality234 b.addWay(id: 208, nodeRefs: [50, 51, 52], tags: t([("addr:interpolation", "even"), ("addr:street", "Rue des Érables")]))235 b.addWay(id: 209, nodeRefs: [53, 54], tags: t([("addr:interpolation", "alphabetic"), ("addr:street", "Rue des Érables")]))236 b.addWay(id: 210, nodeRefs: [55, 56], tags: t([("addr:interpolation", "odd"), ("addr:street", "Rue des Érables")])) // parity contradicts the tag237 b.addWay(id: 300, nodeRefs: [60, 61, 62, 63, 60], tags: t([("building", "yes"), ("amenity", "school"), ("name", "École du Boisé"), ("addr:housenumber", "25"), ("addr:street", "des Érables")]))238 b.addWay(id: 301, nodeRefs: [64, 65, 66, 67, 64], tags: t([("building", "house"), ("addr:housenumber", "7"), ("addr:street", "Chemin Inconnu")]))239 b.addWay(id: 302, nodeRefs: [64, 65], tags: t([("barrier", "fence")]))240 b.finishWays()241 #expect(b.statistics.streetWays == 6)242243 // Nodes, in increasing identifier order like a PBF.244 let nodes: [(Int64, Double, Double, [(String, String)])] = [245 (1, 45.00, -73.10, []), (2, 45.00, -73.00, []), (3, 45.10, -73.00, []), (4, 45.10, -73.10, []), (5, 45.00, -73.05, []), (6, 45.10, -73.05, []),246 (7, 44.95, -73.00, []),247 (20, 45.060, -73.030, []), (21, 45.060, -73.020, []), (22, 45.070, -73.020, []), (23, 45.070, -73.030, []),248 (30, 45.0500, -73.0900, []), (31, 45.0500, -73.0800, []), (32, 45.0500, -73.0700, []),249 (40, 45.0200, -73.0900, []), (41, 45.0200, -73.0100, []), (42, 45.0300, -73.0900, []), (43, 45.0300, -73.0100, []),250 (44, 45.0400, -73.0900, []), (45, 45.0400, -73.0800, []), (46, 45.2000, -73.0900, []), (47, 45.2000, -73.0800, []),251 (50, 45.0502, -73.0900, [("addr:housenumber", "100")]), (51, 45.0502, -73.0850, []), (52, 45.0502, -73.0800, [("addr:housenumber", "120")]),252 (53, 45.0503, -73.0790, [("addr:housenumber", "1A")]), (54, 45.0503, -73.0780, [("addr:housenumber", "1F")]),253 (55, 45.0504, -73.0770, [("addr:housenumber", "200")]), (56, 45.0504, -73.0760, [("addr:housenumber", "210")]),254 (60, 45.0510, -73.0850, []), (61, 45.0510, -73.0840, []), (62, 45.0520, -73.0840, []), (63, 45.0520, -73.0850, []),255 (64, 45.0800, -73.0200, []), (65, 45.0800, -73.0199, []), (66, 45.0801, -73.0199, []), (67, 45.0801, -73.0200, []),256 (900, 45.0550, -73.0500, [("place", "town"), ("name", "Villeneuve"), ("population", "12000")]),257 (901, 45.0498, -73.0880, [("addr:housenumber", "110"), ("addr:street", "Rue des Érables"), ("entrance", "main")]),258 (902, 45.0499, -73.0750, [("amenity", "cafe"), ("name", "Café des Érables"), ("addr:housenumber", "150"), ("addr:street", "Rue des Érables"), ("addr:city", "Villeneuve-Centre")]),259 (903, 45.0700, -73.0600, [("amenity", "drinking_water")]),260 (904, 45.0700, -73.0610, [("amenity", "bench")]),261 (905, 45.2010, -73.0850, [("place", "village"), ("name", "Hameau-du-Nord")]),262 (906, 45.0600, -73.0900, [("addr:housenumber", "5")]),263 (907, 45.0100, -73.0500, [("highway", "bus_stop"), ("name", "Terminus Villeneuve")]),264 ]265 for n in nodes { b.addNode(id: n.0, latitude: n.1, longitude: n.2, tags: t(n.3)) }266267 let url = FileManager.default.temporaryDirectory.appendingPathComponent("orix-geocoder-tests-\(UUID().uuidString)").appendingPathComponent("search.sqlite")268 let summary = try b.write(to: url, dataTimestamp: Date(timeIntervalSince1970: 1_795_000_000))269 return (url, b, summary)270 }271272 @Test func buildsAndAnswers() async throws {273 let (url, build, summary) = try build()274 let s = build.statistics275 #expect(s.adminRelations == 3 && s.adminPolygons == 2 && s.adminIncomplete == 1)276 #expect(s.missingNodes == 0)277 #expect(s.interpolationWays == 3 && s.interpolationRanges == 1 && s.interpolationSkippedAlphabetic == 1 && s.interpolationSkippedInvalid == 1)278 #expect(s.addressesWithoutStreet == 1)279 #expect(s.addressOnlyStreets == 1)280 #expect(summary.places == 2)281 #expect(summary.interpolations == 1)282 // Streets: Érables in Villeneuve, Érables near Hameau-du-Nord, A-40, route 132, Chemin Inconnu (addresses only).283 #expect(summary.streets == 5)284 // Addresses: 100 and 120 (interpolation ends), 110, 150, 25 on Érables; 7 on Chemin Inconnu.285 #expect(summary.addresses == 6)286287 let engine = SearchEngine()288 let info = try await engine.openIndex(at: url)289 #expect(info.regionID == "mini")290 #expect(info.dataDate == Date(timeIntervalSince1970: 1_795_000_000))291 #expect(info.builderVersion == GeocoderBuild.builderVersion)292293 // The street: its two road ways merged, the sidewalk of the same name ignored, the alt_name searchable, the city from the polygon.294 let streets = try await engine.search(SearchQuery(text: "rue des Érables", focus: Coordinate(latitude: 45.05, longitude: -73.08))).results.filter { $0.kind == .street }295 #expect(streets.count == 2)296 let main = try #require(streets.first)297 #expect(main.city == "Villeneuve" && !main.cityIsApproximate)298 #expect(main.streetClass == .residential)299 #expect(abs(main.boundingBox!.minLon - (-73.09)) < 1e-6 && abs(main.boundingBox!.maxLon - (-73.07)) < 1e-6)300 // Outside every polygon: the nearest settlement, flagged as an approximation.301 #expect(streets[1].city == "Hameau-du-Nord" && streets[1].cityIsApproximate)302 #expect(try await engine.search(SearchQuery(text: "Maple Street")).results.first?.name == "Rue des Érables")303304 // Addresses: an entrance node, a building, a point of interest, interpolation ends, interpolated numbers.305 func address(_ text: String) async throws -> SearchResult? { try await engine.search(SearchQuery(text: text)).results.first }306 #expect(try await address("110 rue des Érables")?.osm == OSMElementRef(type: .node, id: 901))307 #expect(try await address("110 rue des Érables")?.addressMatch == .exact)308 #expect(try await address("25 rue des Érables")?.osm == OSMElementRef(type: .way, id: 300)) // addr:street written without "Rue"309 #expect(try await address("150 rue des Érables, Villeneuve")?.addressMatch == .exact)310 #expect(try await address("100 rue des Érables")?.osm == OSMElementRef(type: .node, id: 50))311 let interpolated = try #require(try await address("110 rue des Erables"))312 #expect(interpolated.addressMatch == .exact) // 110 exists as a real object: it wins over the interpolation313 let estimated = try #require(try await address("104 rue des Érables"))314 #expect(estimated.addressMatch == .interpolated)315 #expect(abs(estimated.coordinate.longitude - (-73.0880)) < 1e-5)316 #expect(try await address("105 rue des Érables")?.addressMatch == .streetOnly) // odd number on an even range317 #expect(try await address("205 rue des Érables")?.addressMatch == .streetOnly) // the invalid interpolation way was not used318 #expect(try await address("7 chemin Inconnu")?.addressMatch == .exact)319 #expect(try await address("9 chemin Inconnu")?.addressMatch == .streetOnly)320321 // Points of interest and places.322 let cafe = try #require(try await engine.search(SearchQuery(text: "café", focus: Coordinate(latitude: 45.05, longitude: -73.08))).results.first)323 #expect(cafe.name == "Café des Érables" && cafe.category == .cafe)324 #expect(cafe.city == "Villeneuve-Centre") // its own addr:city wins over the polygon325 #expect(cafe.district == "Vieux-Villeneuve") // the district still comes from the boundary326 #expect(cafe.secondaryLine == "150 Rue des Érables, Vieux-Villeneuve, Villeneuve-Centre")327 let school = try #require(try await engine.search(SearchQuery(text: "école du boisé")).results.first)328 #expect(school.category == .school && school.osm == OSMElementRef(type: .way, id: 300))329 #expect(school.city == "Villeneuve" && school.district == "Vieux-Villeneuve")330 let lake = try #require(try await engine.search(SearchQuery(text: "lac miroir")).results.first)331 #expect(lake.category == .waterBody && lake.osm == OSMElementRef(type: .relation, id: 4) && lake.boundingBox != nil)332 #expect(abs(lake.coordinate.latitude - 45.065) < 1e-6)333 #expect(try await engine.search(SearchQuery(text: "Villeneuve")).results.first?.placeType == .town)334 #expect(try await engine.search(SearchQuery(text: "eau potable", focus: Coordinate(latitude: 45.07, longitude: -73.06))).results.first?.category == .drinkingWater)335 #expect(try await engine.search(SearchQuery(text: "banc")).results.isEmpty)336 #expect(try await engine.search(SearchQuery(text: "Rue Future")).results.isEmpty)337 #expect(try await engine.search(SearchQuery(text: "Terminus Villeneuve")).results.first?.category == .busStop)338339 // Roads by reference, named or not.340 let a40 = try #require(try await engine.search(SearchQuery(text: "A-40")).results.first)341 #expect(a40.name == "Autoroute Félix-Leclerc" && a40.roadRef == "40")342 let r132 = try #require(try await engine.search(SearchQuery(text: "route 132")).results.first)343 #expect(r132.name == "" && r132.roadRef == "132" && r132.streetClass == .primary)344345 // Reverse geocoding on the built geometry.346 guard case .found(let r) = try await engine.reverseGeocode(Coordinate(latitude: 45.0499, longitude: -73.0879)) else { Issue.record("no reverse result"); return }347 #expect(r.address?.result.name == "110 Rue des Érables")348 #expect(r.street?.result.name == "Rue des Érables")349 #expect(abs(r.street!.distance - 11.1) < 1)350 #expect(try await engine.reverseGeocode(Coordinate(latitude: 45.3, longitude: -73.5)) == .nothingWithin(meters: 150))351 }352353 @Test func boundingBoxFilters() async throws {354 let (url, _, summary) = try build(boundingBox: BoundingBox(minLat: 45.0, minLon: -73.1, maxLat: 45.1, maxLon: -73.0))355 #expect(summary.places == 1) // Hameau-du-Nord is outside356 #expect(summary.streets == 4)357 let engine = SearchEngine()358 let info = try await engine.openIndex(at: url)359 #expect(info.boundingBox == BoundingBox(minLat: 45.0, minLon: -73.1, maxLat: 45.1, maxLon: -73.0))360 #expect(try await engine.search(SearchQuery(text: "Hameau-du-Nord")).results.isEmpty)361 }362363 /// Opt-in: set ORIX_GEOCODER_PBF to an .osm.pbf extract (for example data/montreal.osm.pbf) to run the real pipeline.364 @Test(.enabled(if: ProcessInfo.processInfo.environment["ORIX_GEOCODER_PBF"] != nil))365 func realExtract() async throws {366 let pbf = URL(fileURLWithPath: ProcessInfo.processInfo.environment["ORIX_GEOCODER_PBF"]!)367 let out = FileManager.default.temporaryDirectory.appendingPathComponent("orix-geocoder-tests-\(UUID().uuidString)").appendingPathComponent("search.sqlite")368 let outcome = try GeocoderBuild.run(pbf: pbf, output: out, configuration: .init(regionID: "real"))369 #expect(outcome.summary.streets > 0 && outcome.summary.pois > 0 && outcome.statistics.missingNodes == 0)370 let engine = SearchEngine()371 try await engine.openIndex(at: out)372 #expect(!(try await engine.suggest("rue").results.isEmpty))373 try? FileManager.default.removeItem(at: out.deletingLastPathComponent())374 }375}376