parent
0731827b38
commit
b2aa328e67
|
@ -1,13 +1,13 @@
|
||||||
package info.nightscout.core.extensions
|
package info.nightscout.core.extensions
|
||||||
|
|
||||||
import app.aaps.shared.tests.TestBaseWithProfile
|
import app.aaps.shared.tests.TestBaseWithProfile
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import info.nightscout.database.entities.Bolus
|
import info.nightscout.database.entities.Bolus
|
||||||
import info.nightscout.insulin.InsulinLyumjevPlugin
|
import info.nightscout.insulin.InsulinLyumjevPlugin
|
||||||
import info.nightscout.interfaces.insulin.Insulin
|
import info.nightscout.interfaces.insulin.Insulin
|
||||||
import info.nightscout.interfaces.profile.ProfileFunction
|
import info.nightscout.interfaces.profile.ProfileFunction
|
||||||
import info.nightscout.interfaces.ui.UiInteraction
|
import info.nightscout.interfaces.ui.UiInteraction
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
import org.junit.jupiter.api.Assertions
|
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
@ -22,26 +22,26 @@ class BolusExtensionKtTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
private val dia = 7.0
|
private val dia = 7.0
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test fun iobCalc() {
|
||||||
fun iobCalc() {
|
|
||||||
val bolus = Bolus(timestamp = now - 1, amount = 1.0, type = Bolus.Type.NORMAL)
|
val bolus = Bolus(timestamp = now - 1, amount = 1.0, type = Bolus.Type.NORMAL)
|
||||||
// there should be almost full IOB after now
|
// there should be almost full IOB after now
|
||||||
Assertions.assertEquals(1.0, bolus.iobCalc(activePlugin, now, dia).iobContrib, 0.01)
|
assertThat(bolus.iobCalc(activePlugin, now, dia).iobContrib).isWithin(0.01).of(1.0)
|
||||||
// there should be less than 5% after DIA -1
|
// there should be less than 5% after DIA -1
|
||||||
Assertions.assertTrue(0.05 > bolus.iobCalc(activePlugin, now + T.hours(dia.toLong() - 1).msecs(), dia).iobContrib)
|
assertThat(
|
||||||
|
bolus.iobCalc(activePlugin, now + T.hours(dia.toLong() - 1).msecs(), dia).iobContrib
|
||||||
|
).isLessThan(0.05)
|
||||||
// there should be zero after DIA
|
// there should be zero after DIA
|
||||||
Assertions.assertEquals(0.0, bolus.iobCalc(activePlugin, now + T.hours(dia.toLong() + 1).msecs(), dia).iobContrib)
|
assertThat(bolus.iobCalc(activePlugin, now + T.hours(dia.toLong() + 1).msecs(), dia).iobContrib).isEqualTo(0.0)
|
||||||
// no IOB for invalid record
|
// no IOB for invalid record
|
||||||
bolus.isValid = false
|
bolus.isValid = false
|
||||||
Assertions.assertEquals(0.0, bolus.iobCalc(activePlugin, now + T.hours(1).msecs(), dia).iobContrib)
|
assertThat(bolus.iobCalc(activePlugin, now + T.hours(1).msecs(), dia).iobContrib).isEqualTo(0.0)
|
||||||
bolus.isValid = true
|
bolus.isValid = true
|
||||||
bolus.type = Bolus.Type.PRIMING
|
bolus.type = Bolus.Type.PRIMING
|
||||||
Assertions.assertEquals(0.0, bolus.iobCalc(activePlugin, now + T.hours(1).msecs(), dia).iobContrib)
|
assertThat(bolus.iobCalc(activePlugin, now + T.hours(1).msecs(), dia).iobContrib).isEqualTo(0.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue