From 1bc34a37f64bb91bf5af1ab325d3172af7a52903 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 3 Sep 2023 10:23:27 +0200 Subject: [PATCH] ExtendedBolusExtensionKtTest --- .../core/extensions/ExtendedBolusExtension.kt | 1 + .../ExtendedBolusExtensionKtTest.kt | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/core/main/src/main/java/info/nightscout/core/extensions/ExtendedBolusExtension.kt b/core/main/src/main/java/info/nightscout/core/extensions/ExtendedBolusExtension.kt index 353523a669..e03011f3e3 100644 --- a/core/main/src/main/java/info/nightscout/core/extensions/ExtendedBolusExtension.kt +++ b/core/main/src/main/java/info/nightscout/core/extensions/ExtendedBolusExtension.kt @@ -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 diff --git a/plugins/insulin/src/test/java/info/nightscout/core/extensions/ExtendedBolusExtensionKtTest.kt b/plugins/insulin/src/test/java/info/nightscout/core/extensions/ExtendedBolusExtensionKtTest.kt index c4766dd893..777b044e3a 100644 --- a/plugins/insulin/src/test/java/info/nightscout/core/extensions/ExtendedBolusExtensionKtTest.kt +++ b/plugins/insulin/src/test/java/info/nightscout/core/extensions/ExtendedBolusExtensionKtTest.kt @@ -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)) } } \ No newline at end of file