fix tests
This commit is contained in:
parent
26a07f2477
commit
355361ed6d
7 changed files with 34 additions and 59 deletions
|
@ -9,7 +9,6 @@ import info.nightscout.androidaps.insight.database.InsightDatabase
|
||||||
import info.nightscout.androidaps.insight.database.InsightDatabaseDao
|
import info.nightscout.androidaps.insight.database.InsightDatabaseDao
|
||||||
import info.nightscout.androidaps.insight.database.InsightDbHelper
|
import info.nightscout.androidaps.insight.database.InsightDbHelper
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin
|
import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin
|
||||||
import info.nightscout.core.constraints.ConstraintObject
|
|
||||||
import info.nightscout.database.impl.AppRepository
|
import info.nightscout.database.impl.AppRepository
|
||||||
import info.nightscout.implementation.iob.GlucoseStatusProviderImpl
|
import info.nightscout.implementation.iob.GlucoseStatusProviderImpl
|
||||||
import info.nightscout.interfaces.ApsMode
|
import info.nightscout.interfaces.ApsMode
|
||||||
|
@ -95,9 +94,6 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
|
||||||
if (it is PumpEnactResult) {
|
if (it is PumpEnactResult) {
|
||||||
it.context = context
|
it.context = context
|
||||||
}
|
}
|
||||||
if (it is ConstraintObject<*>) {
|
|
||||||
it.aapsLogger = aapsLogger
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +134,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
|
||||||
`when`(sp.getString(R.string.key_danar_bt_name, "")).thenReturn("")
|
`when`(sp.getString(R.string.key_danar_bt_name, "")).thenReturn("")
|
||||||
|
|
||||||
//SafetyPlugin
|
//SafetyPlugin
|
||||||
constraintChecker = ConstraintsCheckerImpl(activePlugin, injector)
|
constraintChecker = ConstraintsCheckerImpl(activePlugin, aapsLogger)
|
||||||
|
|
||||||
val glucoseStatusProvider = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculator, dateUtil, decimalFormatter)
|
val glucoseStatusProvider = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculator, dateUtil, decimalFormatter)
|
||||||
|
|
||||||
|
|
|
@ -45,9 +45,6 @@ class SafetyPluginTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
private val injector = HasAndroidInjector {
|
private val injector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
if (it is ConstraintObject<*>) {
|
|
||||||
it.aapsLogger = aapsLogger
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private val pumpDescription = PumpDescription()
|
private val pumpDescription = PumpDescription()
|
||||||
|
@ -92,7 +89,7 @@ class SafetyPluginTest : TestBaseWithProfile() {
|
||||||
@Test
|
@Test
|
||||||
fun pumpDescriptionShouldLimitLoopInvocation() {
|
fun pumpDescriptionShouldLimitLoopInvocation() {
|
||||||
pumpDescription.isTempBasalCapable = false
|
pumpDescription.isTempBasalCapable = false
|
||||||
val c = safetyPlugin.isLoopInvocationAllowed(ConstraintObject(true, injector))
|
val c = safetyPlugin.isLoopInvocationAllowed(ConstraintObject(true, aapsLogger))
|
||||||
assertThat(c.getReasons()).isEqualTo("Safety: Pump is not temp basal capable")
|
assertThat(c.getReasons()).isEqualTo("Safety: Pump is not temp basal capable")
|
||||||
assertThat(c.value()).isFalse()
|
assertThat(c.value()).isFalse()
|
||||||
}
|
}
|
||||||
|
@ -101,7 +98,7 @@ class SafetyPluginTest : TestBaseWithProfile() {
|
||||||
fun disabledEngineeringModeShouldLimitClosedLoop() {
|
fun disabledEngineeringModeShouldLimitClosedLoop() {
|
||||||
`when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn(ApsMode.CLOSED.name)
|
`when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn(ApsMode.CLOSED.name)
|
||||||
`when`(config.isEngineeringModeOrRelease()).thenReturn(false)
|
`when`(config.isEngineeringModeOrRelease()).thenReturn(false)
|
||||||
val c = safetyPlugin.isClosedLoopAllowed(ConstraintObject(true, injector))
|
val c = safetyPlugin.isClosedLoopAllowed(ConstraintObject(true, aapsLogger))
|
||||||
assertThat(c.getReasons()).contains("Running dev version. Closed loop is disabled.")
|
assertThat(c.getReasons()).contains("Running dev version. Closed loop is disabled.")
|
||||||
assertThat(c.value()).isFalse()
|
assertThat(c.value()).isFalse()
|
||||||
}
|
}
|
||||||
|
@ -109,7 +106,7 @@ class SafetyPluginTest : TestBaseWithProfile() {
|
||||||
@Test
|
@Test
|
||||||
fun setOpenLoopInPreferencesShouldLimitClosedLoop() {
|
fun setOpenLoopInPreferencesShouldLimitClosedLoop() {
|
||||||
`when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn(ApsMode.OPEN.name)
|
`when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn(ApsMode.OPEN.name)
|
||||||
val c = safetyPlugin.isClosedLoopAllowed(ConstraintObject(true, injector))
|
val c = safetyPlugin.isClosedLoopAllowed(ConstraintObject(true, aapsLogger))
|
||||||
assertThat(c.getReasons()).contains("Closed loop mode disabled in preferences")
|
assertThat(c.getReasons()).contains("Closed loop mode disabled in preferences")
|
||||||
assertThat(c.value()).isFalse()
|
assertThat(c.value()).isFalse()
|
||||||
}
|
}
|
||||||
|
@ -117,8 +114,8 @@ class SafetyPluginTest : TestBaseWithProfile() {
|
||||||
@Test
|
@Test
|
||||||
fun notEnabledSMBInPreferencesDisablesSMB() {
|
fun notEnabledSMBInPreferencesDisablesSMB() {
|
||||||
`when`(sp.getBoolean(info.nightscout.plugins.aps.R.string.key_use_smb, false)).thenReturn(false)
|
`when`(sp.getBoolean(info.nightscout.plugins.aps.R.string.key_use_smb, false)).thenReturn(false)
|
||||||
`when`(constraintChecker.isClosedLoopAllowed(anyObject())).thenReturn(ConstraintObject(true, injector))
|
`when`(constraintChecker.isClosedLoopAllowed(anyObject())).thenReturn(ConstraintObject(true, aapsLogger))
|
||||||
val c = openAPSSMBPlugin.isSMBModeEnabled(ConstraintObject(true, injector))
|
val c = openAPSSMBPlugin.isSMBModeEnabled(ConstraintObject(true, aapsLogger))
|
||||||
assertThat(c.getReasons()).contains("SMB disabled in preferences")
|
assertThat(c.getReasons()).contains("SMB disabled in preferences")
|
||||||
assertThat(c.value()).isFalse()
|
assertThat(c.value()).isFalse()
|
||||||
}
|
}
|
||||||
|
@ -126,8 +123,8 @@ class SafetyPluginTest : TestBaseWithProfile() {
|
||||||
@Test
|
@Test
|
||||||
fun openLoopPreventsSMB() {
|
fun openLoopPreventsSMB() {
|
||||||
`when`(sp.getBoolean(info.nightscout.plugins.aps.R.string.key_use_smb, false)).thenReturn(true)
|
`when`(sp.getBoolean(info.nightscout.plugins.aps.R.string.key_use_smb, false)).thenReturn(true)
|
||||||
`when`(constraintChecker.isClosedLoopAllowed()).thenReturn(ConstraintObject(false, injector))
|
`when`(constraintChecker.isClosedLoopAllowed()).thenReturn(ConstraintObject(false, aapsLogger))
|
||||||
val c = safetyPlugin.isSMBModeEnabled(ConstraintObject(true, injector))
|
val c = safetyPlugin.isSMBModeEnabled(ConstraintObject(true, aapsLogger))
|
||||||
assertThat(c.getReasons()).contains("SMB not allowed in open loop mode")
|
assertThat(c.getReasons()).contains("SMB not allowed in open loop mode")
|
||||||
assertThat(c.value()).isFalse()
|
assertThat(c.value()).isFalse()
|
||||||
}
|
}
|
||||||
|
@ -135,7 +132,7 @@ class SafetyPluginTest : TestBaseWithProfile() {
|
||||||
@Test
|
@Test
|
||||||
fun bgSourceShouldPreventSMBAlways() {
|
fun bgSourceShouldPreventSMBAlways() {
|
||||||
`when`(activePlugin.activeBgSource).thenReturn(glimpPlugin)
|
`when`(activePlugin.activeBgSource).thenReturn(glimpPlugin)
|
||||||
val c = safetyPlugin.isAdvancedFilteringEnabled(ConstraintObject(true, injector))
|
val c = safetyPlugin.isAdvancedFilteringEnabled(ConstraintObject(true, aapsLogger))
|
||||||
assertThat(c.getReasons()).isEqualTo("Safety: SMB always and after carbs disabled because active BG source doesn\\'t support advanced filtering")
|
assertThat(c.getReasons()).isEqualTo("Safety: SMB always and after carbs disabled because active BG source doesn\\'t support advanced filtering")
|
||||||
assertThat(c.value()).isFalse()
|
assertThat(c.value()).isFalse()
|
||||||
}
|
}
|
||||||
|
@ -146,7 +143,7 @@ class SafetyPluginTest : TestBaseWithProfile() {
|
||||||
`when`(sp.getDouble(info.nightscout.plugins.aps.R.string.key_openapsama_current_basal_safety_multiplier, 4.0)).thenReturn(4.0)
|
`when`(sp.getDouble(info.nightscout.plugins.aps.R.string.key_openapsama_current_basal_safety_multiplier, 4.0)).thenReturn(4.0)
|
||||||
`when`(sp.getDouble(info.nightscout.plugins.aps.R.string.key_openapsama_max_daily_safety_multiplier, 3.0)).thenReturn(3.0)
|
`when`(sp.getDouble(info.nightscout.plugins.aps.R.string.key_openapsama_max_daily_safety_multiplier, 3.0)).thenReturn(3.0)
|
||||||
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("child")
|
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("child")
|
||||||
val c = ConstraintObject(Double.MAX_VALUE, injector)
|
val c = ConstraintObject(Double.MAX_VALUE, aapsLogger)
|
||||||
safetyPlugin.applyBasalConstraints(c, validProfile)
|
safetyPlugin.applyBasalConstraints(c, validProfile)
|
||||||
assertThat(c.value()).isWithin(0.01).of(2.0)
|
assertThat(c.value()).isWithin(0.01).of(2.0)
|
||||||
assertThat(c.getReasons()).isEqualTo(
|
assertThat(c.getReasons()).isEqualTo(
|
||||||
|
@ -160,7 +157,7 @@ class SafetyPluginTest : TestBaseWithProfile() {
|
||||||
@Test
|
@Test
|
||||||
fun doNotAllowNegativeBasalRate() {
|
fun doNotAllowNegativeBasalRate() {
|
||||||
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("child")
|
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("child")
|
||||||
val d = ConstraintObject(-0.5, injector)
|
val d = ConstraintObject(-0.5, aapsLogger)
|
||||||
safetyPlugin.applyBasalConstraints(d, validProfile)
|
safetyPlugin.applyBasalConstraints(d, validProfile)
|
||||||
assertThat(d.value()).isWithin(0.01).of(0.0)
|
assertThat(d.value()).isWithin(0.01).of(0.0)
|
||||||
assertThat(d.getReasons()).isEqualTo(
|
assertThat(d.getReasons()).isEqualTo(
|
||||||
|
@ -175,7 +172,7 @@ class SafetyPluginTest : TestBaseWithProfile() {
|
||||||
`when`(sp.getDouble(info.nightscout.plugins.aps.R.string.key_openapsama_current_basal_safety_multiplier, 4.0)).thenReturn(4.0)
|
`when`(sp.getDouble(info.nightscout.plugins.aps.R.string.key_openapsama_current_basal_safety_multiplier, 4.0)).thenReturn(4.0)
|
||||||
`when`(sp.getDouble(info.nightscout.plugins.aps.R.string.key_openapsama_max_daily_safety_multiplier, 3.0)).thenReturn(3.0)
|
`when`(sp.getDouble(info.nightscout.plugins.aps.R.string.key_openapsama_max_daily_safety_multiplier, 3.0)).thenReturn(3.0)
|
||||||
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("child")
|
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("child")
|
||||||
val i = ConstraintObject(Int.MAX_VALUE, injector)
|
val i = ConstraintObject(Int.MAX_VALUE, aapsLogger)
|
||||||
safetyPlugin.applyBasalPercentConstraints(i, validProfile)
|
safetyPlugin.applyBasalPercentConstraints(i, validProfile)
|
||||||
assertThat(i.value()).isEqualTo(200)
|
assertThat(i.value()).isEqualTo(200)
|
||||||
assertThat(i.getReasons()).isEqualTo(
|
assertThat(i.getReasons()).isEqualTo(
|
||||||
|
@ -199,7 +196,7 @@ Safety: Limiting max basal rate to 500.00 U/h because of pump limit
|
||||||
`when`(sp.getDouble(info.nightscout.plugins.aps.R.string.key_openapsama_max_daily_safety_multiplier, 3.0)).thenReturn(3.0)
|
`when`(sp.getDouble(info.nightscout.plugins.aps.R.string.key_openapsama_max_daily_safety_multiplier, 3.0)).thenReturn(3.0)
|
||||||
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("child")
|
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("child")
|
||||||
openAPSSMBPlugin.setPluginEnabled(PluginType.APS, true)
|
openAPSSMBPlugin.setPluginEnabled(PluginType.APS, true)
|
||||||
val i = ConstraintObject(Double.MAX_VALUE, injector)
|
val i = ConstraintObject(Double.MAX_VALUE, aapsLogger)
|
||||||
openAPSSMBPlugin.applyBasalConstraints(i, validProfile)
|
openAPSSMBPlugin.applyBasalConstraints(i, validProfile)
|
||||||
assertThat(i.value()).isWithin(0.01).of(1.0)
|
assertThat(i.value()).isWithin(0.01).of(1.0)
|
||||||
assertThat(i.getReasons()).isEqualTo(
|
assertThat(i.getReasons()).isEqualTo(
|
||||||
|
@ -215,7 +212,7 @@ Safety: Limiting max basal rate to 500.00 U/h because of pump limit
|
||||||
@Test
|
@Test
|
||||||
fun doNotAllowNegativePercentBasalRate() {
|
fun doNotAllowNegativePercentBasalRate() {
|
||||||
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("child")
|
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("child")
|
||||||
val i = ConstraintObject(-22, injector)
|
val i = ConstraintObject(-22, aapsLogger)
|
||||||
safetyPlugin.applyBasalPercentConstraints(i, validProfile)
|
safetyPlugin.applyBasalPercentConstraints(i, validProfile)
|
||||||
assertThat(i.value()).isEqualTo(0)
|
assertThat(i.value()).isEqualTo(0)
|
||||||
assertThat(i.getReasons()).isEqualTo(
|
assertThat(i.getReasons()).isEqualTo(
|
||||||
|
@ -232,7 +229,7 @@ Safety: Limiting max basal rate to 500.00 U/h because of pump limit
|
||||||
fun bolusAmountShouldBeLimited() {
|
fun bolusAmountShouldBeLimited() {
|
||||||
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_treatmentssafety_maxbolus, 3.0)).thenReturn(3.0)
|
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_treatmentssafety_maxbolus, 3.0)).thenReturn(3.0)
|
||||||
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("child")
|
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("child")
|
||||||
val d = safetyPlugin.applyBolusConstraints(ConstraintObject(Double.MAX_VALUE, injector))
|
val d = safetyPlugin.applyBolusConstraints(ConstraintObject(Double.MAX_VALUE, aapsLogger))
|
||||||
assertThat(d.value()).isWithin(0.01).of(3.0)
|
assertThat(d.value()).isWithin(0.01).of(3.0)
|
||||||
assertThat(d.getReasons()).isEqualTo(
|
assertThat(d.getReasons()).isEqualTo(
|
||||||
"""
|
"""
|
||||||
|
@ -247,7 +244,7 @@ Safety: Limiting max basal rate to 500.00 U/h because of pump limit
|
||||||
fun doNotAllowNegativeBolusAmount() {
|
fun doNotAllowNegativeBolusAmount() {
|
||||||
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_treatmentssafety_maxbolus, 3.0)).thenReturn(3.0)
|
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_treatmentssafety_maxbolus, 3.0)).thenReturn(3.0)
|
||||||
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("child")
|
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("child")
|
||||||
val d = safetyPlugin.applyBolusConstraints(ConstraintObject(-22.0, injector))
|
val d = safetyPlugin.applyBolusConstraints(ConstraintObject(-22.0, aapsLogger))
|
||||||
assertThat(d.value()).isWithin(0.01).of(0.0)
|
assertThat(d.value()).isWithin(0.01).of(0.0)
|
||||||
assertThat(d.getReasons()).isEqualTo("Safety: Limiting bolus to 0.0 U because of it must be positive value")
|
assertThat(d.getReasons()).isEqualTo("Safety: Limiting bolus to 0.0 U because of it must be positive value")
|
||||||
assertThat(d.getMostLimitedReasons()).isEqualTo("Safety: Limiting bolus to 0.0 U because of it must be positive value")
|
assertThat(d.getMostLimitedReasons()).isEqualTo("Safety: Limiting bolus to 0.0 U because of it must be positive value")
|
||||||
|
@ -259,13 +256,13 @@ Safety: Limiting max basal rate to 500.00 U/h because of pump limit
|
||||||
`when`(sp.getInt(info.nightscout.core.utils.R.string.key_treatmentssafety_maxcarbs, 48)).thenReturn(48)
|
`when`(sp.getInt(info.nightscout.core.utils.R.string.key_treatmentssafety_maxcarbs, 48)).thenReturn(48)
|
||||||
|
|
||||||
// Negative carbs not allowed
|
// Negative carbs not allowed
|
||||||
var i: Constraint<Int> = ConstraintObject(-22, injector)
|
var i: Constraint<Int> = ConstraintObject(-22, aapsLogger)
|
||||||
safetyPlugin.applyCarbsConstraints(i)
|
safetyPlugin.applyCarbsConstraints(i)
|
||||||
assertThat(i.value()).isEqualTo(0)
|
assertThat(i.value()).isEqualTo(0)
|
||||||
assertThat(i.getReasons()).isEqualTo("Safety: Limiting carbs to 0 g because of it must be positive value")
|
assertThat(i.getReasons()).isEqualTo("Safety: Limiting carbs to 0 g because of it must be positive value")
|
||||||
|
|
||||||
// Apply all limits
|
// Apply all limits
|
||||||
i = safetyPlugin.applyCarbsConstraints(ConstraintObject(Int.MAX_VALUE, injector))
|
i = safetyPlugin.applyCarbsConstraints(ConstraintObject(Int.MAX_VALUE, aapsLogger))
|
||||||
assertThat(i.value()).isEqualTo(48)
|
assertThat(i.value()).isEqualTo(48)
|
||||||
assertThat(i.getReasons()).isEqualTo("Safety: Limiting carbs to 48 g because of max value in preferences")
|
assertThat(i.getReasons()).isEqualTo("Safety: Limiting carbs to 48 g because of max value in preferences")
|
||||||
}
|
}
|
||||||
|
@ -282,21 +279,21 @@ Safety: Limiting max basal rate to 500.00 U/h because of pump limit
|
||||||
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("teenage")
|
`when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("teenage")
|
||||||
|
|
||||||
// Apply all limits
|
// Apply all limits
|
||||||
var d: Constraint<Double> = ConstraintObject(Double.MAX_VALUE, injector)
|
var d: Constraint<Double> = ConstraintObject(Double.MAX_VALUE, aapsLogger)
|
||||||
d = safetyPlugin.applyMaxIOBConstraints(d)
|
d = safetyPlugin.applyMaxIOBConstraints(d)
|
||||||
assertThat(d.value()).isWithin(0.01).of(HardLimits.MAX_IOB_LGS)
|
assertThat(d.value()).isWithin(0.01).of(HardLimits.MAX_IOB_LGS)
|
||||||
assertThat(d.getReasons()).isEqualTo("Safety: Limiting IOB to 0.0 U because of Low Glucose Suspend")
|
assertThat(d.getReasons()).isEqualTo("Safety: Limiting IOB to 0.0 U because of Low Glucose Suspend")
|
||||||
assertThat(d.getMostLimitedReasons()).isEqualTo("Safety: Limiting IOB to 0.0 U because of Low Glucose Suspend")
|
assertThat(d.getMostLimitedReasons()).isEqualTo("Safety: Limiting IOB to 0.0 U because of Low Glucose Suspend")
|
||||||
|
|
||||||
// Apply all limits
|
// Apply all limits
|
||||||
d = ConstraintObject(Double.MAX_VALUE, injector)
|
d = ConstraintObject(Double.MAX_VALUE, aapsLogger)
|
||||||
val a = openAPSAMAPlugin.applyMaxIOBConstraints(d)
|
val a = openAPSAMAPlugin.applyMaxIOBConstraints(d)
|
||||||
assertThat(a.value()).isWithin(0.01).of(1.5)
|
assertThat(a.value()).isWithin(0.01).of(1.5)
|
||||||
assertThat(d.getReasons()).isEqualTo("OpenAPSAMA: Limiting IOB to 1.5 U because of max value in preferences\nOpenAPSAMA: Limiting IOB to 7.0 U because of hard limit")
|
assertThat(d.getReasons()).isEqualTo("OpenAPSAMA: Limiting IOB to 1.5 U because of max value in preferences\nOpenAPSAMA: Limiting IOB to 7.0 U because of hard limit")
|
||||||
assertThat(d.getMostLimitedReasons()).isEqualTo("OpenAPSAMA: Limiting IOB to 1.5 U because of max value in preferences")
|
assertThat(d.getMostLimitedReasons()).isEqualTo("OpenAPSAMA: Limiting IOB to 1.5 U because of max value in preferences")
|
||||||
|
|
||||||
// Apply all limits
|
// Apply all limits
|
||||||
d = ConstraintObject(Double.MAX_VALUE, injector)
|
d = ConstraintObject(Double.MAX_VALUE, aapsLogger)
|
||||||
val s = openAPSSMBPlugin.applyMaxIOBConstraints(d)
|
val s = openAPSSMBPlugin.applyMaxIOBConstraints(d)
|
||||||
assertThat(s.value()).isWithin(0.01).of(3.0)
|
assertThat(s.value()).isWithin(0.01).of(3.0)
|
||||||
assertThat(d.getReasons()).isEqualTo("OpenAPSSMB: Limiting IOB to 3.0 U because of max value in preferences\nOpenAPSSMB: Limiting IOB to 22.0 U because of hard limit")
|
assertThat(d.getReasons()).isEqualTo("OpenAPSSMB: Limiting IOB to 3.0 U because of max value in preferences\nOpenAPSSMB: Limiting IOB to 22.0 U because of hard limit")
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package info.nightscout.core.data
|
package info.nightscout.core.data
|
||||||
|
|
||||||
import dagger.android.AndroidInjector
|
|
||||||
import dagger.android.HasAndroidInjector
|
|
||||||
import info.nightscout.core.constraints.ConstraintObject
|
import info.nightscout.core.constraints.ConstraintObject
|
||||||
import info.nightscout.sharedtests.TestBase
|
import info.nightscout.sharedtests.TestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
|
@ -13,10 +11,8 @@ import org.junit.jupiter.api.Test
|
||||||
*/
|
*/
|
||||||
class ConstraintTest : TestBase() {
|
class ConstraintTest : TestBase() {
|
||||||
|
|
||||||
private val injector = HasAndroidInjector { AndroidInjector { } }
|
|
||||||
|
|
||||||
@Test fun doTests() {
|
@Test fun doTests() {
|
||||||
val b = ConstraintObject(false, aapsLogger)
|
val b = ConstraintObject(true, aapsLogger)
|
||||||
Assertions.assertEquals(true, b.value())
|
Assertions.assertEquals(true, b.value())
|
||||||
Assertions.assertEquals("", b.getReasons())
|
Assertions.assertEquals("", b.getReasons())
|
||||||
Assertions.assertEquals("", b.getMostLimitedReasons())
|
Assertions.assertEquals("", b.getMostLimitedReasons())
|
||||||
|
|
|
@ -35,9 +35,6 @@ class ObjectivesPluginTest : TestBase() {
|
||||||
it.rh = rh
|
it.rh = rh
|
||||||
it.dateUtil = dateUtil
|
it.dateUtil = dateUtil
|
||||||
}
|
}
|
||||||
if (it is ConstraintObject<*>) {
|
|
||||||
it.aapsLogger = aapsLogger
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +49,7 @@ class ObjectivesPluginTest : TestBase() {
|
||||||
|
|
||||||
@Test fun notStartedObjectivesShouldLimitLoopInvocation() {
|
@Test fun notStartedObjectivesShouldLimitLoopInvocation() {
|
||||||
objectivesPlugin.objectives[Objectives.FIRST_OBJECTIVE].startedOn = 0
|
objectivesPlugin.objectives[Objectives.FIRST_OBJECTIVE].startedOn = 0
|
||||||
val c = objectivesPlugin.isLoopInvocationAllowed(ConstraintObject(true, injector))
|
val c = objectivesPlugin.isLoopInvocationAllowed(ConstraintObject(true, aapsLogger))
|
||||||
Assertions.assertEquals("Objectives: Objective 1 not started", c.getReasons())
|
Assertions.assertEquals("Objectives: Objective 1 not started", c.getReasons())
|
||||||
Assertions.assertEquals(false, c.value())
|
Assertions.assertEquals(false, c.value())
|
||||||
objectivesPlugin.objectives[Objectives.FIRST_OBJECTIVE].startedOn = dateUtil.now()
|
objectivesPlugin.objectives[Objectives.FIRST_OBJECTIVE].startedOn = dateUtil.now()
|
||||||
|
@ -60,21 +57,21 @@ class ObjectivesPluginTest : TestBase() {
|
||||||
|
|
||||||
@Test fun notStartedObjective6ShouldLimitClosedLoop() {
|
@Test fun notStartedObjective6ShouldLimitClosedLoop() {
|
||||||
objectivesPlugin.objectives[Objectives.MAXIOB_ZERO_CL_OBJECTIVE].startedOn = 0
|
objectivesPlugin.objectives[Objectives.MAXIOB_ZERO_CL_OBJECTIVE].startedOn = 0
|
||||||
val c = objectivesPlugin.isClosedLoopAllowed(ConstraintObject(true, injector))
|
val c = objectivesPlugin.isClosedLoopAllowed(ConstraintObject(true, aapsLogger))
|
||||||
Assertions.assertEquals(true, c.getReasons().contains("Objective 6 not started"))
|
Assertions.assertEquals(true, c.getReasons().contains("Objective 6 not started"))
|
||||||
Assertions.assertEquals(false, c.value())
|
Assertions.assertEquals(false, c.value())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun notStartedObjective8ShouldLimitAutosensMode() {
|
@Test fun notStartedObjective8ShouldLimitAutosensMode() {
|
||||||
objectivesPlugin.objectives[Objectives.AUTOSENS_OBJECTIVE].startedOn = 0
|
objectivesPlugin.objectives[Objectives.AUTOSENS_OBJECTIVE].startedOn = 0
|
||||||
val c = objectivesPlugin.isAutosensModeEnabled(ConstraintObject(true, injector))
|
val c = objectivesPlugin.isAutosensModeEnabled(ConstraintObject(true, aapsLogger))
|
||||||
Assertions.assertEquals(true, c.getReasons().contains("Objective 8 not started"))
|
Assertions.assertEquals(true, c.getReasons().contains("Objective 8 not started"))
|
||||||
Assertions.assertEquals(false, c.value())
|
Assertions.assertEquals(false, c.value())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun notStartedObjective10ShouldLimitSMBMode() {
|
@Test fun notStartedObjective10ShouldLimitSMBMode() {
|
||||||
objectivesPlugin.objectives[Objectives.SMB_OBJECTIVE].startedOn = 0
|
objectivesPlugin.objectives[Objectives.SMB_OBJECTIVE].startedOn = 0
|
||||||
val c = objectivesPlugin.isSMBModeEnabled(ConstraintObject(true, injector))
|
val c = objectivesPlugin.isSMBModeEnabled(ConstraintObject(true, aapsLogger))
|
||||||
Assertions.assertEquals(true, c.getReasons().contains("Objective 9 not started"))
|
Assertions.assertEquals(true, c.getReasons().contains("Objective 9 not started"))
|
||||||
Assertions.assertEquals(false, c.value())
|
Assertions.assertEquals(false, c.value())
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,9 +62,6 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
private var injector: HasAndroidInjector = HasAndroidInjector {
|
private var injector: HasAndroidInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
if (it is ConstraintObject<*>) {
|
|
||||||
it.aapsLogger = aapsLogger
|
|
||||||
}
|
|
||||||
if (it is PumpEnactResult) {
|
if (it is PumpEnactResult) {
|
||||||
it.context = context
|
it.context = context
|
||||||
}
|
}
|
||||||
|
@ -873,7 +870,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("BASAL 1 20")
|
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("BASAL 1 20")
|
||||||
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("TBR duration must be a multiple of 30 minutes and greater than 0.")
|
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("TBR duration must be a multiple of 30 minutes and greater than 0.")
|
||||||
`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(ConstraintObject(1.0, injector))
|
`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(ConstraintObject(1.0, aapsLogger))
|
||||||
|
|
||||||
//BASAL 1 30
|
//BASAL 1 30
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
@ -921,7 +918,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("EXTENDED a%")
|
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("EXTENDED a%")
|
||||||
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("Wrong format")
|
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("Wrong format")
|
||||||
`when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(ConstraintObject(1.0, injector))
|
`when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(ConstraintObject(1.0, aapsLogger))
|
||||||
|
|
||||||
//EXTENDED 1 0
|
//EXTENDED 1 0
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
@ -958,7 +955,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("BOLUS")
|
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("BOLUS")
|
||||||
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("Wrong format")
|
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("Wrong format")
|
||||||
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(1.0, injector))
|
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(1.0, aapsLogger))
|
||||||
`when`(dateUtilMocked.now()).thenReturn(1000L)
|
`when`(dateUtilMocked.now()).thenReturn(1000L)
|
||||||
`when`(sp.getLong(R.string.key_smscommunicator_remote_bolus_min_distance, T.msecs(Constants.remoteBolusMinDistance).mins())).thenReturn(15L)
|
`when`(sp.getLong(R.string.key_smscommunicator_remote_bolus_min_distance, T.msecs(Constants.remoteBolusMinDistance).mins())).thenReturn(15L)
|
||||||
//BOLUS 1
|
//BOLUS 1
|
||||||
|
@ -967,7 +964,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("BOLUS 1")
|
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("BOLUS 1")
|
||||||
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("Remote bolus not available. Try again later.")
|
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("Remote bolus not available. Try again later.")
|
||||||
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, injector))
|
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, aapsLogger))
|
||||||
`when`(dateUtilMocked.now()).thenReturn(Constants.remoteBolusMinDistance + 1002L)
|
`when`(dateUtilMocked.now()).thenReturn(Constants.remoteBolusMinDistance + 1002L)
|
||||||
|
|
||||||
//BOLUS 0
|
//BOLUS 0
|
||||||
|
@ -983,8 +980,8 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("BOLUS a")
|
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("BOLUS a")
|
||||||
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("Wrong format")
|
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("Wrong format")
|
||||||
`when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(ConstraintObject(1.0, injector))
|
`when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(ConstraintObject(1.0, aapsLogger))
|
||||||
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(1.0, injector))
|
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(1.0, aapsLogger))
|
||||||
|
|
||||||
//BOLUS 1
|
//BOLUS 1
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
@ -1081,7 +1078,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("CARBS")
|
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("CARBS")
|
||||||
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("Wrong format")
|
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("Wrong format")
|
||||||
`when`(constraintChecker.applyCarbsConstraints(anyObject())).thenReturn(ConstraintObject(0, injector))
|
`when`(constraintChecker.applyCarbsConstraints(anyObject())).thenReturn(ConstraintObject(0, aapsLogger))
|
||||||
|
|
||||||
//CARBS 0
|
//CARBS 0
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
@ -1089,7 +1086,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("CARBS 0")
|
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("CARBS 0")
|
||||||
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("Wrong format")
|
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("Wrong format")
|
||||||
`when`(constraintChecker.applyCarbsConstraints(anyObject())).thenReturn(ConstraintObject(1, injector))
|
`when`(constraintChecker.applyCarbsConstraints(anyObject())).thenReturn(ConstraintObject(1, aapsLogger))
|
||||||
|
|
||||||
//CARBS 1
|
//CARBS 1
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
|
|
@ -6,7 +6,6 @@ import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin
|
||||||
import info.nightscout.androidaps.danaRv2.DanaRv2Plugin
|
import info.nightscout.androidaps.danaRv2.DanaRv2Plugin
|
||||||
import info.nightscout.androidaps.danar.DanaRPlugin
|
import info.nightscout.androidaps.danar.DanaRPlugin
|
||||||
import info.nightscout.androidaps.danar.comm.MessageBase
|
import info.nightscout.androidaps.danar.comm.MessageBase
|
||||||
import info.nightscout.core.constraints.ConstraintObject
|
|
||||||
import info.nightscout.interfaces.ConfigBuilder
|
import info.nightscout.interfaces.ConfigBuilder
|
||||||
import info.nightscout.interfaces.constraints.ConstraintsChecker
|
import info.nightscout.interfaces.constraints.ConstraintsChecker
|
||||||
import info.nightscout.interfaces.profile.Instantiator
|
import info.nightscout.interfaces.profile.Instantiator
|
||||||
|
@ -50,9 +49,6 @@ open class DanaRTestBase : TestBaseWithProfile() {
|
||||||
|
|
||||||
val injector = HasAndroidInjector {
|
val injector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
if (it is ConstraintObject<*>) {
|
|
||||||
it.aapsLogger = aapsLogger
|
|
||||||
}
|
|
||||||
if (it is MessageBase) {
|
if (it is MessageBase) {
|
||||||
it.aapsLogger = aapsLogger
|
it.aapsLogger = aapsLogger
|
||||||
it.dateUtil = dateUtil
|
it.dateUtil = dateUtil
|
||||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.pump.danars
|
||||||
|
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.core.constraints.ConstraintObject
|
|
||||||
import info.nightscout.interfaces.profile.Instantiator
|
import info.nightscout.interfaces.profile.Instantiator
|
||||||
import info.nightscout.interfaces.ui.UiInteraction
|
import info.nightscout.interfaces.ui.UiInteraction
|
||||||
import info.nightscout.pump.dana.DanaPump
|
import info.nightscout.pump.dana.DanaPump
|
||||||
|
@ -22,9 +21,6 @@ open class DanaRSTestBase : TestBaseWithProfile() {
|
||||||
|
|
||||||
val injector = HasAndroidInjector {
|
val injector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
if (it is ConstraintObject<*>) {
|
|
||||||
it.aapsLogger = aapsLogger
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue