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/CostTest.kt11 * Description : lecture des réponses réelles de la méthode du coût12 * (préremplissage et calcul), relevées par l'app iOS. Aucun13 * appel au service : le calcul (POST) n'est jamais lancé par14 * un test.15 * Module : test16 * Repository : https://git.spboucher.ai/vrai-prix-android17 * Project Website : https://www.vrai-prix.com18 * Created : 2026-11-2919 * Last Modified : 2026-11-2920 *21 * =============================================================================22 * AUTHOR & PROFESSIONAL AFFILIATION23 * =============================================================================24 *25 * Author : Simon-Pierre Boucher26 * Position : Professor of Finance27 * Institution : Université du Québec en Outaouais (UQO)28 * Department : Département des sciences administratives29 * Organization : SP Boucher30 *31 * Website : https://spboucher.ai32 * Git : https://git.spboucher.ai33 *34 * =============================================================================35 * OFFICIAL CONTACT DIRECTORY36 * =============================================================================37 *38 * General : info@spboucher.ai39 * Professional : contact@spboucher.ai40 * Direct : simon@spboucher.ai41 * Research : research@spboucher.ai42 * Development : dev@spboucher.ai43 * Support : support@spboucher.ai44 * Security/Admin : admin@spboucher.ai45 * Notifications : notifications@spboucher.ai46 *47 * Preferred Contact: dev@spboucher.ai48 *49 * =============================================================================50 * COPYRIGHT & INTELLECTUAL PROPERTY51 * =============================================================================52 *53 * Copyright (c) 202654 * Simon-Pierre Boucher55 *56 * All rights reserved where applicable.57 *58 * This file is governed by the applicable project license,59 * copyright notices, institutional agreements and relevant law.60 *61 * Unless expressly authorized by the applicable license or62 * rights holder, copying, redistribution, sublicensing,63 * publication and commercial exploitation are not permitted.64 *65 * Existing third-party rights and notices remain unaffected.66 *67 * =============================================================================68 * CONFIDENTIALITY & SECURITY69 * =============================================================================70 *71 * Classification : Public72 * Distribution : Public repository; use is governed by the project license73 * Security Contact : admin@spboucher.ai74 *75 * Access to this source does not independently grant permission76 * to redistribute or disclose confidential materials.77 *78 * Do not embed credentials, private keys, access tokens,79 * certificates or confidential personal information.80 *81 * =============================================================================82 * LICENSE & MAINTENANCE83 * =============================================================================84 *85 * License : None specified (no license file in this repository)86 * Maintainer : Simon-Pierre Boucher87 * Technical Contact: dev@spboucher.ai88 *89 * =============================================================================90 * END OF SP BOUCHER SOURCE HEADER91 * =============================================================================92 */9394package com.spboucher.vraiprix9596import com.spboucher.vraiprix.core.json.J97import com.spboucher.vraiprix.core.net.CostEstimate98import com.spboucher.vraiprix.core.net.CostPrefill99import org.junit.Assert.assertEquals100import org.junit.Assert.assertFalse101import org.junit.Assert.assertNotNull102import org.junit.Assert.assertNull103import org.junit.Assert.assertTrue104import org.junit.Test105106class CostTest {107 private fun fixture(name: String): J {108 val text = javaClass.getResource("/fixtures/$name")!!.readText()109 return J.parse(text)!!110 }111112 @Test113 fun prefillKeepsTheInputAndNeverSaves() {114 val p = CostPrefill.from(fixture("cost-prop.json"))115 val body = J.parse(p.body)!!116 assertEquals(listOf("input", "save"), body.keys)117 assertEquals(false, body["save"].bool)118 assertEquals("property", body["input"]["mode"].text)119 assertEquals("66023954154278060000000", body["input"]["propertyId"].text)120 assertEquals(4257.0, body["input"]["building"]["grossFloorAreaSqft"].double!!, 0.0)121 // l'entrée est renvoyée telle quelle : rien d'autre que le préremplissage du service122 assertEquals(fixture("cost-prop.json")["input"].el, body["input"].el)123 assertEquals(10, p.missing.size)124 assertTrue("kitchenQuality" in p.missing)125 assertEquals("Montréal", p.locationName)126 val r = p.readings!!127 assertEquals(3283000.0, r.hybrid!!, 0.0)128 assertEquals(3108500.0, r.hedonic!!, 0.0)129 assertEquals(3607200.0, r.comparables!!, 0.0)130 assertEquals(3193900.0, r.rollValue!!, 0.0)131 assertNull(r.askingPrice)132 }133134 @Test(expected = IllegalArgumentException::class)135 fun prefillWithoutInputIsRefused() {136 CostPrefill.from(J.parse("""{"missing":[]}""")!!)137 }138139 @Test140 fun estimateReadsTheAggregates() {141 val e = CostEstimate.from(fixture("cost-est.json"))142 assertEquals("1.0.0", e.methodVersion)143 assertEquals("2026-11-26", e.priceDate)144 assertEquals(515962.0, e.directCost!!, 0.0)145 assertEquals(68623.0, e.indirectCost!!, 0.0)146 assertEquals(40921.0, e.contractorOverhead!!, 0.0)147 assertEquals(50040.0, e.contractorProfit!!, 0.0)148 assertEquals(17538.0, e.contingency!!, 0.0)149 assertEquals(693084.0, e.replacementCostNew!!, 0.0)150 assertEquals(638829.0, e.rangeLow!!, 0.0)151 assertEquals(747339.0, e.rangeHigh!!, 0.0)152 assertEquals(162.81, e.perSqft!!, 1e-9)153 assertEquals(1752.48, e.perM2!!, 1e-9)154 assertEquals(1451500.0, e.landValue!!, 0.0)155 assertEquals(1520808.0, e.costApproachValue!!, 0.0)156 val d = e.depreciation!!157 assertEquals(89.0, d.effectiveAge!!, 0.0)158 assertEquals(60.0, d.economicLife!!, 0.0)159 assertEquals(90.0, d.physicalPct!!, 0.0)160 assertEquals(623776.0, d.total!!, 0.0)161 assertEquals(69308.0, d.depreciatedImprovementValue!!, 0.0)162 // la valeur par le coût est le bâtiment déprécié plus le terrain : ce que la réponse dit, pas un calcul de l'app163 assertEquals(e.costApproachValue!!, d.depreciatedImprovementValue!! + e.landValue!!, 0.5)164 val c = e.confidence!!165 assertEquals("B", c.letter)166 assertEquals(73.0, c.total!!, 0.0)167 assertEquals(2, c.notesFr.size)168 assertFalse(e.categories.isEmpty())169 val site = e.categories.first { it.category == "site" }170 assertEquals("Préparation du site", site.label)171 assertEquals(8133.0, site.adjusted!!, 0.0)172 assertTrue(e.indirect.any { it.key == "plansPct" && it.amount == 15479.0 })173 assertNotNull(e.categories.maxByOrNull { it.adjusted ?: 0.0 })174 }175176 @Test177 fun estimateToleratesMissingBlocks() {178 val e = CostEstimate.from(J.parse("""{"costApproachValue": 100000}""")!!)179 assertEquals(100000.0, e.costApproachValue!!, 0.0)180 assertNull(e.depreciation)181 assertNull(e.confidence)182 assertTrue(e.categories.isEmpty())183 }184}185