Changed initialize to reset.

This commit is contained in:
Erik C. Thauvin 2020-07-27 15:38:03 -07:00
parent 61706679e9
commit ae134efac4
2 changed files with 9 additions and 5 deletions

View file

@ -81,19 +81,19 @@ class ReadingTime @JvmOverloads constructor(
var text: String = text
set(value) {
initialize()
reset(value != text)
field = value
}
var wpm: Int = wpm
set(value) {
initialize()
reset(value != wpm)
field = value
}
var excludeImages: Boolean = excludeImages
set(value) {
initialize()
reset(value != excludeImages)
field = value
}
@ -138,7 +138,7 @@ class ReadingTime @JvmOverloads constructor(
return time
}
private fun initialize() {
readTime = INVALID
private fun reset(isChanged: Boolean) {
if (isChanged) readTime = INVALID
}
}

View file

@ -98,5 +98,9 @@ class ReadingTimeTest {
rt.text = "This is a test."
rt.postfix = ""
assertEquals("1", rt.calcReadingTime())
rt.text = ""
assertEquals("0", rt.calcReadingTime())
assertEquals( 0.0, rt.calcReadingTimeInSec())
}
}