Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * PROJECT METADATA8 * -----------------------------------------------------------------------------9 * Project : Vrai-Prix Android10 * File : app/src/test/kotlin/com/spboucher/vraiprix/FormatTest.kt11 * Description : formats du français du Québec : montants, écarts signés à12 * vrai signe moins, étiquettes compactes, dates, adresses,13 * superficies, distances.14 * Module : test15 * Repository : https://git.spboucher.ai/vrai-prix-android16 * Project Website : https://www.vrai-prix.com17 * Created : 2026-11-2918 * Last Modified : 2026-11-2919 *20 * =============================================================================21 * AUTHOR & PROFESSIONAL AFFILIATION22 * =============================================================================23 *24 * Author : Simon-Pierre Boucher25 * Position : Professor of Finance26 * Institution : Université du Québec en Outaouais (UQO)27 * Department : Département des sciences administratives28 * Organization : SP Boucher29 *30 * Website : https://spboucher.ai31 * Git : https://git.spboucher.ai32 *33 * =============================================================================34 * OFFICIAL CONTACT DIRECTORY35 * =============================================================================36 *37 * General : info@spboucher.ai38 * Professional : contact@spboucher.ai39 * Direct : simon@spboucher.ai40 * Research : research@spboucher.ai41 * Development : dev@spboucher.ai42 * Support : support@spboucher.ai43 * Security/Admin : admin@spboucher.ai44 * Notifications : notifications@spboucher.ai45 *46 * Preferred Contact: dev@spboucher.ai47 *48 * =============================================================================49 * COPYRIGHT & INTELLECTUAL PROPERTY50 * =============================================================================51 *52 * Copyright (c) 202653 * Simon-Pierre Boucher54 *55 * All rights reserved where applicable.56 *57 * This file is governed by the applicable project license,58 * copyright notices, institutional agreements and relevant law.59 *60 * Unless expressly authorized by the applicable license or61 * rights holder, copying, redistribution, sublicensing,62 * publication and commercial exploitation are not permitted.63 *64 * Existing third-party rights and notices remain unaffected.65 *66 * =============================================================================67 * CONFIDENTIALITY & SECURITY68 * =============================================================================69 *70 * Classification : Public71 * Distribution : Public repository; use is governed by the project license72 * Security Contact : admin@spboucher.ai73 *74 * Access to this source does not independently grant permission75 * to redistribute or disclose confidential materials.76 *77 * Do not embed credentials, private keys, access tokens,78 * certificates or confidential personal information.79 *80 * =============================================================================81 * LICENSE & MAINTENANCE82 * =============================================================================83 *84 * License : None specified (no license file in this repository)85 * Maintainer : Simon-Pierre Boucher86 * Technical Contact: dev@spboucher.ai87 *88 * =============================================================================89 * END OF SP BOUCHER SOURCE HEADER90 * =============================================================================91 */9293package com.spboucher.vraiprix9495import com.spboucher.vraiprix.core.util.Fmt96import org.junit.Assert.assertEquals97import org.junit.Test9899class FormatTest {100 private val n = " "101102 @Test fun money() {103 assertEquals("449${n}000$n$", Fmt.money(449_000.0))104 assertEquals("1${n}250${n}000$n$", Fmt.money(1_250_000.4))105 assertEquals("950$n$", Fmt.money(950.0))106 assertEquals("—", Fmt.money(null))107 assertEquals("—", Fmt.money(Double.NaN))108 assertEquals("−12${n}000$n$", Fmt.money(-12_000.0))109 assertEquals("+28${n}900$n$", Fmt.signedMoney(28_900.0))110 assertEquals("−12${n}000$n$", Fmt.signedMoney(-12_000.0))111 }112113 @Test fun signedPercentUsesRealMinus() {114 assertEquals("+6,3$n%", Fmt.pct(6.3))115 assertEquals("−11,6$n%", Fmt.pct(-11.6))116 assertEquals("0,0$n%", Fmt.pct(0.04))117 assertEquals("+5$n%", Fmt.pct(5.2, 0))118 assertEquals("21,6$n%", Fmt.share(0.2159))119 assertEquals("21,6$n%", Fmt.percent(21.59))120 assertEquals("—", Fmt.pct(null))121 }122123 @Test fun compactLabels() {124 assertEquals("460${n}k$", Fmt.compact(460_100.0))125 assertEquals("1,2${n}M$", Fmt.compact(1_234_000.0))126 assertEquals("1${n}M$", Fmt.compact(999_600.0))127 assertEquals("12${n}M$", Fmt.compact(12_400_000.0))128 assertEquals("850$n$", Fmt.compact(850.0))129 assertEquals("450${n}k$", Fmt.axis(450_000.0))130 assertEquals("1,25${n}M$", Fmt.axis(1_250_000.0))131 assertEquals("2${n}M$", Fmt.axis(2_000_000.0))132 }133134 @Test fun bigNumbersAndIntegers() {135 assertEquals("378,5${n}G$", Fmt.big(378.5e9))136 assertEquals("3,7${n}M", Fmt.big(3_700_000.0, ""))137 assertEquals("3${n}747${n}008", Fmt.int(3_747_008))138 assertEquals("—", Fmt.int(null))139 assertEquals("1,06", Fmt.decimal(1.06, 2))140 }141142 @Test fun dates() {143 assertEquals("14 mars 2024", Fmt.day("2024-03-14"))144 assertEquals("1er juillet 2023", Fmt.day("2023-07-01"))145 assertEquals("18 nov. 2026", Fmt.day("2026-11-18", short = true))146 assertEquals("14 mars 2024", Fmt.day("2024-03-14T08:12:00.000Z"))147 assertEquals("pas une date", Fmt.day("pas une date"))148 assertEquals("—", Fmt.day(null))149 assertEquals("juillet 2026", Fmt.month("2026-07"))150 assertEquals("T3${n}2026", Fmt.period("2026-T3"))151 assertEquals("octobre 2026", Fmt.period("2026-10"))152 }153154 @Test fun addressesFromTheRollAreSoftened() {155 assertEquals("104 Rue Rochon", Fmt.address("104 Rue ROCHON"))156 assertEquals("1234 Rue Saint-Denis", Fmt.address("1234 Rue SAINT-DENIS"))157 assertEquals("5681 Rue Campanules", Fmt.address("5681 Rue Campanules"))158 assertEquals("12 Avenue De L'Église", Fmt.address("12 Avenue DE L'ÉGLISE".replace("DE ", "De ")))159 assertEquals("", Fmt.address(" "))160 assertEquals("", Fmt.address(null))161 assertEquals("Copropriété", Fmt.capitalized("copropriété"))162 }163164 @Test fun measures() {165 assertEquals("95,5${n}m² (1${n}028${n}pi²)", Fmt.area(95.5))166 assertEquals("110${n}m² (1${n}187${n}pi²)", Fmt.area(110.3))167 assertEquals("3${n}007${n}m²", Fmt.area(3007.2, both = false))168 assertEquals("—", Fmt.area(0.0))169 assertEquals("1${n}250${n}pi²", Fmt.areaSqft(1250.0))170 assertEquals("120${n}m", Fmt.distance(118.0))171 assertEquals("10${n}m", Fmt.distance(2.0))172 assertEquals("1,4${n}km", Fmt.distance(1_420.0))173 assertEquals("12${n}km", Fmt.distance(12_300.0))174 }175176 @Test fun agoAndSlug() {177 assertEquals("ce mois-ci", Fmt.ago(0.4))178 assertEquals("il y a 7${n}mois", Fmt.ago(7.2))179 assertEquals("il y a 2${n}ans", Fmt.ago(26.0))180 assertEquals("104-rue-rochon-saint-colomban", Fmt.slug("104 Rue Rochon, Saint-Colomban"))181 assertEquals("levis", Fmt.slug("Lévis"))182 }183}184