SPB Git

Repository Public

PropertyReadingTest.kt 8.1 KB 187 lines kotlin

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/PropertyReadingTest.kt11 * Description      : règles de la fiche d'une propriété sur des réponses12 *                    réelles : le prix lu contre la valeur (seulement face à13 *                    une valeur ferme), le cadrage de la carte des comparables,14 *                    l'écriture du champ « et si ».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-12-0120 *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.model.Comparables98import com.spboucher.vraiprix.core.model.PricePosition99import com.spboucher.vraiprix.core.model.Property100import com.spboucher.vraiprix.features.map.MapLayers101import com.spboucher.vraiprix.features.property.ThousandsTransformation102import com.spboucher.vraiprix.features.property.priceReading103import org.junit.Assert.assertEquals104import org.junit.Assert.assertNull105import org.junit.Assert.assertTrue106import org.junit.Test107108class PropertyReadingTest {109    private fun fixture(name: String): J = J.parse(javaClass.getResource("/fixtures/$name")!!.readText())!!110    private fun property(name: String): Property = Property.from(fixture(name))111112    @Test113    fun askedPriceIsReadAsTheEngineComparedIt() {114        val r = priceReading(property("v3-fiche-inscrite.json"))!!115        assertTrue(r.asked)116        assertEquals(699172.0, r.amount, 0.0)   // le prix ramené, pas le prix demandé (714 900 $)117        assertEquals(PricePosition.DANS, r.position)118        assertEquals(5.2, r.gapPct!!, 1e-9)119    }120121    @Test122    fun lastMarketSaleIsReadBroughtToTheValueDate() {123        val p = property("v3-fiche-valeur.json")124        val r = priceReading(p)!!125        assertEquals(false, r.asked)126        assertEquals(597000.0, r.amount, 0.0)127        assertEquals(PricePosition.DANS, r.position)128        assertEquals((597000.0 / 575600.0 - 1) * 100, r.gapPct!!, 1e-9)129    }130131    @Test132    fun noPriceIsReadWithoutAFirmValue() {133        assertNull(priceReading(property("v3-fiche-ordre.json")))134        assertNull(priceReading(property("v3-fiche-chalet.json")))135        // une abstention a une dernière vente ramenée : elle n'est située face à rien136        assertNull(priceReading(property("v3-fiche-abstention.json")))137        assertNull(priceReading(property("v3-fiche-hors-champ.json")))138    }139140    @Test141    fun saleOutsideTheIntervalTakesItsSideFromTheBounds() {142        val p = property("v3-fiche-valeur.json")143        val a = p.valeur.amounts!!144        fun with(ramene: Double, dans: Boolean?) = priceReading(p.copy(derniereVente = p.derniereVente!!.copy(prixRamene = ramene, dansIntervalle = dans)))!!145        assertEquals(PricePosition.AU_DESSUS, with(a.high + 1, false).position)146        assertEquals(PricePosition.SOUS, with(a.low - 1, false).position)147        assertEquals(PricePosition.DANS, with(a.high, null).position)   // bornes comprises148        assertEquals(PricePosition.DANS, with(a.low, null).position)149        // une vente hors marché n'est jamais située150        assertNull(priceReading(p.copy(derniereVente = p.derniereVente!!.copy(deMarche = false))))151    }152153    @Test154    fun comparablesFrameHoldsTheSubjectAndEverySale() {155        val p = property("v3-fiche-valeur.json")156        val all = Comparables.from(fixture("v3-comparables.json")).items157        val comps = MapLayers.located(all)158        assertEquals(6, comps.size)159        // les numéros sont ceux de la liste, pas un nouveau compte160        assertTrue(comps.all { (n, x) -> all[n - 1] === x })161        val frame = MapLayers.frame(p.lat!!, p.lng!!, all)162        assertTrue(frame.contains(p.lat!!, p.lng!!))163        for ((_, c) in comps) assertTrue(frame.contains(c.lat!!, c.lng!!))164    }165166    @Test167    fun comparablesFrameOfALonePointDoesNotOverZoom() {168        val frame = MapLayers.frame(46.85, -71.38, emptyList())169        // au moins 130 m de haut environ : une propriété seule ne donne pas un zoom excessif170        assertTrue(frame.latSpan >= 0.0011 && frame.lngSpan >= 0.0016)171        assertEquals(46.85, (frame.south + frame.north) / 2, 1e-9)172        assertEquals(-71.38, (frame.west + frame.east) / 2, 1e-9)173    }174175    @Test176    fun thousandsAreSeparatedOnScreenOnly() {177        val nb = " "178        assertEquals("650${nb}000", ThousandsTransformation.format("650000"))179        assertEquals("1${nb}250${nb}000", ThousandsTransformation.format("1250000"))180        assertEquals("999", ThousandsTransformation.format("999"))181        assertEquals("", ThousandsTransformation.format(""))182        assertEquals(0, ThousandsTransformation.spacesBefore(3, 6))183        assertEquals(1, ThousandsTransformation.spacesBefore(4, 6))184        assertEquals(2, ThousandsTransformation.spacesBefore(7, 7))185    }186}187
Files main
Menu

Theme