Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Vrai-Prix iOS9// File : VraiPrixTests/FormatTests.swift10// Description : formats du français du Québec et lecture d'un prix11// (verdicts).12// Module : VraiPrixTests13// Repository : https://git.spboucher.ai/vrai-prix-ios-v314// Project Website : https://www.vrai-prix.com15// Created : 2026-11-2616// Last Modified : 2026-11-2617//18// =============================================================================19// AUTHOR & PROFESSIONAL AFFILIATION20// =============================================================================21//22// Author : Simon-Pierre Boucher23// Position : Professor of Finance24// Institution : Université du Québec en Outaouais (UQO)25// Department : Département des sciences administratives26// Organization : SP Boucher27//28// Website : https://spboucher.ai29// Git : https://git.spboucher.ai30//31// =============================================================================32// OFFICIAL CONTACT DIRECTORY33// =============================================================================34//35// General : info@spboucher.ai36// Professional : contact@spboucher.ai37// Direct : simon@spboucher.ai38// Research : research@spboucher.ai39// Development : dev@spboucher.ai40// Support : support@spboucher.ai41// Security/Admin : admin@spboucher.ai42// Notifications : notifications@spboucher.ai43//44// Preferred Contact: support@spboucher.ai45//46// =============================================================================47// COPYRIGHT & INTELLECTUAL PROPERTY48// =============================================================================49//50// Copyright (c) 202651// Simon-Pierre Boucher52//53// All rights reserved where applicable.54//55// This file is governed by the applicable project license,56// copyright notices, institutional agreements and relevant law.57//58// Unless expressly authorized by the applicable license or59// rights holder, copying, redistribution, sublicensing,60// publication and commercial exploitation are not permitted.61//62// Existing third-party rights and notices remain unaffected.63//64// =============================================================================65// CONFIDENTIALITY & SECURITY66// =============================================================================67//68// Classification : Public69// Distribution : Public repository; use is governed by the project license70// Security Contact : admin@spboucher.ai71//72// Access to this source does not independently grant permission73// to redistribute or disclose confidential materials.74//75// Do not embed credentials, private keys, access tokens,76// certificates or confidential personal information.77//78// =============================================================================79// LICENSE & MAINTENANCE80// =============================================================================81//82// License : None specified (no license file in this repository)83// Maintainer : Simon-Pierre Boucher84// Technical Contact: dev@spboucher.ai85//86// =============================================================================87// END OF SP BOUCHER SOURCE HEADER88// =============================================================================8990import XCTest91@testable import VraiPrix9293final class FormatTests: XCTestCase {94 private let s = Fmt.nbsp9596 func testMoney() {97 XCTAssertEqual(Fmt.money(460_100), "460\(s)100\(s)$")98 XCTAssertEqual(Fmt.money(3_283_000), "3\(s)283\(s)000\(s)$")99 XCTAssertEqual(Fmt.money(950), "950\(s)$")100 XCTAssertEqual(Fmt.money(nil), "—")101 XCTAssertEqual(Fmt.money(.nan), "—")102 }103104 func testSignedMoneyUsesTrueMinus() {105 XCTAssertEqual(Fmt.signedMoney(28_900), "+28\(s)900\(s)$")106 XCTAssertEqual(Fmt.signedMoney(-83_000), "\u{2212}83\(s)000\(s)$")107 XCTAssertEqual(Fmt.signedMoney(0), "0\(s)$")108 }109110 func testPercent() {111 XCTAssertEqual(Fmt.pct(6.28), "+6,3\(s)%")112 XCTAssertEqual(Fmt.pct(-11.6), "\u{2212}11,6\(s)%")113 XCTAssertEqual(Fmt.pct(0.01), "0,0\(s)%")114 XCTAssertEqual(Fmt.pct(81.2, digits: 0), "+81\(s)%")115 XCTAssertEqual(Fmt.share(0.2159), "21,6\(s)%")116 }117118 func testCompact() {119 XCTAssertEqual(Fmt.compact(460_100), "460\(s)k$")120 XCTAssertEqual(Fmt.compact(1_234_000), "1,2\(s)M$")121 XCTAssertEqual(Fmt.compact(3_000_000), "3\(s)M$")122 XCTAssertEqual(Fmt.compact(12_400_000), "12\(s)M$")123 XCTAssertEqual(Fmt.compact(999_600), "1\(s)M$")124 XCTAssertEqual(GaugeScale.label(450_000), "450\(s)k$")125 XCTAssertEqual(GaugeScale.label(1_250_000), "1,25\(s)M$")126 XCTAssertEqual(GaugeScale.label(2_000_000), "2\(s)M$")127 }128129 func testDates() {130 XCTAssertEqual(Fmt.day("2024-03-14"), "14 mars 2024")131 XCTAssertEqual(Fmt.month("2026-07"), "juillet 2026")132 XCTAssertEqual(Fmt.day("pas une date"), "pas une date")133 XCTAssertNotNil(Fmt.monthDate("2021-01"))134 }135136 func testAddressSoftensShoutingCaps() {137 XCTAssertEqual(Fmt.address("728 Avenue PRATT"), "728 Avenue Pratt")138 XCTAssertEqual(Fmt.address("5681 Rue Campanules"), "5681 Rue Campanules")139 XCTAssertEqual(Fmt.address(" "), "Adresse non précisée")140 XCTAssertEqual(Fmt.address(nil), "Adresse non précisée")141 }142143 func testAreasAndDistances() {144 XCTAssertEqual(Fmt.area(m2: 395.5), "396\(s)m² (4\(s)257\(s)pi²)")145 XCTAssertEqual(Fmt.distance(m: 0.12), "10\(s)m")146 XCTAssertEqual(Fmt.distance(m: 1187), "1,2\(s)km")147 XCTAssertEqual(Fmt.ago(months: 0.4), "ce mois-ci")148 XCTAssertEqual(Fmt.ago(months: 7), "il y a 7 mois")149 }150151 // MARK: Verdicts152153 func testVerdictRuleIsTheServiceRule() {154 // règle publiée par /api/version : ±7 % à la valeur ; nettement au-dessus = plus de 15 % ET hors de la fourchette155 let t = Verdict.Thresholds.standard156 XCTAssertEqual(Verdict(gapPct: -11.6, thresholds: t), .sous)157 XCTAssertEqual(Verdict(gapPct: 1.1, thresholds: t), .juste)158 XCTAssertEqual(Verdict(gapPct: 6.3, thresholds: t), .juste)159 XCTAssertEqual(Verdict(gapPct: -7, thresholds: t), .juste)160 XCTAssertEqual(Verdict(gapPct: 8.6, thresholds: t), .dessus)161 XCTAssertEqual(Verdict(gapPct: 17.4, inRange: false, thresholds: t), .nettement)162 XCTAssertEqual(Verdict(gapPct: 17.4, inRange: nil, thresholds: t), .nettement)163 XCTAssertEqual(Verdict(gapPct: 17.4, inRange: true, thresholds: t), .dessus, "un prix dans la fourchette n'est jamais nettement au-dessus")164 XCTAssertEqual(Verdict(rawValue: "tres-dessus"), .nettement)165 XCTAssertNil(Verdict(rawValue: "inconnu"))166 }167168 func testReadingPrefersTheService() {169 let server = Reading.of(verdict: "sous", ecartPct: -10.3, dansFourchette: true, price: 500_000, value: 400_000, low: 1, high: 2)170 XCTAssertEqual(server?.verdict, .sous); XCTAssertEqual(server?.gapPct, -10.3); XCTAssertEqual(server?.inRange, true)171 let local = Reading.of(verdict: nil, ecartPct: nil, dansFourchette: nil, price: 489_000, value: 460_100, low: 400_200, high: 566_000)172 XCTAssertEqual(local?.verdict, .juste); XCTAssertEqual(local!.gapPct, 6.281, accuracy: 0.01); XCTAssertEqual(local?.inRange, true)173 XCTAssertNil(Reading(verdict: nil, ecartPct: nil, dansFourchette: nil))174 XCTAssertNil(Reading(price: 2995, value: 7_535_400, low: nil, high: nil), "un loyer inscrit comme prix n'est pas lu")175 XCTAssertNil(Reading(price: nil, value: 400_000, low: nil, high: nil))176 // plage de lecture du service : valeur / prix dans [0,4 ; 2,5]177 XCTAssertNotNil(Verdict.gapPct(price: 1_000_000, value: 400_000))178 XCTAssertNil(Verdict.gapPct(price: 1_000_001, value: 400_000))179 XCTAssertNil(Verdict.gapPct(price: 400_000, value: 0))180 }181182 func testVerdictPositions() {183 XCTAssertEqual(Verdict.sous.position, -1)184 XCTAssertEqual(Verdict.juste.position, 0)185 XCTAssertEqual(Verdict.nettement.position, 1)186 XCTAssertEqual(PropType.label("condo_ou_multi"), "Condo")187 XCTAssertEqual(PropType.label("maison"), "Maison")188 XCTAssertEqual(PropType.label("immeuble"), "Immeuble")189 XCTAssertEqual(PropType.label("indéterminé"), "Autre")190 XCTAssertEqual(PropType.label(nil), "Propriété")191 }192}193