Cotton code
51 lines · 2.1 KB · KotlinRaw
package com.cottondb.messages.chatimport org.junit.Assert.assertEqualsimport org.junit.Test/** * The speed meter's pictures figure (FEEDBACK 23 Nov item 3: opening a chat, pictures take 1 to 2 seconds to appear): * from the tap that opens a chat, or a scroll coming to rest, to the moment every picture tile on screen holds its * picture. Said once per measure; a measure whose tiles all left the screen undrawn is dropped, never said. */class PictureTilesSpeedTest {    private var clock = 0L    private val said = mutableListOf<Triple<Long, Int, String>>()    private val tiles = ChatSpeed.Tiles(now = { clock }, say = { ms, n, from -> said += Triple(ms, n, from) })    @Test    fun the_figure_ends_when_the_last_tile_on_screen_is_drawn() {        clock = 100        tiles.since(100, "tap")        tiles.shown("msg:a:0"); tiles.shown("msg:a:1"); tiles.shown("msg:b:0")        clock = 400; tiles.drawn("msg:a:0")        clock = 900; tiles.drawn("msg:b:0")        assertEquals(emptyList<Triple<Long, Int, String>>(), said)        clock = 1300; tiles.drawn("msg:a:1")        assertEquals(listOf(Triple(1200L, 3, "tap")), said)        // Said once: a tile drawn later starts nothing by itself.        tiles.shown("msg:c:0"); clock = 1500; tiles.drawn("msg:c:0")        assertEquals(1, said.size)    }    @Test    fun a_scroll_at_rest_with_tiles_waiting_measures_from_its_stop() {        tiles.shown("msg:old:0")        clock = 5000; tiles.rested()        clock = 5750; tiles.drawn("msg:old:0")        assertEquals(listOf(Triple(750L, 1, "scroll_rest")), said)        // Nothing waiting when the scroll stops: nothing to measure.        clock = 6000; tiles.rested()        assertEquals(1, said.size)    }    @Test    fun tiles_that_leave_the_screen_undrawn_drop_the_measure() {        tiles.since(0, "tap")        tiles.shown("msg:a:0"); tiles.shown("msg:a:1")        clock = 300; tiles.drawn("msg:a:0")        tiles.gone("msg:a:1")        clock = 900; tiles.shown("msg:z:0"); tiles.drawn("msg:z:0")        assertEquals(emptyList<Triple<Long, Int, String>>(), said)    }}