From c68ab9f1ca6c0be573cfacbd4c1db8684d68e951 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 21 Mar 2018 22:06:28 +0100 Subject: [PATCH] applyBasalPercentConstraints refactor & tests part2 --- .../androidaps/interfaces/Constraint.java | 25 ++++++++---- .../ObjectivesPlugin.java | 10 ++--- .../ConstraintsSafety/SafetyPlugin.java | 30 +++++++-------- .../plugins/PumpCombo/ComboPlugin.java | 2 +- .../PumpDanaR/AbstractDanaRPlugin.java | 9 ++--- .../plugins/PumpDanaRS/DanaRSPlugin.java | 9 ++--- .../PumpInsight/InsightPumpPlugin.java | 6 +-- .../androidaps/interfaces/ConstraintTest.java | 20 +++++----- .../interfaces/ConstraintsCheckerTest.java | 38 ++++++++++--------- 9 files changed, 78 insertions(+), 71 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/Constraint.java b/app/src/main/java/info/nightscout/androidaps/interfaces/Constraint.java index a830bcde73..de3d266d7b 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/Constraint.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/Constraint.java @@ -37,34 +37,34 @@ public class Constraint { return this; } - public Constraint set(T value, String reason) { + public Constraint set(T value, String reason, Object from) { this.value = value; - reason(reason); + reason(reason, from); return this; } - public Constraint setIfSmaller(T value, String reason) { + public Constraint setIfSmaller(T value, String reason, Object from) { if (value.compareTo(this.value) < 0) { this.value = value; } if (value.compareTo(this.originalValue) < 0) { - reason(reason); + reason(reason, from); } return this; } - public Constraint setIfGreater(T value, String reason) { + public Constraint setIfGreater(T value, String reason, Object from) { if (value.compareTo(this.value) > 0) { this.value = value; } if (value.compareTo(this.originalValue) > 0) { - reason(reason); + reason(reason, from); } return this; } - public Constraint reason(String reason) { - reasons.add(reason); + public Constraint reason(String reason, Object from) { + reasons.add(from.getClass().getSimpleName() + ": " + reason); return this; } @@ -79,4 +79,13 @@ public class Constraint { return sb.toString(); } + public List getReasonList() { + return reasons; + } + + public void copyReasons(Constraint another) { + for (String s: another.getReasonList()) { + reasons.add(s); + } + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java index 10e61545be..a442f95c09 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java @@ -302,35 +302,35 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { @Override public Constraint isLoopInvokationAllowed(Constraint value) { if (objectives.get(0).started.getTime() == 0) - value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 1)); + value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 1), this); return value; } @Override public Constraint isClosedLoopAllowed(Constraint value) { if (objectives.get(3).started.getTime() == 0) - value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 4)); + value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 4), this); return value; } @Override public Constraint isAutosensModeEnabled(Constraint value) { if (objectives.get(5).started.getTime() == 0) - value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 6)); + value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 6), this); return value; } @Override public Constraint isAMAModeEnabled(Constraint value) { if (objectives.get(6).started.getTime() == 0) - value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 7)); + value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 7), this); return value; } @Override public Constraint isSMBModeEnabled(Constraint value) { if (objectives.get(7).started.getTime() == 0) - value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 8)); + value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 8), this); return value; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java index 4759b11ad7..0b3f408498 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java @@ -3,16 +3,12 @@ package info.nightscout.androidaps.plugins.ConstraintsSafety; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Objects; - -import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.PluginBase; -import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.HardLimits; @@ -99,18 +95,18 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface { @Override public Constraint isLoopInvokationAllowed(Constraint value) { if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable) - value.set(false, MainApp.gs(R.string.pumpisnottempbasalcapable)); + value.set(false, MainApp.gs(R.string.pumpisnottempbasalcapable), this); return value; } @Override public Constraint isClosedLoopAllowed(Constraint value) { if (!MainApp.isEngineeringModeOrRelease()) - value.set(false, MainApp.gs(R.string.closed_loop_disabled_on_dev_branch)); + value.set(false, MainApp.gs(R.string.closed_loop_disabled_on_dev_branch), this); String mode = SP.getString("aps_mode", "open"); if (!mode.equals("closed")) - value.set(false, MainApp.gs(R.string.closedmodedisabledinpreferences)); + value.set(false, MainApp.gs(R.string.closedmodedisabledinpreferences), this); return value; } @@ -123,7 +119,7 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface { public Constraint isAMAModeEnabled(Constraint value) { boolean enabled = SP.getBoolean("openapsama_useautosens", false); if (!enabled) - value.set(false, MainApp.gs(R.string.amadisabledinpreferences)); + value.set(false, MainApp.gs(R.string.amadisabledinpreferences), this); return value; } @@ -131,26 +127,26 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface { public Constraint isSMBModeEnabled(Constraint value) { boolean enabled = SP.getBoolean(R.string.key_use_smb, false); if (!enabled) - value.set(false, MainApp.gs(R.string.smbdisabledinpreferences)); + value.set(false, MainApp.gs(R.string.smbdisabledinpreferences), this); return value; } @Override public Constraint applyBasalConstraints(Constraint absoluteRate, Profile profile) { - absoluteRate.setIfGreater(0d, String.format(MainApp.gs(R.string.limitingbasalratio), 0d, MainApp.gs(R.string.basalmustbepositivevalue))); + absoluteRate.setIfGreater(0d, String.format(MainApp.gs(R.string.limitingbasalratio), 0d, MainApp.gs(R.string.basalmustbepositivevalue)), this); double maxBasal = SP.getDouble(R.string.key_openapsma_max_basal, 1d); - absoluteRate.setIfSmaller(maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), maxBasal, MainApp.gs(R.string.maxbasalinpreferences))); + absoluteRate.setIfSmaller(maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), maxBasal, MainApp.gs(R.string.maxbasalinpreferences)), this); // Check percentRate but absolute rate too, because we know real current basal in pump Double maxBasalMult = SP.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d); double maxFromBasalMult = Math.floor(maxBasalMult * profile.getBasal() * 100) / 100; - absoluteRate.setIfSmaller(maxFromBasalMult, String.format(MainApp.gs(R.string.limitingbasalratio), maxFromBasalMult, MainApp.gs(R.string.maxbasalmultiplier))); + absoluteRate.setIfSmaller(maxFromBasalMult, String.format(MainApp.gs(R.string.limitingbasalratio), maxFromBasalMult, MainApp.gs(R.string.maxbasalmultiplier)), this); Double maxBasalFromDaily = SP.getDouble(R.string.key_openapsama_max_daily_safety_multiplier, 3d); double maxFromDaily = Math.floor(profile.getMaxDailyBasal() * maxBasalFromDaily * 100) / 100; - absoluteRate.setIfSmaller(maxFromDaily, String.format(MainApp.gs(R.string.limitingbasalratio), maxFromDaily, MainApp.gs(R.string.maxdailybasalmultiplier))); + absoluteRate.setIfSmaller(maxFromDaily, String.format(MainApp.gs(R.string.limitingbasalratio), maxFromDaily, MainApp.gs(R.string.maxdailybasalmultiplier)), this); return absoluteRate; } @@ -160,18 +156,18 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface { Double currentBasal = profile.getBasal(); Double absoluteRate = currentBasal * ((double) percentRate.originalValue() / 100); - percentRate.reason("Percent rate " + percentRate.originalValue() + "% recalculated to " + DecimalFormatter.to2Decimal(absoluteRate) + " U/h with current basal " + DecimalFormatter.to2Decimal(currentBasal) + " U/h"); + percentRate.reason("Percent rate " + percentRate.originalValue() + "% recalculated to " + DecimalFormatter.to2Decimal(absoluteRate) + " U/h with current basal " + DecimalFormatter.to2Decimal(currentBasal) + " U/h", this); Constraint absoluteConstraint = new Constraint<>(absoluteRate); applyBasalConstraints(absoluteConstraint, profile); - + percentRate.copyReasons(absoluteConstraint); Integer percentRateAfterConst = Double.valueOf(absoluteConstraint.value() / currentBasal * 100).intValue(); if (percentRateAfterConst < 100) percentRateAfterConst = Round.ceilTo((double) percentRateAfterConst, 10d).intValue(); else percentRateAfterConst = Round.floorTo((double) percentRateAfterConst, 10d).intValue(); - percentRate.set(percentRateAfterConst, String.format(MainApp.gs(R.string.limitingpercentrate), percentRateAfterConst, MainApp.gs(R.string.pumplimit))); + percentRate.set(percentRateAfterConst, String.format(MainApp.gs(R.string.limitingpercentrate), percentRateAfterConst, MainApp.gs(R.string.pumplimit)), this); return percentRate; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index aaa5c8e165..c0219f110f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -1428,7 +1428,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf @Override public Constraint isLoopInvokationAllowed(Constraint value) { if (!validBasalRateProfileSelectedOnPump) - value.set(false, MainApp.gs(R.string.novalidbasalrate)); + value.set(false, MainApp.gs(R.string.novalidbasalrate), this); return value; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java index c236ee6716..bd5ea1bb7f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java @@ -7,7 +7,6 @@ import org.json.JSONObject; import org.slf4j.Logger; import java.util.Date; -import java.util.Objects; import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Config; @@ -19,13 +18,13 @@ import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.DanaRInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; @@ -462,14 +461,14 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface, @Override public Constraint applyBasalConstraints(Constraint absoluteRate, Profile profile) { if (pump != null) - absoluteRate.setIfSmaller(pump.maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), pump.maxBasal, MainApp.gs(R.string.pumplimit))); + absoluteRate.setIfSmaller(pump.maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), pump.maxBasal, MainApp.gs(R.string.pumplimit)), this); return absoluteRate; } @Override public Constraint applyBasalPercentConstraints(Constraint percentRate, Profile profile) { - percentRate.setIfGreater(0, String.format(MainApp.gs(R.string.limitingpercentrate), 0, MainApp.gs(R.string.basalmustbepositivevalue))); - percentRate.setIfSmaller(getPumpDescription().maxTempPercent, String.format(MainApp.gs(R.string.limitingpercentrate), getPumpDescription().maxTempPercent, MainApp.gs(R.string.pumplimit))); + percentRate.setIfGreater(0, String.format(MainApp.gs(R.string.limitingpercentrate), 0, MainApp.gs(R.string.basalmustbepositivevalue)), this); + percentRate.setIfSmaller(getPumpDescription().maxTempPercent, String.format(MainApp.gs(R.string.limitingpercentrate), getPumpDescription().maxTempPercent, MainApp.gs(R.string.pumplimit)), this); return percentRate; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index 93148349af..5dd5352335 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -15,7 +15,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Date; -import java.util.Objects; import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Config; @@ -30,13 +29,13 @@ import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.events.EventAppExit; +import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.DanaRInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; @@ -301,14 +300,14 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface, @Override public Constraint applyBasalConstraints(Constraint absoluteRate, Profile profile) { if (pump != null) - absoluteRate.setIfSmaller(pump.maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), pump.maxBasal, MainApp.gs(R.string.pumplimit))); + absoluteRate.setIfSmaller(pump.maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), pump.maxBasal, MainApp.gs(R.string.pumplimit)), this); return absoluteRate; } @Override public Constraint applyBasalPercentConstraints(Constraint percentRate, Profile profile) { - percentRate.setIfGreater(0, String.format(MainApp.gs(R.string.limitingpercentrate), 0, MainApp.gs(R.string.basalmustbepositivevalue))); - percentRate.setIfSmaller(getPumpDescription().maxTempPercent, String.format(MainApp.gs(R.string.limitingpercentrate), getPumpDescription().maxTempPercent, MainApp.gs(R.string.pumplimit))); + percentRate.setIfGreater(0, String.format(MainApp.gs(R.string.limitingpercentrate), 0, MainApp.gs(R.string.basalmustbepositivevalue)), this); + percentRate.setIfSmaller(getPumpDescription().maxTempPercent, String.format(MainApp.gs(R.string.limitingpercentrate), getPumpDescription().maxTempPercent, MainApp.gs(R.string.pumplimit)), this); return percentRate; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java index ea114d1da8..d3dae07d01 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java @@ -1116,15 +1116,15 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints @Override public Constraint applyBasalConstraints(Constraint absoluteRate, Profile profile) { if (statusResult != null) { - absoluteRate.setIfSmaller(statusResult.maximumBasalAmount, String.format(MainApp.gs(R.string.limitingbasalratio), statusResult.maximumBasalAmount, MainApp.gs(R.string.pumplimit))); + absoluteRate.setIfSmaller(statusResult.maximumBasalAmount, String.format(MainApp.gs(R.string.limitingbasalratio), statusResult.maximumBasalAmount, MainApp.gs(R.string.pumplimit)), this); } return absoluteRate; } @Override public Constraint applyBasalPercentConstraints(Constraint percentRate, Profile profile) { - percentRate.setIfGreater(0, String.format(MainApp.gs(R.string.limitingpercentrate), 0, MainApp.gs(R.string.basalmustbepositivevalue))); - percentRate.setIfSmaller(getPumpDescription().maxTempPercent, String.format(MainApp.gs(R.string.limitingpercentrate), getPumpDescription().maxTempPercent, MainApp.gs(R.string.pumplimit))); + percentRate.setIfGreater(0, String.format(MainApp.gs(R.string.limitingpercentrate), 0, MainApp.gs(R.string.basalmustbepositivevalue)), this); + percentRate.setIfSmaller(getPumpDescription().maxTempPercent, String.format(MainApp.gs(R.string.limitingpercentrate), getPumpDescription().maxTempPercent, MainApp.gs(R.string.pumplimit)), this); return percentRate; } diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintTest.java b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintTest.java index 36953e9922..01c3a927f7 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintTest.java +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintTest.java @@ -21,23 +21,23 @@ public class ConstraintTest { b.set(false); Assert.assertEquals(Boolean.FALSE, b.value()); Assert.assertEquals("", b.getReasons()); - b.set(true, "Set true"); + b.set(true, "Set true", this); Assert.assertEquals(Boolean.TRUE, b.value()); - Assert.assertEquals("Set true", b.getReasons()); - b.set(false, "Set false"); + Assert.assertEquals("ConstraintTest: Set true", b.getReasons()); + b.set(false, "Set false", this); Assert.assertEquals(Boolean.FALSE, b.value()); - Assert.assertEquals("Set true\nSet false", b.getReasons()); + Assert.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getReasons()); Constraint d = new Constraint<>(10d); - d.set(5d, "Set 5d"); + d.set(5d, "Set 5d", this); Assert.assertEquals(5d, d.value()); - Assert.assertEquals("Set 5d", d.getReasons()); - d.setIfSmaller(6d, "Set 6d"); + Assert.assertEquals("ConstraintTest: Set 5d", d.getReasons()); + d.setIfSmaller(6d, "Set 6d", this); Assert.assertEquals(5d, d.value()); - Assert.assertEquals("Set 5d\nSet 6d", d.getReasons()); - d.setIfSmaller(4d, "Set 4d"); + Assert.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d", d.getReasons()); + d.setIfSmaller(4d, "Set 4d", this); Assert.assertEquals(4d, d.value()); - Assert.assertEquals("Set 5d\nSet 6d\nSet 4d", d.getReasons()); + Assert.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d", d.getReasons()); Assert.assertEquals(10d, d.originalValue()); } } diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java index a3360333b6..46daf30a79 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java @@ -200,18 +200,18 @@ public class ConstraintsCheckerTest { Constraint d = new Constraint<>(-0.5d); constraintChecker.applyBasalConstraints(d, profile); Assert.assertEquals(0d, d.value()); - Assert.assertEquals("Limiting basal rate to 0.00 U/h because of basal must be positive value", d.getReasons()); + Assert.assertEquals("SafetyPlugin: Limiting basal rate to 0.00 U/h because of basal must be positive value", d.getReasons()); // Apply all limits d = new Constraint<>(Constants.REALLYHIGHBASALRATE); constraintChecker.applyBasalConstraints(d, profile); Assert.assertEquals(0.8d, d.value()); - Assert.assertEquals("Limiting basal rate to 1.00 U/h because of max basal settings in preferences\n" + - "Limiting basal rate to 4.00 U/h because of max basal multiplier\n" + - "Limiting basal rate to 3.00 U/h because of max daily basal multiplier\n" + - "Limiting basal rate to 0.80 U/h because of pump limit\n" + - "Limiting basal rate to 0.80 U/h because of pump limit\n" + - "Limiting basal rate to 1.10 U/h because of pump limit", d.getReasons()); + Assert.assertEquals("SafetyPlugin: Limiting basal rate to 1.00 U/h because of max basal settings in preferences\n" + + "SafetyPlugin: Limiting basal rate to 4.00 U/h because of max basal multiplier\n" + + "SafetyPlugin: Limiting basal rate to 3.00 U/h because of max daily basal multiplier\n" + + "DanaRPlugin: Limiting basal rate to 0.80 U/h because of pump limit\n" + + "DanaRSPlugin: Limiting basal rate to 0.80 U/h because of pump limit\n" + + "InsightPumpPlugin: Limiting basal rate to 1.10 U/h because of pump limit", d.getReasons()); } @@ -239,21 +239,25 @@ public class ConstraintsCheckerTest { Constraint i = new Constraint<>(-22); constraintChecker.applyBasalPercentConstraints(i, profile); Assert.assertEquals((Integer)0, i.value()); - Assert.assertEquals("Percent rate -22% recalculated to -0.22 U/h with current basal 1.00 U/h\n" + // SafetyPlugin - "Limiting percent rate to 0% because of pump limit\n" + // SafetyPlugin - "Limiting percent rate to 0% because of basal must be positive value\n" + // DanaRPlugin - "Limiting percent rate to 0% because of basal must be positive value\n" + // DanaRSPlugin - "Limiting percent rate to 0% because of basal must be positive value", i.getReasons()); // InsightPlugin + Assert.assertEquals("SafetyPlugin: Percent rate -22% recalculated to -0.22 U/h with current basal 1.00 U/h\n" + + "SafetyPlugin: Limiting basal rate to 0.00 U/h because of basal must be positive value\n" + + "SafetyPlugin: Limiting percent rate to 0% because of pump limit\n" + + "DanaRPlugin: Limiting percent rate to 0% because of basal must be positive value\n" + + "DanaRSPlugin: Limiting percent rate to 0% because of basal must be positive value\n" + + "InsightPumpPlugin: Limiting percent rate to 0% because of basal must be positive value", i.getReasons()); // InsightPlugin // Apply all limits i = new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE); constraintChecker.applyBasalPercentConstraints(i, profile); Assert.assertEquals((Integer)100, i.value()); - Assert.assertEquals("Percent rate 1111111% recalculated to 11111.11 U/h with current basal 1.00 U/h\n" + // SafetyPlugin - "Limiting percent rate to 100% because of pump limit\n" + - "Limiting percent rate to 200% because of pump limit\n" + - "Limiting percent rate to 200% because of pump limit\n" + - "Limiting percent rate to 250% because of pump limit", i.getReasons()); + Assert.assertEquals("SafetyPlugin: Percent rate 1111111% recalculated to 11111.11 U/h with current basal 1.00 U/h\n" + + "SafetyPlugin: Limiting basal rate to 1.00 U/h because of max basal settings in preferences\n" + + "SafetyPlugin: Limiting basal rate to 4.00 U/h because of max basal multiplier\n" + + "SafetyPlugin: Limiting basal rate to 3.00 U/h because of max daily basal multiplier\n" + + "SafetyPlugin: Limiting percent rate to 100% because of pump limit\n" + + "DanaRPlugin: Limiting percent rate to 200% because of pump limit\n" + + "DanaRSPlugin: Limiting percent rate to 200% because of pump limit\n" + + "InsightPumpPlugin: Limiting percent rate to 250% because of pump limit", i.getReasons()); }