ExtendedBolusExtensionKtTest
This commit is contained in:
parent
78d64fb7ac
commit
1bc34a37f6
|
@ -82,6 +82,7 @@ fun ExtendedBolus.iobCalc(
|
|||
isTempTarget: Boolean,
|
||||
insulinInterface: Insulin
|
||||
): IobTotal {
|
||||
if (!isValid) return IobTotal(time)
|
||||
val result = IobTotal(time)
|
||||
val realDuration = getPassedDurationToTimeInMinutes(time)
|
||||
var sensitivityRatio = lastAutosensResult.ratio
|
||||
|
|
|
@ -3,6 +3,8 @@ 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.aps.AutosensResult
|
||||
import info.nightscout.interfaces.aps.SMBDefaults
|
||||
import info.nightscout.interfaces.insulin.Insulin
|
||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||
import info.nightscout.interfaces.profile.ProfileFunction
|
||||
|
@ -29,6 +31,7 @@ class ExtendedBolusExtensionKtTest : TestBaseWithProfile() {
|
|||
fun setup() {
|
||||
insulin = InsulinLyumjevPlugin(profileInjector, rh, profileFunctions, rxBus, aapsLogger, config, hardLimits, uiInteraction)
|
||||
Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin)
|
||||
Mockito.`when`(dateUtil.now()).thenReturn(now)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -45,5 +48,28 @@ class ExtendedBolusExtensionKtTest : TestBaseWithProfile() {
|
|||
// no IOB for invalid record
|
||||
bolus.isValid = false
|
||||
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))
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue