ExtendedBolusExtensionKtTest
This commit is contained in:
parent
2538378c0c
commit
61d67173f2
3 changed files with 58 additions and 1 deletions
|
@ -6,6 +6,7 @@ import info.nightscout.database.entities.TemporaryBasal
|
||||||
import info.nightscout.database.entities.interfaces.end
|
import info.nightscout.database.entities.interfaces.end
|
||||||
import info.nightscout.interfaces.aps.AutosensResult
|
import info.nightscout.interfaces.aps.AutosensResult
|
||||||
import info.nightscout.interfaces.insulin.Insulin
|
import info.nightscout.interfaces.insulin.Insulin
|
||||||
|
import info.nightscout.interfaces.iob.Iob
|
||||||
import info.nightscout.interfaces.iob.IobTotal
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.interfaces.profile.Profile
|
import info.nightscout.interfaces.profile.Profile
|
||||||
import info.nightscout.interfaces.utils.DecimalFormatter
|
import info.nightscout.interfaces.utils.DecimalFormatter
|
||||||
|
@ -45,6 +46,7 @@ fun ExtendedBolus.toTemporaryBasal(profile: Profile): TemporaryBasal =
|
||||||
)
|
)
|
||||||
|
|
||||||
fun ExtendedBolus.iobCalc(time: Long, profile: Profile, insulinInterface: Insulin): IobTotal {
|
fun ExtendedBolus.iobCalc(time: Long, profile: Profile, insulinInterface: Insulin): IobTotal {
|
||||||
|
if (!isValid) return IobTotal(time)
|
||||||
val result = IobTotal(time)
|
val result = IobTotal(time)
|
||||||
val realDuration = getPassedDurationToTimeInMinutes(time)
|
val realDuration = getPassedDurationToTimeInMinutes(time)
|
||||||
if (realDuration > 0) {
|
if (realDuration > 0) {
|
||||||
|
|
|
@ -36,9 +36,15 @@ class BolusExtensionKtTest : TestBaseWithProfile() {
|
||||||
val bolus = Bolus(timestamp = now - 1, amount = 1.0, type = Bolus.Type.NORMAL)
|
val bolus = Bolus(timestamp = now - 1, amount = 1.0, type = Bolus.Type.NORMAL)
|
||||||
// there should be almost full IOB after now
|
// there should be almost full IOB after now
|
||||||
Assertions.assertEquals(1.0, bolus.iobCalc(activePlugin, now, dia).iobContrib, 0.01)
|
Assertions.assertEquals(1.0, bolus.iobCalc(activePlugin, now, dia).iobContrib, 0.01)
|
||||||
// there should be less that 5% after DIA -1
|
// there should be less than 5% after DIA -1
|
||||||
Assertions.assertTrue(0.05 > bolus.iobCalc(activePlugin, now + T.hours(dia.toLong() - 1).msecs(), dia).iobContrib)
|
Assertions.assertTrue(0.05 > bolus.iobCalc(activePlugin, now + T.hours(dia.toLong() - 1).msecs(), dia).iobContrib)
|
||||||
// there should be zero after DIA
|
// there should be zero after DIA
|
||||||
Assertions.assertEquals(0.0, bolus.iobCalc(activePlugin, now + T.hours(dia.toLong() + 1).msecs(), dia).iobContrib)
|
Assertions.assertEquals(0.0, bolus.iobCalc(activePlugin, now + T.hours(dia.toLong() + 1).msecs(), dia).iobContrib)
|
||||||
|
// no IOB for invalid record
|
||||||
|
bolus.isValid = false
|
||||||
|
Assertions.assertEquals(0.0, bolus.iobCalc(activePlugin, now + T.hours(1).msecs(), dia).iobContrib)
|
||||||
|
bolus.isValid = true
|
||||||
|
bolus.type = Bolus.Type.PRIMING
|
||||||
|
Assertions.assertEquals(0.0, bolus.iobCalc(activePlugin, now + T.hours(1).msecs(), dia).iobContrib)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package info.nightscout.core.extensions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.TestBaseWithProfile
|
||||||
|
import info.nightscout.database.entities.ExtendedBolus
|
||||||
|
import info.nightscout.insulin.InsulinLyumjevPlugin
|
||||||
|
import info.nightscout.interfaces.insulin.Insulin
|
||||||
|
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||||
|
import info.nightscout.interfaces.profile.ProfileFunction
|
||||||
|
import info.nightscout.interfaces.ui.UiInteraction
|
||||||
|
import info.nightscout.shared.utils.T
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito
|
||||||
|
|
||||||
|
class ExtendedBolusExtensionKtTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
|
@Mock lateinit var activePlugin: ActivePlugin
|
||||||
|
@Mock lateinit var profileFunctions: ProfileFunction
|
||||||
|
@Mock lateinit var uiInteraction: UiInteraction
|
||||||
|
|
||||||
|
private lateinit var insulin: Insulin
|
||||||
|
|
||||||
|
private val now = 1000000L
|
||||||
|
private val dia = 7.0
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun setup() {
|
||||||
|
insulin = InsulinLyumjevPlugin(profileInjector, rh, profileFunctions, rxBus, aapsLogger, config, hardLimits, uiInteraction)
|
||||||
|
Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun iobCalc() {
|
||||||
|
val bolus = ExtendedBolus(timestamp = now - 1, amount = 1.0, duration = T.hours(1).msecs())
|
||||||
|
// there should zero IOB after now
|
||||||
|
Assertions.assertEquals(0.0, bolus.iobCalc(now, validProfile, insulin).iob, 0.01)
|
||||||
|
// there should be significant IOB at EB finish
|
||||||
|
Assertions.assertTrue(0.8 < bolus.iobCalc(now + T.hours(1).msecs(), validProfile, insulin).iob)
|
||||||
|
// there should be less that 5% after DIA -1
|
||||||
|
Assertions.assertTrue(0.05 > bolus.iobCalc(now + T.hours(dia.toLong() - 1).msecs(), validProfile, insulin).iob)
|
||||||
|
// there should be zero after DIA
|
||||||
|
Assertions.assertEquals(0.0, bolus.iobCalc(now + T.hours(dia.toLong() + 1).msecs(), validProfile, insulin).iob)
|
||||||
|
// no IOB for invalid record
|
||||||
|
bolus.isValid = false
|
||||||
|
Assertions.assertEquals(0.0, bolus.iobCalc(now + T.hours(1).msecs(), validProfile, insulin).iob)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue