diff options
author | Allan Wang <me@allanwang.ca> | 2017-08-05 23:10:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-05 23:10:28 -0700 |
commit | 187d8e64dc7189f63707d154166867084662dbe3 (patch) | |
tree | 372503ac381f12a905a0608519228f9792bb1c0b /core/src/test | |
parent | caaa5653deda0640a475d0ccad6daeb7852502f7 (diff) | |
download | kau-187d8e64dc7189f63707d154166867084662dbe3.tar.gz kau-187d8e64dc7189f63707d154166867084662dbe3.tar.bz2 kau-187d8e64dc7189f63707d154166867084662dbe3.zip |
Create debounce and update searchview (#27)
* Prepare version
* Create debounce base
* Add debouncer and fix transition crash
* Add debounce docs
* Update links
* Update searchview docs
* Test without a ref
* Add links to core components
* Update links
* Update to bullet points
* Test core md
* Test slash
* Test slash
* Specify implemented dependencies
Diffstat (limited to 'core/src/test')
-rw-r--r-- | core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt b/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt new file mode 100644 index 0000000..12bc5a4 --- /dev/null +++ b/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt @@ -0,0 +1,53 @@ +package ca.allanwang.kau.kotlin + +import org.jetbrains.anko.doAsync +import org.junit.Test +import kotlin.test.assertEquals + +/** + * Created by Allan Wang on 2017-08-05. + */ +class DebounceTest { + + @Test + fun basic() { + var i = 0 + val debounce = debounce(20) { i++ } + assertEquals(0, i, "i should start as 0") + (1..5).forEach { debounce() } + Thread.sleep(50) + assertEquals(1, i, "Debouncing did not cancel previous requests") + } + + @Test + fun basicExtension() { + var i = 0 + val increment: () -> Unit = { i++ } + (1..5).forEach { increment() } + assertEquals(5, i, "i should be 5") + val debounce = increment.debounce(50) + (6..10).forEach { debounce() } + assertEquals(5, i, "i should not have changed") + Thread.sleep(100) + assertEquals(6, i, "i should increment to 6") + } + + @Test + fun multipleDebounces() { + var i = 0 + val debounce = debounce<Int>(10) { i += it } + debounce(1) //ignore -> i = 0 + Thread.sleep(5) + assertEquals(0, i) + debounce(2) //accept -> i = 2 + Thread.sleep(15) + assertEquals(2, i) + debounce(4) //ignore -> i = 2 + Thread.sleep(5) + assertEquals(2, i) + debounce(8) //accept -> i = 10 + Thread.sleep(15) + assertEquals(10, i) + } + +}
\ No newline at end of file |