Added DeltaType tests and negative delta values allowed
This commit is contained in:
parent
b9ddbe7011
commit
3f86788eb4
|
@ -36,7 +36,7 @@ public class TriggerDelta extends Trigger {
|
||||||
private double maxValue = 1d;
|
private double maxValue = 1d;
|
||||||
private double step = 1;
|
private double step = 1;
|
||||||
private DecimalFormat decimalFormat = new DecimalFormat("1");
|
private DecimalFormat decimalFormat = new DecimalFormat("1");
|
||||||
private String units = ProfileFunctions.getInstance().getProfileUnits();
|
private String units;
|
||||||
private DeltaType deltaType;
|
private DeltaType deltaType;
|
||||||
|
|
||||||
private InputDelta value = new InputDelta( (double) minValue,(double) minValue, (double) maxValue, step, decimalFormat, deltaType);
|
private InputDelta value = new InputDelta( (double) minValue,(double) minValue, (double) maxValue, step, decimalFormat, deltaType);
|
||||||
|
@ -44,11 +44,13 @@ public class TriggerDelta extends Trigger {
|
||||||
|
|
||||||
public TriggerDelta() {
|
public TriggerDelta() {
|
||||||
super();
|
super();
|
||||||
|
this.units = ProfileFunctions.getInstance().getProfileUnits();
|
||||||
initializer();
|
initializer();
|
||||||
}
|
}
|
||||||
|
|
||||||
private TriggerDelta(TriggerDelta triggerDelta) {
|
private TriggerDelta(TriggerDelta triggerDelta) {
|
||||||
super();
|
super();
|
||||||
|
this.units = ProfileFunctions.getInstance().getProfileUnits();
|
||||||
initializer();
|
initializer();
|
||||||
value = triggerDelta.value;
|
value = triggerDelta.value;
|
||||||
lastRun = triggerDelta.lastRun;
|
lastRun = triggerDelta.lastRun;
|
||||||
|
@ -60,7 +62,7 @@ public class TriggerDelta extends Trigger {
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeltaType getType() {
|
public DeltaType getType() {
|
||||||
return value.getDeltaType();
|
return deltaType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUnits() {
|
public String getUnits() {
|
||||||
|
@ -157,6 +159,7 @@ public class TriggerDelta extends Trigger {
|
||||||
|
|
||||||
TriggerDelta setValue(double requestedValue, DeltaType requestedType) {
|
TriggerDelta setValue(double requestedValue, DeltaType requestedType) {
|
||||||
this.value.setValue(requestedValue, requestedType);
|
this.value.setValue(requestedValue, requestedType);
|
||||||
|
this.deltaType = requestedType;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,13 +171,13 @@ public class TriggerDelta extends Trigger {
|
||||||
void initializer(){
|
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 = -4d;
|
||||||
this.step = 0.1d;
|
this.step = 0.1d;
|
||||||
this.decimalFormat = new DecimalFormat("0.1");
|
this.decimalFormat = new DecimalFormat("0.1");
|
||||||
this.deltaType = DeltaType.DELTA;
|
this.deltaType = DeltaType.DELTA;
|
||||||
} else {
|
} else {
|
||||||
this.maxValue = 72d;
|
this.maxValue = 72d;
|
||||||
this.minValue = 2d;
|
this.minValue = -72d;
|
||||||
this.step = 1d;
|
this.step = 1d;
|
||||||
this.deltaType = DeltaType.DELTA;
|
this.deltaType = DeltaType.DELTA;
|
||||||
}
|
}
|
||||||
|
@ -201,16 +204,4 @@ 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,7 +20,6 @@ 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;
|
||||||
|
@ -41,13 +40,18 @@ public class TriggerDeltaTest {
|
||||||
@Test
|
@Test
|
||||||
public void shouldRunTest() {
|
public void shouldRunTest() {
|
||||||
when(IobCobCalculatorPlugin.getPlugin().getBgReadings()).thenReturn(generateValidBgData());
|
when(IobCobCalculatorPlugin.getPlugin().getBgReadings()).thenReturn(generateValidBgData());
|
||||||
|
//Test if time passed is less than 5 min
|
||||||
TriggerDelta t = new TriggerDelta().setUnits(Constants.MGDL).setValue(73d, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL);
|
TriggerDelta t = new TriggerDelta().setUnits(Constants.MGDL).setValue(-3d, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER).lastRun(now-1);
|
||||||
Assert.assertFalse(t.shouldRun());
|
Assert.assertFalse(t.shouldRun());
|
||||||
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(-2d, DeltaType.LONG_AVERAGE).comparator(Comparator.Compare.IS_EQUAL);
|
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(73d, DeltaType.LONG_AVERAGE).comparator(Comparator.Compare.IS_EQUAL);
|
||||||
Assert.assertTrue(t.shouldRun());
|
Assert.assertFalse(t.shouldRun());
|
||||||
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(-3d, DeltaType.LONG_AVERAGE).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER);
|
Assert.assertEquals(DeltaType.LONG_AVERAGE, t.getType());
|
||||||
|
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(-2d, DeltaType.SHORT_AVERAGE).comparator(Comparator.Compare.IS_EQUAL);
|
||||||
|
Assert.assertFalse(t.shouldRun());
|
||||||
|
Assert.assertEquals(DeltaType.SHORT_AVERAGE, t.getType());
|
||||||
|
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(-3d, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER);
|
||||||
Assert.assertTrue(t.shouldRun());
|
Assert.assertTrue(t.shouldRun());
|
||||||
|
Assert.assertEquals(DeltaType.DELTA, t.getType());
|
||||||
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(2d, DeltaType.LONG_AVERAGE).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.LONG_AVERAGE).comparator(Comparator.Compare.IS_EQUAL);
|
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(2d, DeltaType.LONG_AVERAGE).comparator(Comparator.Compare.IS_EQUAL);
|
||||||
|
@ -70,6 +74,8 @@ public class TriggerDeltaTest {
|
||||||
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(214, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL).lastRun(now - 1);
|
t = new TriggerDelta().setUnits(Constants.MGDL).setValue(214, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL).lastRun(now - 1);
|
||||||
Assert.assertFalse(t.shouldRun());
|
Assert.assertFalse(t.shouldRun());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -113,22 +119,6 @@ public class TriggerDeltaTest {
|
||||||
Assert.assertEquals(Optional.of(R.drawable.as), new TriggerDelta().icon());
|
Assert.assertEquals(Optional.of(R.drawable.as), new TriggerDelta().icon());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
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);
|
|
||||||
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);
|
|
||||||
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);
|
|
||||||
Assert.assertEquals(DeltaType.LONG_AVERAGE, t.getType());
|
|
||||||
Assert.assertEquals(-2d, t.deltaValue(), 0d);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void mock() {
|
public void mock() {
|
||||||
AAPSMocker.mockMainApp();
|
AAPSMocker.mockMainApp();
|
||||||
|
@ -142,14 +132,12 @@ public class TriggerDeltaTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void initializerTest(){
|
public void initializerTest(){
|
||||||
PowerMockito.when(ProfileFunctions.getInstance().getProfileUnits()).thenReturn(Constants.MMOL);
|
PowerMockito.when(ProfileFunctions.getInstance().getProfileUnits()).thenReturn(Constants.MMOL);
|
||||||
TriggerDelta t = new TriggerDelta();
|
TriggerDelta t = new TriggerDelta();
|
||||||
Assert.assertTrue(t.getUnits().equals(Constants.MMOL));
|
Assert.assertTrue(t.getUnits().equals(Constants.MMOL));
|
||||||
Assert.assertTrue(t.getUnits().equals(Constants.MGDL));
|
PowerMockito.when(ProfileFunctions.getInstance().getProfileUnits()).thenReturn(Constants.MGDL);
|
||||||
Assert.assertNull(t.getUnits());
|
|
||||||
Assert.assertNotNull(t.getUnits());
|
|
||||||
when(ProfileFunctions.getInstance().getProfileUnits()).thenReturn(Constants.MGDL);
|
|
||||||
t = new TriggerDelta();
|
t = new TriggerDelta();
|
||||||
Assert.assertEquals(Constants.MGDL, t.getUnits());
|
Assert.assertEquals(Constants.MGDL, t.getUnits());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue