tests
This commit is contained in:
parent
f15ead9c6f
commit
b9ddbe7011
2 changed files with 42 additions and 11 deletions
|
@ -44,12 +44,12 @@ public class TriggerDelta extends Trigger {
|
||||||
|
|
||||||
public TriggerDelta() {
|
public TriggerDelta() {
|
||||||
super();
|
super();
|
||||||
setUnits();
|
initializer();
|
||||||
}
|
}
|
||||||
|
|
||||||
private TriggerDelta(TriggerDelta triggerDelta) {
|
private TriggerDelta(TriggerDelta triggerDelta) {
|
||||||
super();
|
super();
|
||||||
setUnits();
|
initializer();
|
||||||
value = triggerDelta.value;
|
value = triggerDelta.value;
|
||||||
lastRun = triggerDelta.lastRun;
|
lastRun = triggerDelta.lastRun;
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ public class TriggerDelta extends Trigger {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUnits(){
|
void initializer(){
|
||||||
if (this.units.equals(Constants.MMOL)) {
|
if (this.units.equals(Constants.MMOL)) {
|
||||||
this.maxValue = 4d;
|
this.maxValue = 4d;
|
||||||
this.minValue = 0.1d;
|
this.minValue = 0.1d;
|
||||||
|
@ -201,4 +201,16 @@ public class TriggerDelta extends Trigger {
|
||||||
.build(root);
|
.build(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Used for testing deltaType
|
||||||
|
public double deltaValue(){
|
||||||
|
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||||
|
|
||||||
|
if (deltaType == DeltaType.SHORT_AVERAGE)
|
||||||
|
return glucoseStatus.short_avgdelta;
|
||||||
|
else if (deltaType == DeltaType.LONG_AVERAGE)
|
||||||
|
return glucoseStatus.long_avgdelta;
|
||||||
|
else
|
||||||
|
return glucoseStatus.delta;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -20,6 +20,7 @@ import info.AAPSMocker;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.Comparator;
|
import info.nightscout.androidaps.plugins.general.automation.elements.Comparator;
|
||||||
|
@ -43,21 +44,21 @@ public class TriggerDeltaTest {
|
||||||
|
|
||||||
TriggerDelta t = new TriggerDelta().setUnits(Constants.MGDL).setValue(73d, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL);
|
TriggerDelta t = new TriggerDelta().setUnits(Constants.MGDL).setValue(73d, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL);
|
||||||
Assert.assertFalse(t.shouldRun());
|
Assert.assertFalse(t.shouldRun());
|
||||||
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(-2d, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL);
|
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(-2d, DeltaType.LONG_AVERAGE).comparator(Comparator.Compare.IS_EQUAL);
|
||||||
Assert.assertTrue(t.shouldRun());
|
Assert.assertTrue(t.shouldRun());
|
||||||
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(-3d, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER);
|
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(-3d, DeltaType.LONG_AVERAGE).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER);
|
||||||
Assert.assertTrue(t.shouldRun());
|
Assert.assertTrue(t.shouldRun());
|
||||||
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(2d, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(2d, DeltaType.LONG_AVERAGE).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
||||||
Assert.assertTrue(t.shouldRun());
|
Assert.assertTrue(t.shouldRun());
|
||||||
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(2d, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL);
|
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(2d, DeltaType.LONG_AVERAGE).comparator(Comparator.Compare.IS_EQUAL);
|
||||||
Assert.assertFalse(t.shouldRun());
|
Assert.assertFalse(t.shouldRun());
|
||||||
t = new TriggerDelta().setUnits(Constants.MMOL).setValue(0.3d, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
t = new TriggerDelta().setUnits(Constants.MMOL).setValue(0.3d, DeltaType.LONG_AVERAGE).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
||||||
Assert.assertTrue(t.shouldRun());
|
Assert.assertTrue(t.shouldRun());
|
||||||
t = new TriggerDelta().setUnits(Constants.MMOL).setValue(0.1d, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER);
|
t = new TriggerDelta().setUnits(Constants.MMOL).setValue(0.1d, DeltaType.LONG_AVERAGE).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER);
|
||||||
Assert.assertFalse(t.shouldRun());
|
Assert.assertFalse(t.shouldRun());
|
||||||
t = new TriggerDelta().setUnits(Constants.MMOL).setValue(-0.5d, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER);
|
t = new TriggerDelta().setUnits(Constants.MMOL).setValue(-0.5d, DeltaType.LONG_AVERAGE).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER);
|
||||||
Assert.assertTrue(t.shouldRun());
|
Assert.assertTrue(t.shouldRun());
|
||||||
t = new TriggerDelta().setUnits(Constants.MMOL).setValue(-0.2d, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
t = new TriggerDelta().setUnits(Constants.MMOL).setValue(-0.2d, DeltaType.LONG_AVERAGE).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
||||||
Assert.assertFalse(t.shouldRun());
|
Assert.assertFalse(t.shouldRun());
|
||||||
|
|
||||||
when(IobCobCalculatorPlugin.getPlugin().getBgReadings()).thenReturn(new ArrayList<>());
|
when(IobCobCalculatorPlugin.getPlugin().getBgReadings()).thenReturn(new ArrayList<>());
|
||||||
|
@ -114,12 +115,18 @@ public class TriggerDeltaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deltaTypeTest() {
|
public void deltaTypeTest() {
|
||||||
|
when(IobCobCalculatorPlugin.getPlugin().getBgReadings()).thenReturn(generateValidBgData());
|
||||||
TriggerDelta t = new TriggerDelta().setUnits(Constants.MGDL).setValue(213, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
TriggerDelta t = new TriggerDelta().setUnits(Constants.MGDL).setValue(213, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
||||||
Assert.assertEquals(DeltaType.DELTA, t.getType());
|
Assert.assertEquals(DeltaType.DELTA, t.getType());
|
||||||
|
Assert.assertEquals(-2d, t.deltaValue(), 0d);
|
||||||
|
Assert.assertTrue(t.shouldRun());
|
||||||
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(213, DeltaType.SHORT_AVERAGE).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(213, DeltaType.SHORT_AVERAGE).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
||||||
Assert.assertEquals(DeltaType.SHORT_AVERAGE, t.getType());
|
Assert.assertEquals(DeltaType.SHORT_AVERAGE, t.getType());
|
||||||
|
Assert.assertEquals(-2d, t.deltaValue(), 0d);
|
||||||
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(213, DeltaType.LONG_AVERAGE).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(213, DeltaType.LONG_AVERAGE).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
||||||
Assert.assertEquals(DeltaType.LONG_AVERAGE, t.getType());
|
Assert.assertEquals(DeltaType.LONG_AVERAGE, t.getType());
|
||||||
|
Assert.assertEquals(-2d, t.deltaValue(), 0d);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -135,6 +142,18 @@ public class TriggerDeltaTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void initializerTest(){
|
||||||
|
PowerMockito.when(ProfileFunctions.getInstance().getProfileUnits()).thenReturn(Constants.MMOL);
|
||||||
|
TriggerDelta t = new TriggerDelta();
|
||||||
|
Assert.assertTrue(t.getUnits().equals(Constants.MMOL));
|
||||||
|
Assert.assertTrue(t.getUnits().equals(Constants.MGDL));
|
||||||
|
Assert.assertNull(t.getUnits());
|
||||||
|
Assert.assertNotNull(t.getUnits());
|
||||||
|
when(ProfileFunctions.getInstance().getProfileUnits()).thenReturn(Constants.MGDL);
|
||||||
|
t = new TriggerDelta();
|
||||||
|
Assert.assertEquals(Constants.MGDL, t.getUnits());
|
||||||
|
}
|
||||||
|
|
||||||
List<BgReading> generateValidBgData() {
|
List<BgReading> generateValidBgData() {
|
||||||
List<BgReading> list = new ArrayList<>();
|
List<BgReading> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue