SPB Git

Repository Public

FormatTest.kt 6.4 KB 158 lines kotlin

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * PROJECT METADATA8 * -----------------------------------------------------------------------------9 * Project          : Valo-Plex Android10 * File             : app/src/test/kotlin/com/spboucher/valoplex/FormatTest.kt11 * Description      : formats fr-CA : montants, grands nombres, pourcentages,12 *                    dates, adresses, saisie.13 * Module           : test14 * Repository       : https://git.spboucher.ai/valo-plex-android15 * Project Website  : https://www.valo-plex.com16 * Created          : 2026-12-0117 * Last Modified    : 2026-12-0118 *19 * =============================================================================20 * AUTHOR & PROFESSIONAL AFFILIATION21 * =============================================================================22 *23 * Author           : Simon-Pierre Boucher24 * Position         : Professor of Finance25 * Institution      : Université du Québec en Outaouais (UQO)26 * Department       : Département des sciences administratives27 * Organization     : SP Boucher28 *29 * Website          : https://spboucher.ai30 * Git              : https://git.spboucher.ai31 *32 * =============================================================================33 * OFFICIAL CONTACT DIRECTORY34 * =============================================================================35 *36 * General          : info@spboucher.ai37 * Professional     : contact@spboucher.ai38 * Direct           : simon@spboucher.ai39 * Research         : research@spboucher.ai40 * Development      : dev@spboucher.ai41 * Support          : support@spboucher.ai42 * Security/Admin   : admin@spboucher.ai43 * Notifications    : notifications@spboucher.ai44 *45 * Preferred Contact: contact@spboucher.ai46 *47 * =============================================================================48 * COPYRIGHT & INTELLECTUAL PROPERTY49 * =============================================================================50 *51 * Copyright (c) 202652 * Simon-Pierre Boucher53 *54 * All rights reserved where applicable.55 *56 * This file is governed by the applicable project license,57 * copyright notices, institutional agreements and relevant law.58 *59 * Unless expressly authorized by the applicable license or60 * rights holder, copying, redistribution, sublicensing,61 * publication and commercial exploitation are not permitted.62 *63 * Existing third-party rights and notices remain unaffected.64 *65 * =============================================================================66 * CONFIDENTIALITY & SECURITY67 * =============================================================================68 *69 * Classification   : Public70 * Distribution     : Public repository; use is governed by the project license71 * Security Contact : admin@spboucher.ai72 *73 * Access to this source does not independently grant permission74 * to redistribute or disclose confidential materials.75 *76 * Do not embed credentials, private keys, access tokens,77 * certificates or confidential personal information.78 *79 * =============================================================================80 * LICENSE & MAINTENANCE81 * =============================================================================82 *83 * License          : None specified (no license file in this repository)84 * Maintainer       : Simon-Pierre Boucher85 * Technical Contact: dev@spboucher.ai86 *87 * =============================================================================88 * END OF SP BOUCHER SOURCE HEADER89 * =============================================================================90 */9192package com.spboucher.valoplex9394import org.junit.Assert.assertEquals95import org.junit.Assert.assertNull96import org.junit.Test9798class FormatTest {99    private val nb = " "100101    @Test fun dollars() {102        assertEquals("955${nb}000${nb}$", Format.dollars(955000.0))103        assertEquals("1${nb}380${nb}$", Format.dollars(1380.4))104        assertEquals("—", Format.dollars(null))105        assertEquals("—", Format.dollars(Double.NaN))106        assertEquals("−1${nb}333${nb}$", Format.dollars(-1332.85))107        assertEquals("0${nb}$", Format.dollars(-0.2))108    }109110    @Test fun grandsMontants() {111        assertEquals("1,25${nb}M$", Format.grand(1_250_000.0))112        assertEquals("426,7${nb}G$", Format.grand(426_704_737_000.0))113        assertEquals("715${nb}k$", Format.grand(715_000.0))114        assertEquals("950${nb}$", Format.grand(950.0))115    }116117    @Test fun nombresEtPourcentages() {118        assertEquals("395${nb}472", Format.nombre(395472))119        assertEquals("17,1", Format.nombre(17.14, 1))120        assertEquals("4,16${nb}%", Format.pct(0.0416, 2))121        assertEquals("+12${nb}%", Format.pct(0.1234, 0, signe = true))122        assertEquals("−42${nb}%", Format.pct(-0.4220689, 0, signe = true))123        assertEquals("0${nb}%", Format.pct(0.001, 0, signe = true))124        assertEquals("—", Format.pct(null))125    }126127    @Test fun dates() {128        assertEquals("18 août 2023", Format.dateLongue("2023-08-18"))129        assertEquals("1er juillet 2024", Format.dateLongue("2024-07-01"))130        assertEquals("—", Format.dateLongue(null))131        assertEquals("pas une date", Format.dateLongue("pas une date"))132    }133134    @Test fun adresses() {135        assertEquals("2335-2339, rue Wellington", Format.adresse("2335-2339 Rue WELLINGTON"))136        assertEquals("520-522, avenue 5e", Format.adresse("520-522 Avenue 5E"))137        assertEquals("3026-3030, rue Rushbrooke", Format.adresse("3026-3030 Rue RUSHBROOKE"))138        assertEquals("12, chemin de la Côte-des-Neiges", Format.adresse("12 Chemin DE LA CÔTE-DES-NEIGES"))139        assertEquals("164, Laurentide", Format.adresse("164 LAURENTIDE"))140        assertEquals("Adresse inconnue", Format.adresse(null))141    }142143    @Test fun classesEtDistances() {144        assertEquals("Triplex", Format.libelleClasse("triplex", 3))145        assertEquals("Immeuble de 8 logements", Format.libelleClasse("6-11", 8))146        assertEquals("134${nb}m", Format.distance(0.13436665715464116))147        assertEquals("2,4${nb}km", Format.distance(2.44))148        assertEquals("Sous la fourchette", Format.position("sous"))149    }150151    @Test fun saisie() {152        assertEquals(4.5, Format.lire("4,5")!!, 1e-9)153        assertEquals(850000.0, Format.lire("850 000")!!, 1e-9)154        assertNull(Format.lire(""))155        assertNull(Format.lire("1,2,3"))156    }157}158
Files main
Menu

Theme