fix and add test

This commit is contained in:
Milos Kozak 2020-03-10 21:33:52 +01:00
parent 72a8bbfc75
commit c7c8aea65c
2 changed files with 9 additions and 3 deletions

View file

@ -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))

View file

@ -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)
}