SPB Git

Repository Public BSD-3-Clause

TripCoverageTests.swift 7.3 KB 157 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Maps9// File             : Apps/ORIXMaps/Tests/ORIXMapsTests/TripCoverageTests.swift10// Module           : ORIXMapsTests11// 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 ORIXMapPackage91import Testing92@testable import ORIXMaps9394struct TripCoverageTests {95    private func catalogRegion(_ id: String, _ box: BoundingBox) -> CatalogRegion {96        CatalogRegion(id: id, names: ["en": id], bbox: box, capabilities: ["map"],97                      latest: CatalogRelease(dataVersion: DataVersion("2026.11.24")!, dataTimestamp: "2026-11-24T00:00:00Z", buildDate: nil, downloadSize: 1, installedSize: 1,98                                             sha256: String(repeating: "0", count: 64), signingKeyId: "k", minAppVersion: nil,99                                             path: "files/\(id)/2026.11.24/\(id)-2026.11.24.orixmap", preambleSize: nil))100    }101102    @Test func aTripInsideOneRegionIsFullyCovered() {103        let r = TripCoverage.compute(line: [downtownMontreal, olympicStadium], regions: [region("mtl", montrealBox)], catalog: [catalogRegion("mtl", montrealBox)], installedIDs: ["mtl"])104        #expect(r.coveredShare == 1 && r.isComplete)105        #expect(r.installed.map(\.id) == ["mtl"])106        #expect(r.available.isEmpty)107    }108109    @Test func withNoRegionNothingIsCoveredAndTheCatalogOffersTheMap() {110        let r = TripCoverage.compute(line: [downtownMontreal, olympicStadium], regions: [], catalog: [catalogRegion("mtl", montrealBox), catalogRegion("qc", quebecCityBox)], installedIDs: [])111        #expect(r.coveredShare == 0 && !r.isComplete)112        #expect(r.installed.isEmpty)113        #expect(r.available.map(\.id) == ["mtl"])114    }115116    @Test func montrealToQuebecIsPartlyCoveredAndTheMissingMapIsOffered() {117        let r = TripCoverage.compute(line: [downtownMontreal, quebecCity], regions: [region("mtl", montrealBox)],118                                     catalog: [catalogRegion("mtl", montrealBox), catalogRegion("qc", quebecCityBox)], installedIDs: ["mtl"])119        #expect(r.coveredShare > 0.05 && r.coveredShare < 0.5)120        #expect(!r.isComplete)121        #expect(r.installed.map(\.id) == ["mtl"])122        // The installed region is never offered again; the one containing the uncovered end is.123        #expect(r.available.map(\.id) == ["qc"])124    }125126    @Test func bothEndsCoveredButNotTheMiddle() {127        let r = TripCoverage.compute(line: [downtownMontreal, quebecCity], regions: [region("mtl", montrealBox), region("qc", quebecCityBox)], catalog: [], installedIDs: ["mtl", "qc"])128        #expect(r.coveredShare > 0.2 && r.coveredShare < 0.9)129        #expect(Set(r.installed.map(\.id)) == ["mtl", "qc"])130        #expect(r.available.isEmpty)131    }132133    @Test func theDevelopmentRegionDoesNotCount() {134        let world = BoundingBox(minLat: -85, minLon: -180, maxLat: 85, maxLon: 180)135        let r = TripCoverage.compute(line: [downtownMontreal, quebecCity], regions: [region("dev", world)], catalog: [], installedIDs: [])136        #expect(r.coveredShare == 0 && r.installed.isEmpty)137    }138139    @Test func aRegionOffTheTripIsNotListed() {140        let r = TripCoverage.compute(line: [downtownMontreal, olympicStadium], regions: [region("mtl", montrealBox), region("qc", quebecCityBox)], catalog: [], installedIDs: ["mtl", "qc"])141        #expect(r.installed.map(\.id) == ["mtl"])142    }143144    @Test func degenerateLines() {145        let empty = TripCoverage.compute(line: [], regions: [region("mtl", montrealBox)], catalog: [], installedIDs: ["mtl"])146        #expect(empty.coveredShare == 0 && empty.installed.isEmpty)147        let point = TripCoverage.compute(line: [downtownMontreal], regions: [region("mtl", montrealBox)], catalog: [], installedIDs: ["mtl"])148        #expect(point.coveredShare == 1)149    }150151    @Test func samplingStep() {152        #expect(TripCoverage.sampleStep(forLength: 0) == 500)153        #expect(TripCoverage.sampleStep(forLength: 250_000) == 500)154        #expect(TripCoverage.sampleStep(forLength: 4_000_000) == 2_000)155    }156}157
Files main
Menu

Theme