GlucoseValueExtensionKtTest
This commit is contained in:
parent
f17b37e8df
commit
54735af1ec
3 changed files with 66 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
|||
package info.nightscout.core.extensions
|
||||
|
||||
import info.nightscout.core.main.R
|
||||
import info.nightscout.database.entities.GlucoseValue
|
||||
import info.nightscout.interfaces.Constants
|
||||
import info.nightscout.interfaces.GlucoseUnit
|
||||
|
@ -31,3 +32,16 @@ fun InMemoryGlucoseValue.valueToUnitsString(units: GlucoseUnit): String =
|
|||
if (units == GlucoseUnit.MGDL) DecimalFormatter.to0Decimal(recalculated)
|
||||
else DecimalFormatter.to1Decimal(recalculated * Constants.MGDL_TO_MMOLL)
|
||||
|
||||
fun GlucoseValue.TrendArrow.directionToIcon(): Int =
|
||||
when (this) {
|
||||
GlucoseValue.TrendArrow.TRIPLE_DOWN -> R.drawable.ic_invalid
|
||||
GlucoseValue.TrendArrow.DOUBLE_DOWN -> R.drawable.ic_doubledown
|
||||
GlucoseValue.TrendArrow.SINGLE_DOWN -> R.drawable.ic_singledown
|
||||
GlucoseValue.TrendArrow.FORTY_FIVE_DOWN -> R.drawable.ic_fortyfivedown
|
||||
GlucoseValue.TrendArrow.FLAT -> R.drawable.ic_flat
|
||||
GlucoseValue.TrendArrow.FORTY_FIVE_UP -> R.drawable.ic_fortyfiveup
|
||||
GlucoseValue.TrendArrow.SINGLE_UP -> R.drawable.ic_singleup
|
||||
GlucoseValue.TrendArrow.DOUBLE_UP -> R.drawable.ic_doubleup
|
||||
GlucoseValue.TrendArrow.TRIPLE_UP -> R.drawable.ic_invalid
|
||||
GlucoseValue.TrendArrow.NONE -> R.drawable.ic_invalid
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package info.nightscout.core.extensions
|
||||
|
||||
import info.nightscout.core.main.R
|
||||
import info.nightscout.database.entities.GlucoseValue
|
||||
|
||||
fun GlucoseValue.TrendArrow.directionToIcon(): Int {
|
||||
return when {
|
||||
this == GlucoseValue.TrendArrow.DOUBLE_DOWN -> R.drawable.ic_doubledown
|
||||
this == GlucoseValue.TrendArrow.SINGLE_DOWN -> R.drawable.ic_singledown
|
||||
this == GlucoseValue.TrendArrow.FORTY_FIVE_DOWN -> R.drawable.ic_fortyfivedown
|
||||
this == GlucoseValue.TrendArrow.FLAT -> R.drawable.ic_flat
|
||||
this == GlucoseValue.TrendArrow.FORTY_FIVE_UP -> R.drawable.ic_fortyfiveup
|
||||
this == GlucoseValue.TrendArrow.SINGLE_UP -> R.drawable.ic_singleup
|
||||
this == GlucoseValue.TrendArrow.DOUBLE_UP -> R.drawable.ic_doubleup
|
||||
this == GlucoseValue.TrendArrow.NONE -> R.drawable.ic_invalid
|
||||
else -> R.drawable.ic_invalid
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package info.nightscout.core.extensions
|
||||
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.core.main.R
|
||||
import info.nightscout.database.entities.GlucoseValue
|
||||
import info.nightscout.interfaces.GlucoseUnit
|
||||
import info.nightscout.interfaces.iob.InMemoryGlucoseValue
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class GlucoseValueExtensionKtTest : TestBaseWithProfile() {
|
||||
|
||||
private val glucoseValue = GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = 1514766900000, sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT)
|
||||
private val inMemoryGlucoseValue = InMemoryGlucoseValue(1000, 100.0, sourceSensor = GlucoseValue.SourceSensor.UNKNOWN)
|
||||
@Test
|
||||
fun valueToUnitsString() {
|
||||
Assertions.assertEquals("100", glucoseValue.valueToUnitsString(GlucoseUnit.MGDL))
|
||||
Assertions.assertEquals("5.6", glucoseValue.valueToUnitsString(GlucoseUnit.MMOL))
|
||||
}
|
||||
@Test
|
||||
fun inMemoryValueToUnitsString() {
|
||||
Assertions.assertEquals("100", inMemoryGlucoseValue.valueToUnitsString(GlucoseUnit.MGDL))
|
||||
Assertions.assertEquals("5.6", inMemoryGlucoseValue.valueToUnitsString(GlucoseUnit.MMOL))
|
||||
}
|
||||
@Test
|
||||
fun inMemoryValueToUnits() {
|
||||
Assertions.assertEquals(100.0, inMemoryGlucoseValue.valueToUnits(GlucoseUnit.MGDL))
|
||||
Assertions.assertEquals(5.55, inMemoryGlucoseValue.valueToUnits(GlucoseUnit.MMOL), 0.01)
|
||||
}
|
||||
@Test
|
||||
fun directionToIcon() {
|
||||
Assertions.assertEquals(R.drawable.ic_flat, glucoseValue.trendArrow.directionToIcon())
|
||||
glucoseValue.trendArrow = GlucoseValue.TrendArrow.NONE
|
||||
Assertions.assertEquals(R.drawable.ic_invalid, glucoseValue.trendArrow.directionToIcon())
|
||||
glucoseValue.trendArrow = GlucoseValue.TrendArrow.TRIPLE_DOWN
|
||||
Assertions.assertEquals(R.drawable.ic_invalid, glucoseValue.trendArrow.directionToIcon())
|
||||
glucoseValue.trendArrow = GlucoseValue.TrendArrow.TRIPLE_UP
|
||||
Assertions.assertEquals(R.drawable.ic_invalid, glucoseValue.trendArrow.directionToIcon())
|
||||
glucoseValue.trendArrow = GlucoseValue.TrendArrow.DOUBLE_DOWN
|
||||
Assertions.assertEquals(R.drawable.ic_doubledown, glucoseValue.trendArrow.directionToIcon())
|
||||
glucoseValue.trendArrow = GlucoseValue.TrendArrow.SINGLE_DOWN
|
||||
Assertions.assertEquals(R.drawable.ic_singledown, glucoseValue.trendArrow.directionToIcon())
|
||||
glucoseValue.trendArrow = GlucoseValue.TrendArrow.FORTY_FIVE_DOWN
|
||||
Assertions.assertEquals(R.drawable.ic_fortyfivedown, glucoseValue.trendArrow.directionToIcon())
|
||||
glucoseValue.trendArrow = GlucoseValue.TrendArrow.FORTY_FIVE_UP
|
||||
Assertions.assertEquals(R.drawable.ic_fortyfiveup, glucoseValue.trendArrow.directionToIcon())
|
||||
glucoseValue.trendArrow = GlucoseValue.TrendArrow.SINGLE_UP
|
||||
Assertions.assertEquals(R.drawable.ic_singleup, glucoseValue.trendArrow.directionToIcon())
|
||||
glucoseValue.trendArrow = GlucoseValue.TrendArrow.DOUBLE_UP
|
||||
Assertions.assertEquals(R.drawable.ic_doubleup, glucoseValue.trendArrow.directionToIcon())
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue