commonTest.number.range.TestNumberRangeViewModel.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of instantsearch-core Show documentation
Show all versions of instantsearch-core Show documentation
InstantSearch Android is a library providing widgets and helpers to help you build the best instant-search experience on Android with Algolia. It is built on top of Algolia's Kotlin API Client to provide you a high-level solution to quickly build various search interfaces.
package number.range
import com.algolia.instantsearch.core.number.range.NumberRangeViewModel
import com.algolia.instantsearch.core.number.range.Range
import shouldEqual
import kotlin.test.Test
class TestNumberRangeViewModel {
@Test
fun computeShouldNotCoerceIfNoBounds() {
val viewModel = NumberRangeViewModel()
val range = Range(1..5)
viewModel.eventRange.subscribe { viewModel.range.value = it }
viewModel.coerce(range)
viewModel.range.value shouldEqual range
}
@Test
fun computeShouldCoerceMin() {
val bounds = Range(0f..10f)
val range = Range(-1f..9f)
val viewModel = NumberRangeViewModel(bounds = bounds)
viewModel.eventRange.subscribe { viewModel.range.value = it }
viewModel.coerce(range)
viewModel.range.value shouldEqual Range(bounds.min, range.max)
}
@Test
fun computeShouldCoerceMax() {
val bounds = Range(0L..10L)
val range = Range(0L..11L)
val viewModel = NumberRangeViewModel(bounds = bounds)
viewModel.eventRange.subscribe { viewModel.range.value = it }
viewModel.coerce(range)
viewModel.range.value shouldEqual Range(range.min, bounds.max)
}
@Test
fun changeMinShouldCoerceRange() {
val viewModel = NumberRangeViewModel(bounds = Range(0.5..10.5))
val range = Range(1.5..9.5)
viewModel.eventRange.subscribe { viewModel.range.value = it }
viewModel.coerce(range)
viewModel.range.value shouldEqual range
viewModel.bounds.value = Range(6.5..10.5)
viewModel.range.value shouldEqual Range(6.5..9.5)
}
@Test
fun changeMaxShouldCoerceRange() {
val viewModel = NumberRangeViewModel(bounds = Range(0..10))
val range = Range(1..9)
viewModel.eventRange.subscribe { viewModel.range.value = it }
viewModel.coerce(range)
viewModel.range.value shouldEqual range
viewModel.bounds.value = Range(0..8)
viewModel.range.value shouldEqual Range(1..8)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy