SPB Git

Repository Public

LogiqueTest.kt 8.7 KB 179 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/LogiqueTest.kt11 * Description      : géométrie de l'élévation, départ et corps du pro forma,12 *                    liens entrants, listes locales.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 com.spboucher.valoplex.data.Decodeur95import com.spboucher.valoplex.data.EntreeProForma96import com.spboucher.valoplex.data.Listes97import com.spboucher.valoplex.data.Memo98import com.spboucher.valoplex.ui.PlanFacade99import org.junit.Assert.assertEquals100import org.junit.Assert.assertFalse101import org.junit.Assert.assertNull102import org.junit.Assert.assertTrue103import org.junit.Test104105class LogiqueTest {106    @Test fun elevation() {107        // triplex de deux étages, en rangée des deux côtés : 2 niveaux, 4 travées (comme Facade.tsx)108        val p = PlanFacade.de(3, 2.0, "En rangée plus de 1 côté")109        assertEquals(2, p.niveaux); assertEquals(4, p.travees)110        assertTrue(p.mitoyenGauche); assertTrue(p.mitoyenDroite)111        assertEquals(4 * 28f + 16, p.largeur, 0f)112        assertEquals(300f, p.w, 0f)113        assertTrue(p.estPorte(0, 1)); assertFalse(p.estPorte(1, 1)); assertFalse(p.estPorte(0, 0))114        // sans étages au rôle : 3 logements → 3 niveaux ; 6 → 2 ; 30 → 3 niveaux, 9 travées au plus115        assertEquals(3, PlanFacade.de(3, null, null).niveaux)116        assertEquals(2, PlanFacade.de(6, 0.0, null).niveaux)117        val grand = PlanFacade.de(30, null, "Détaché")118        assertEquals(3, grand.niveaux); assertEquals(9, grand.travees)119        assertFalse(grand.mitoyenGauche)120        assertEquals(6, PlanFacade.de(100, 12.0, null).niveaux)121        val jumele = PlanFacade.de(2, 2.0, "Jumelé")122        assertTrue(jumele.mitoyenGauche); assertFalse(jumele.mitoyenDroite)123    }124125    @Test fun departDuCalculateur() {126        val c = Depart.LIBRE.champs()127        assertEquals("850000", c["prix"]); assertEquals("1800", c["assurances"]); assertEquals("4,5", c["gestionPct"])128        assertEquals("20", c["miseDeFondsPct"]); assertEquals("25", c["amortissementAns"])129        val gros = Depart(3_000_000.0, 12, 14000.0, 20000.0, 2000.0)130        assertEquals("schl", gros.financement())131        assertEquals("5", gros.champs()["gestionPct"]); assertEquals("400", gros.champs()["conciergerieParLogement"])132        assertEquals("15", gros.champs()["miseDeFondsPct"]); assertEquals("40", gros.champs()["amortissementAns"])133        assertEquals("25" to "25", Depart.reglagesFinancement("conventionnel"))134    }135136    @Test fun corpsDeLaDemande() {137        val e = Depart.entree(Depart.LIBRE.champs(), "residentiel", 0.0416, "montreal")!!138        assertEquals(850000.0, e.prix, 0.0); assertEquals(3, e.logements); assertEquals(4.5, e.tauxPct!!, 0.0)139        val json = Decodeur.json.encodeToString(EntreeProForma.serializer(), e)140        assertTrue(json.contains("\"loyersMensuels\":4200.0"))141        assertTrue(json.contains("\"financement\":\"residentiel\""))142        assertTrue(json.contains("\"ville\":\"montreal\""))143        // champs facultatifs absents : aucune clé nulle n'est envoyée144        val sans = Decodeur.json.encodeToString(EntreeProForma.serializer(), Depart.entree(Depart.LIBRE.champs(), "schl", null, null)!!)145        assertFalse(sans.contains("null")); assertFalse(sans.contains("tgaMarche"))146        assertNull(Depart.entree(Depart.LIBRE.champs() + ("prix" to ""), "residentiel", null, null))147        assertNull(Depart.entree(Depart.LIBRE.champs() + ("logements" to "0"), "residentiel", null, null))148    }149150    @Test fun liens() {151        assertEquals("immeuble/66023003702256660000000", Liens.route("valoplex://immeuble/66023003702256660000000"))152        assertEquals("immeuble/66023003702256660000000", Liens.route("https://www.valo-plex.com/immeuble/66023003702256660000000"))153        assertEquals("region/montreal", Liens.route("https://www.valo-plex.com/marche/montreal"))154        assertEquals(Routes.MARCHE, Liens.route("valoplex://marche"))155        assertEquals(Routes.A_VENDRE, Liens.route("https://www.valo-plex.com/a-vendre?region=06"))156        assertEquals(Routes.METHODE, Liens.route("valoplex://methodologie"))157        assertEquals(Routes.CALCULATEUR, Liens.route("valoplex://calculateur"))158        assertNull(Liens.route("valoplex://immeuble/../../etc"))159        assertNull(Liens.route("https://exemple.com/immeuble/66023003702256660000000"))160        assertNull(Liens.route(null))161    }162163    @Test fun listesLocales() {164        fun m(n: Int) = Memo("id$n", "$n, rue Wellington", "Montréal", 3, 900000.0 + n, "ferme")165        var recents = emptyList<Memo>()166        for (n in 1..15) recents = Listes.avecRecent(recents, m(n))167        assertEquals(Listes.MAX_RECENTS, recents.size); assertEquals("id15", recents[0].id)168        recents = Listes.avecRecent(recents, m(10))169        assertEquals("id10", recents[0].id); assertEquals(1, recents.count { it.id == "id10" })170        var favoris = Listes.basculer(emptyList(), m(1))171        assertEquals(1, favoris.size)172        favoris = Listes.rafraichir(favoris, m(1).copy(valeur = 1.0))173        assertEquals(1.0, favoris[0].valeur!!, 0.0)174        assertTrue(Listes.basculer(favoris, m(1)).isEmpty())175        assertEquals(recents, Listes.decoder(Listes.coder(recents)))176        assertTrue(Listes.decoder("pas du json").isEmpty())177    }178}179
Files main
Menu

Theme