mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-27 14:40:22 +00:00
Add helper text when dragging filter at a low velocity.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package org.thoughtcrime.securesms.conversationlist.chatfilter
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
class ProgressVelocityTrackerTest {
|
||||
|
||||
@Test
|
||||
fun `When I calculate velocity, then I expect 0f`() {
|
||||
val testSubject = ProgressVelocityTracker(3)
|
||||
val actual = testSubject.calculateVelocity()
|
||||
assertEquals("Velocity of an empty tracker should be 0f", 0f, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given a single entry, when I calculate velocity, then I expect 0f`() {
|
||||
val testSubject = ProgressVelocityTracker(3)
|
||||
testSubject.submitProgress(0f, 0.milliseconds)
|
||||
val actual = testSubject.calculateVelocity()
|
||||
assertEquals("Velocity of a tracker with a single element should be 0f", 0f, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given 0f to 1f in 1 second, when I calculate velocity, then I expect a rate of 100 percent per second`() {
|
||||
val testSubject = ProgressVelocityTracker(3)
|
||||
testSubject.submitProgress(0f, 0.milliseconds)
|
||||
testSubject.submitProgress(1f, 1.seconds)
|
||||
val actual = testSubject.calculateVelocity()
|
||||
assertEquals("If we complete the progress in 1 second, then we should have a rate of 1 per thousand milliseconds", 1f, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given 5 entries, when I calculate velocity, then I expect a rate based off the last 3 entries`() {
|
||||
val testSubject = ProgressVelocityTracker(3)
|
||||
val entries = listOf(
|
||||
0.0f to 0.seconds,
|
||||
0.1f to 10.milliseconds,
|
||||
0.2f to 20.milliseconds,
|
||||
0.3f to 40.milliseconds,
|
||||
0.4f to 80.milliseconds
|
||||
)
|
||||
|
||||
entries.forEach { (progress, duration) -> testSubject.submitProgress(progress, duration) }
|
||||
|
||||
val velocityA = testSubject.calculateVelocity()
|
||||
|
||||
testSubject.clear()
|
||||
|
||||
entries.drop(2).forEach { (progress, duration) -> testSubject.submitProgress(progress, duration) }
|
||||
|
||||
val velocityB = testSubject.calculateVelocity()
|
||||
|
||||
assertEquals("Expected the velocities to match.", velocityA, velocityB)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.thoughtcrime.securesms.conversationlist.chatfilter
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class RingBufferTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun `Given a negative capacity, when I call the constructor, then I expect an IllegalArgumentException`() {
|
||||
RingBuffer<Int>(-1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given I enqueue more items than my capacity, when I getSize, then I expect my initial capacity`() {
|
||||
val capacity = 10
|
||||
val testSubject = RingBuffer<Int>(capacity)
|
||||
|
||||
(1..(capacity * 2)).forEach {
|
||||
testSubject.add(it)
|
||||
}
|
||||
|
||||
assertEquals("Capacity should never exceed $capacity items.", capacity, testSubject.size())
|
||||
assertEquals("First item should be 10", 11, testSubject[0])
|
||||
assertEquals("Last item should be 20", 20, testSubject[testSubject.size() - 1])
|
||||
}
|
||||
|
||||
@Test(expected = ArrayIndexOutOfBoundsException::class)
|
||||
fun `when I get, then I expect an ArrayIndexOutOfBoundsException`() {
|
||||
val testSubject = RingBuffer<Int>(10)
|
||||
testSubject[0]
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given some added elements, when I get, then I expect the element`() {
|
||||
val testSubject = RingBuffer<Int>(10)
|
||||
val expected = 1
|
||||
testSubject.add(expected)
|
||||
val actual = testSubject[0]
|
||||
assertEquals("Expected get to return $expected", expected, actual)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user