ExtendedBolusExtensionKtTest

This commit is contained in:
Milos Kozak 2023-09-03 10:23:27 +02:00
parent 78d64fb7ac
commit 1bc34a37f6
2 changed files with 27 additions and 0 deletions

View file

@ -82,6 +82,7 @@ fun ExtendedBolus.iobCalc(
isTempTarget: Boolean, isTempTarget: Boolean,
insulinInterface: Insulin insulinInterface: Insulin
): IobTotal { ): IobTotal {
if (!isValid) return IobTotal(time)
val result = IobTotal(time) val result = IobTotal(time)
val realDuration = getPassedDurationToTimeInMinutes(time) val realDuration = getPassedDurationToTimeInMinutes(time)
var sensitivityRatio = lastAutosensResult.ratio var sensitivityRatio = lastAutosensResult.ratio

View file

@ -3,6 +3,8 @@ package info.nightscout.core.extensions
import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.database.entities.ExtendedBolus import info.nightscout.database.entities.ExtendedBolus
import info.nightscout.insulin.InsulinLyumjevPlugin import info.nightscout.insulin.InsulinLyumjevPlugin
import info.nightscout.interfaces.aps.AutosensResult
import info.nightscout.interfaces.aps.SMBDefaults
import info.nightscout.interfaces.insulin.Insulin import info.nightscout.interfaces.insulin.Insulin
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.profile.ProfileFunction
@ -29,6 +31,7 @@ class ExtendedBolusExtensionKtTest : TestBaseWithProfile() {
fun setup() { fun setup() {
insulin = InsulinLyumjevPlugin(profileInjector, rh, profileFunctions, rxBus, aapsLogger, config, hardLimits, uiInteraction) insulin = InsulinLyumjevPlugin(profileInjector, rh, profileFunctions, rxBus, aapsLogger, config, hardLimits, uiInteraction)
Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin) Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin)
Mockito.`when`(dateUtil.now()).thenReturn(now)
} }
@Test @Test
@ -45,5 +48,28 @@ class ExtendedBolusExtensionKtTest : TestBaseWithProfile() {
// no IOB for invalid record // no IOB for invalid record
bolus.isValid = false bolus.isValid = false
Assertions.assertEquals(0.0, bolus.iobCalc(now + T.hours(1).msecs(), validProfile, insulin).iob) Assertions.assertEquals(0.0, bolus.iobCalc(now + T.hours(1).msecs(), validProfile, insulin).iob)
bolus.isValid = true
val asResult = AutosensResult()
// there should zero IOB after now
Assertions.assertEquals(0.0, bolus.iobCalc(now, validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).iob, 0.01)
// there should be significant IOB at EB finish
Assertions.assertTrue(0.8 < bolus.iobCalc(now + T.hours(1).msecs(), validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, 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, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).iob)
// there should be zero after DIA
Assertions.assertEquals(0.0, bolus.iobCalc(now + T.hours(dia.toLong() + 1).msecs(), validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).iob)
// no IOB for invalid record
bolus.isValid = false
Assertions.assertEquals(0.0, bolus.iobCalc(now + T.hours(1).msecs(), validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).iob)
}
@Test
fun isInProgress() {
val bolus = ExtendedBolus(timestamp = now - 1, amount = 1.0, duration = T.hours(1).msecs())
Mockito.`when`(dateUtil.now()).thenReturn(now)
Assertions.assertTrue(bolus.isInProgress(dateUtil))
Mockito.`when`(dateUtil.now()).thenReturn(now + T.hours(2).msecs())
Assertions.assertFalse(bolus.isInProgress(dateUtil))
} }
} }