Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * PROJECT METADATA8 * -----------------------------------------------------------------------------9 * Project : Immo-Ka Android10 * File : app/src/test/kotlin/com/spboucher/immoka/DoorTest.kt11 * Description : « la porte de la maison s'ouvre » — machine à états,12 * interruption, choix du niveau, pistes du Door Engine 3.013 * (1 220, 800, 300, 140 ms), trajectoire du battant,14 * projection du symbole, scène en fonction du temps (posée15 * sur la photo, pénombre de 30 %, voyage, révélation,16 * effacement).17 * Module : test18 * Repository : https://git.spboucher.ai/immo-ka-android19 * Project Website : https://www.immo-ka.com20 * Created : 2026-11-2921 * Last Modified : 2026-11-2922 *23 * =============================================================================24 * AUTHOR & PROFESSIONAL AFFILIATION25 * =============================================================================26 *27 * Author : Simon-Pierre Boucher28 * Position : Professor of Finance29 * Institution : Université du Québec en Outaouais (UQO)30 * Department : Département des sciences administratives31 * Organization : SP Boucher32 *33 * Website : https://spboucher.ai34 * Git : https://git.spboucher.ai35 *36 * =============================================================================37 * OFFICIAL CONTACT DIRECTORY38 * =============================================================================39 *40 * General : info@spboucher.ai41 * Professional : contact@spboucher.ai42 * Direct : simon@spboucher.ai43 * Research : research@spboucher.ai44 * Development : dev@spboucher.ai45 * Support : support@spboucher.ai46 * Security/Admin : admin@spboucher.ai47 * Notifications : notifications@spboucher.ai48 *49 * Preferred Contact: contact@spboucher.ai50 *51 * =============================================================================52 * COPYRIGHT & INTELLECTUAL PROPERTY53 * =============================================================================54 *55 * Copyright (c) 202656 * Simon-Pierre Boucher57 *58 * All rights reserved where applicable.59 *60 * This file is governed by the applicable project license,61 * copyright notices, institutional agreements and relevant law.62 *63 * Unless expressly authorized by the applicable license or64 * rights holder, copying, redistribution, sublicensing,65 * publication and commercial exploitation are not permitted.66 *67 * Existing third-party rights and notices remain unaffected.68 *69 * =============================================================================70 * CONFIDENTIALITY & SECURITY71 * =============================================================================72 *73 * Classification : Public74 * Distribution : Public repository; use is governed by the project license75 * Security Contact : admin@spboucher.ai76 *77 * Access to this source does not independently grant permission78 * to redistribute or disclose confidential materials.79 *80 * Do not embed credentials, private keys, access tokens,81 * certificates or confidential personal information.82 *83 * =============================================================================84 * LICENSE & MAINTENANCE85 * =============================================================================86 *87 * License : None specified (no license file in this repository)88 * Maintainer : Simon-Pierre Boucher89 * Technical Contact: dev@spboucher.ai90 *91 * =============================================================================92 * END OF SP BOUCHER SOURCE HEADER93 * =============================================================================94 */9596package com.spboucher.immoka9798import com.spboucher.immoka.design.brand.Box99import com.spboucher.immoka.design.brand.BrandGeometry100import com.spboucher.immoka.design.door.BezierEase101import com.spboucher.immoka.design.door.DoorEvent102import com.spboucher.immoka.design.door.DoorLevel103import com.spboucher.immoka.design.door.DoorLevelPolicy104import com.spboucher.immoka.design.door.DoorOrigin105import com.spboucher.immoka.design.door.DoorPreference106import com.spboucher.immoka.design.door.DoorScene107import com.spboucher.immoka.design.door.DoorState108import com.spboucher.immoka.design.door.DoorStateMachine109import com.spboucher.immoka.design.door.SwingPath110import org.junit.Assert.assertEquals111import org.junit.Assert.assertFalse112import org.junit.Assert.assertTrue113import org.junit.Test114115class DoorTest {116 private val source = Box(20f, 600f, 286f, 214f)117 private val hero = Box(0f, 90f, 402f, 320f)118119 @Test fun `machine a etats - le parcours complet`() {120 val m = DoorStateMachine()121 assertEquals(DoorState.CLOSED, m.state)122 for ((e, s) in listOf(DoorEvent.APPEAR to DoorState.IDLE, DoorEvent.TOUCH_DOWN to DoorState.HOVER, DoorEvent.TRIGGER to DoorState.OPENING,123 DoorEvent.PANEL_OPENED to DoorState.OPEN, DoorEvent.REVEAL to DoorState.REVEALING, DoorEvent.EXPAND to DoorState.NAVIGATING,124 DoorEvent.FINISH to DoorState.COMPLETED, DoorEvent.CLOSE to DoorState.CLOSING, DoorEvent.CLOSED to DoorState.CLOSED)) {125 assertTrue("$e", m.send(e)); assertEquals(s, m.state)126 }127 }128129 @Test fun `machine a etats - les transitions non prevues sont refusees`() {130 val m = DoorStateMachine()131 assertFalse(m.send(DoorEvent.REVEAL)); assertFalse(m.send(DoorEvent.FINISH)); assertFalse(m.send(DoorEvent.INTERRUPT))132 assertEquals(DoorState.CLOSED, m.state); assertFalse(m.isRunning)133 m.send(DoorEvent.TRIGGER); assertTrue(m.isRunning)134 assertFalse(m.send(DoorEvent.TOUCH_DOWN)); assertEquals(DoorState.OPENING, m.state)135 assertEquals(22f, DoorState.HOVER.restAngle); assertEquals(40f, DoorState.AJAR.restAngle); assertEquals(86f, DoorState.OPEN.restAngle)136 }137138 @Test fun `interruption et erreur - la navigation a deja eu lieu, on termine`() {139 val m = DoorStateMachine()140 m.send(DoorEvent.TRIGGER); assertTrue(m.send(DoorEvent.INTERRUPT)); assertEquals(DoorState.INTERRUPTED, m.state)141 assertTrue(m.send(DoorEvent.FINISH)); assertEquals(DoorState.COMPLETED, m.state)142 assertTrue(m.send(DoorEvent.RESET)); assertEquals(DoorState.CLOSED, m.state)143 // photo absente : repli sans blocage144 m.send(DoorEvent.TRIGGER); m.send(DoorEvent.PANEL_OPENED); assertTrue(m.send(DoorEvent.FAIL)); assertEquals(DoorState.ERROR, m.state)145 assertTrue(m.send(DoorEvent.FINISH)); assertEquals(DoorState.COMPLETED, m.state)146 // le niveau discret passe de l'ouverture directement à l'extension147 val c = DoorStateMachine(); c.send(DoorEvent.TRIGGER); assertTrue(c.send(DoorEvent.EXPAND)); assertEquals(DoorState.NAVIGATING, c.state)148 }149150 @Test fun `niveau selon la frequence, l'origine et les reglages`() {151 fun lvl(n: Int, o: DoorOrigin = DoorOrigin.CARD, reduce: Boolean = false, p: DoorPreference = DoorPreference.AUTOMATIC) =152 DoorLevelPolicy.level(n, o, reduce, p)153 assertEquals(DoorLevel.SIGNATURE, lvl(0)); assertEquals(DoorLevel.SIGNATURE, lvl(2))154 assertEquals(DoorLevel.STANDARD, lvl(3)); assertEquals(DoorLevel.STANDARD, lvl(9)); assertEquals(DoorLevel.COMPACT, lvl(10))155 assertEquals(DoorLevel.STANDARD, lvl(0, DoorOrigin.FAVORITE)); assertEquals(DoorLevel.COMPACT, lvl(1, DoorOrigin.MAP_PILL))156 assertEquals(DoorLevel.NONE, lvl(0, DoorOrigin.DIRECT_LINK)); assertEquals(DoorLevel.NONE, lvl(0, p = DoorPreference.OFF))157 assertEquals(DoorLevel.REDUCED, lvl(0, reduce = true)); assertEquals(DoorLevel.COMPACT, lvl(0, p = DoorPreference.DISCREET))158 // « Aucune » l'emporte sur les animations réduites ; un réglage inconnu vaut « Automatique »159 assertEquals(DoorLevel.NONE, lvl(0, reduce = true, p = DoorPreference.OFF)); assertEquals(DoorPreference.AUTOMATIC, DoorPreference.of("x"))160 }161162 @Test fun `pistes du Door Engine 3_0`() {163 assertEquals(1.22, DoorLevel.SIGNATURE.total, 1e-9); assertEquals(0.80, DoorLevel.STANDARD.total, 1e-9)164 assertEquals(0.30, DoorLevel.COMPACT.total, 1e-9); assertEquals(0.14, DoorLevel.REDUCED.total, 1e-9); assertEquals(0.0, DoorLevel.NONE.total, 0.0)165 assertEquals(0.66, DoorLevel.SIGNATURE.swing, 1e-9); assertEquals(0.40, DoorLevel.STANDARD.swing, 1e-9)166 assertEquals(84f, DoorLevel.SIGNATURE.angle); assertEquals(0f, DoorLevel.COMPACT.angle)167 // la fiche est poussée pendant le pivotement : elle n'attend pas la fin de l'animation168 for (l in listOf(DoorLevel.SIGNATURE, DoorLevel.STANDARD)) {169 val p = l.plan170 assertTrue(p.pushAt > p.swingStart && p.pushAt < p.swingEnd); assertTrue(p.revealEnd <= p.total && p.travelEnd <= p.total)171 }172 assertEquals(0.378, DoorLevel.SIGNATURE.plan.pushAt, 1e-9); assertEquals(0.23, DoorLevel.STANDARD.plan.pushAt, 1e-9)173 }174175 @Test fun `trajectoire du battant et courbes`() {176 assertEquals(0.0, SwingPath.value(-1.0), 0.0); assertEquals(1.0, SwingPath.value(2.0), 0.0)177 assertEquals(0.035, SwingPath.value(0.10), 1e-9); assertEquals(0.56, SwingPath.value(0.5), 1e-9)178 var prev = -1.0179 for (i in 0..100) { val v = SwingPath.value(i / 100.0); assertTrue(v >= prev); prev = v }180 assertEquals(0.0, BezierEase.door(0.0), 0.0); assertEquals(1.0, BezierEase.door(1.0), 0.0)181 assertTrue(BezierEase.arrive(0.5) > 0.5)182 // la courbe qui « se pose » dépasse légèrement sa cible avant d'y revenir183 assertTrue((1..99).any { BezierEase.settle(it / 100.0) > 1.0 })184 }185186 @Test fun `projection du symbole`() {187 assertEquals(18f, BrandGeometry.panelWidth(0f), 1e-4f)188 // à 40° exactement, le logo garde son battant dessiné à la main (13,5) ; ailleurs, la projection189 assertEquals(13.5f, BrandGeometry.panelWidth(40f), 1e-4f)190 assertEquals(12.6f, BrandGeometry.panelWidth(40.01f), 0.1f)191 assertEquals(3.3f, BrandGeometry.panelWidth(84f), 0.15f)192 var prev = 99f193 for (a in 0..90) { if (a == 40) continue; val w = BrandGeometry.panelWidth(a.toFloat()); assertTrue(w <= prev); prev = w }194 val e = BrandGeometry.freeEdge(60f)195 assertTrue(e.top > 0 && e.bottom > 0 && e.top < e.bottom)196 assertEquals(0.30f, BrandGeometry.panelShade(90f), 1e-6f); assertEquals(0f, BrandGeometry.panelShade(0f), 0f)197 assertEquals(0.6f, BrandGeometry.opening.width / BrandGeometry.opening.height, 1e-6f)198 // la silhouette se referme sur le faîte199 assertEquals(14, BrandGeometry.silhouette.size)200 }201202 @Test fun `scene - posee sur la photo, penombre, voyage, revelation, effacement`() {203 val l = DoorLevel.SIGNATURE204 val t0 = DoorScene.at(0.0, l, source, hero)205 assertEquals(source, t0.frame); assertEquals(0f, t0.house); assertEquals(0f, t0.angle); assertEquals(0f, t0.veil); assertEquals(1f, t0.rootOpacity)206 // la maison est posée : elle tient en entier dans la photo, la photo autour est à 30 % de pénombre207 val posed = DoorScene.at(0.26, l, source, hero)208 assertEquals(1f, posed.house, 1e-3f); assertEquals(0.30f, posed.dim, 1e-3f); assertEquals(1f, posed.houseScale, 1e-3f)209 val hb = DoorScene.houseBox(source)210 assertTrue(hb.left >= source.left && hb.right <= source.right && hb.top >= source.top && hb.bottom <= source.bottom)211 // la béquille s'abaisse puis revient212 assertTrue(DoorScene.at(0.2, l, source, hero).lever < -20); assertEquals(0f, DoorScene.at(0.31, l, source, hero).lever)213 // le battant pivote jusqu'à 84°, la fiche est poussée voile plein214 assertEquals(84f, DoorScene.at(0.84, l, source, hero).angle, 1e-3f)215 assertEquals(1f, DoorScene.at(l.plan.pushAt, l, source, hero).veil, 1e-3f); assertEquals(0f, DoorScene.at(0.7, l, source, hero).veil, 1e-3f)216 // la photo voyage jusqu'à la galerie, l'embrasure s'étend, la maison s'efface217 val end = DoorScene.at(1.10, l, source, hero)218 assertEquals(hero.left, end.frame.left, 0.01f); assertEquals(hero.width, end.frame.width, 0.01f)219 assertEquals(1f, end.reveal, 1e-3f); assertEquals(0f, end.house, 1e-3f); assertEquals(0f, end.dim, 1e-3f); assertEquals(0f, end.corner, 1e-3f)220 assertEquals(0f, DoorScene.at(1.22, l, source, hero).rootOpacity, 1e-3f)221 val mid = DoorScene.at(0.7, l, source, hero)222 assertTrue(mid.frame.top < source.top && mid.frame.top > hero.top)223 }224225 @Test fun `scene - niveaux discret et reduit`() {226 val c = DoorScene.at(0.12, DoorLevel.COMPACT, source, hero)227 assertEquals(0f, c.house); assertEquals(0f, c.angle); assertEquals(1f, c.reveal); assertTrue(c.frame.top < source.top)228 val r = DoorScene.at(0.07, DoorLevel.REDUCED, source, hero)229 // aucun déplacement : seul un fondu accompagne la fiche230 assertEquals(hero, r.frame); assertEquals(0.5f, r.veil, 1e-3f); assertEquals(0f, r.rootOpacity)231 // l'appui : la photo se resserre à 0,985 au plus puis revient232 val pressed = (0..14).minOf { DoorScene.at(it / 100.0, DoorLevel.SIGNATURE, source, hero).press }233 assertEquals(0.985f, pressed, 1e-3f); assertEquals(1f, DoorScene.at(0.14, DoorLevel.SIGNATURE, source, hero).press, 1e-3f)234 }235}236