From c7c8aea65c8c0b6774a59b47f33c0b390dca3380 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 10 Mar 2020 21:33:52 +0100 Subject: [PATCH] fix and add test --- .../pump/common/bolusInfo/DetailedBolusInfoStorage.kt | 7 ++++--- .../pump/common/bolusInfo/DetailedBolusInfoStorageTest.kt | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt index daf6c80b2b..884ba3a46b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt @@ -44,11 +44,12 @@ object DetailedBolusInfoStorage { // If not found, use last record if amount is the same if (store.size > 0) { val d = store[store.size - 1] - if (abs(d.insulin - bolus) < 0.01) + if (abs(d.insulin - bolus) < 0.01) { if (L.isEnabled(L.PUMP)) log.debug("Using LAST & removing bolus info: $d") - store.removeAt(store.size - 1) - return d + store.removeAt(store.size - 1) + return d + } } //Not found if (L.isEnabled(L.PUMP)) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorageTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorageTest.kt index d0944d23bc..29e945c4bb 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorageTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorageTest.kt @@ -82,6 +82,11 @@ class DetailedBolusInfoStorageTest { d = DetailedBolusInfoStorage.findDetailedBolusInfo(1070000, 4.0) assertNull(d) assertEquals(3, DetailedBolusInfoStorage.store.size) + // Use last, if bolus size is the same + setUp() + d = DetailedBolusInfoStorage.findDetailedBolusInfo(1070000, 5.0) + assertEquals(5.0, d!!.insulin, 0.01) + assertEquals(2, DetailedBolusInfoStorage.store.size) }