PumpEnactTestResult
This commit is contained in:
parent
c20d74b1d9
commit
e4f2049405
4 changed files with 246 additions and 46 deletions
|
@ -21,19 +21,19 @@ public class PumpEnactResult {
|
|||
public String comment = "";
|
||||
|
||||
// Result of basal change
|
||||
public Integer duration = -1; // duration set [minutes]
|
||||
public int duration = -1; // duration set [minutes]
|
||||
public double absolute = -1d; // absolute rate [U/h] , isPercent = false
|
||||
public int percent = -1; // percent of current basal [%] (100% = current basal), isPercent = true
|
||||
public boolean isPercent = false; // if true percent is used, otherwise absolute
|
||||
public boolean isTempCancel = false; // if true we are caceling temp basal
|
||||
// Result of treatment delivery
|
||||
public Double bolusDelivered = 0d; // real value of delivered insulin
|
||||
public Double carbsDelivered = 0d; // real value of delivered carbs
|
||||
public double bolusDelivered = 0d; // real value of delivered insulin
|
||||
public double carbsDelivered = 0d; // real value of delivered carbs
|
||||
|
||||
public boolean queued = false;
|
||||
|
||||
public PumpEnactResult success(boolean success) {
|
||||
this.success = success;
|
||||
this.success = success;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -87,76 +87,83 @@ public class PumpEnactResult {
|
|||
return this;
|
||||
}
|
||||
|
||||
public String log() {
|
||||
return "Success: " + success + " Enacted: " + enacted + " Comment: " + comment + " Duration: " + duration + " Absolute: " + absolute + " Percent: " + percent + " IsPercent: " + isPercent + " Queued: " + queued;
|
||||
public String log() {
|
||||
return "Success: " + success +
|
||||
" Enacted: " + enacted +
|
||||
" Comment: " + comment +
|
||||
" Duration: " + duration +
|
||||
" Absolute: " + absolute +
|
||||
" Percent: " + percent +
|
||||
" IsPercent: " + isPercent +
|
||||
" IsTempCancel: " + isTempCancel +
|
||||
" bolusDelivered: " + bolusDelivered +
|
||||
" carbsDelivered: " + carbsDelivered +
|
||||
" Queued: " + queued;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String ret = MainApp.sResources.getString(R.string.success) + ": " + success;
|
||||
String ret = MainApp.gs(R.string.success) + ": " + success;
|
||||
if (enacted) {
|
||||
if (bolusDelivered > 0) {
|
||||
ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted;
|
||||
ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + MainApp.sResources.getString(R.string.smb_shortname)
|
||||
ret += "\n" + MainApp.gs(R.string.enacted) + ": " + enacted;
|
||||
ret += "\n" + MainApp.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + MainApp.gs(R.string.smb_shortname)
|
||||
+ ": " + bolusDelivered + " " + MainApp.gs(R.string.insulin_unit_shortname);
|
||||
} else if (isTempCancel) {
|
||||
ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted;
|
||||
ret += "\n" + MainApp.gs(R.string.enacted) + ": " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment;
|
||||
ret += MainApp.sResources.getString(R.string.canceltemp);
|
||||
ret += "\n" + MainApp.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + MainApp.gs(R.string.canceltemp);
|
||||
} else if (isPercent) {
|
||||
ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted;
|
||||
ret += "\n" + MainApp.gs(R.string.enacted) + ": " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + MainApp.sResources.getString(R.string.duration) + ": " + duration + " min";
|
||||
ret += "\n" + MainApp.sResources.getString(R.string.percent) + ": " + percent + "%";
|
||||
ret += "\n" + MainApp.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + MainApp.gs(R.string.duration) + ": " + duration + " min";
|
||||
ret += "\n" + MainApp.gs(R.string.percent) + ": " + percent + "%";
|
||||
} else {
|
||||
ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted;
|
||||
ret += "\n" + MainApp.gs(R.string.enacted) + ": " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + MainApp.sResources.getString(R.string.duration) + ": " + duration + " min";
|
||||
ret += "\n" + MainApp.sResources.getString(R.string.absolute) + ": " + absolute + " U/h";
|
||||
ret += "\n" + MainApp.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + MainApp.gs(R.string.duration) + ": " + duration + " min";
|
||||
ret += "\n" + MainApp.gs(R.string.absolute) + ": " + absolute + " U/h";
|
||||
}
|
||||
} else {
|
||||
ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + MainApp.gs(R.string.comment) + ": " + comment;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Spanned toSpanned() {
|
||||
String ret = "<b>" + MainApp.sResources.getString(R.string.success) + "</b>: " + success;
|
||||
public String toHtml() {
|
||||
String ret = "<b>" + MainApp.gs(R.string.success) + "</b>: " + success;
|
||||
if (queued) {
|
||||
ret = MainApp.sResources.getString(R.string.waitingforpumpresult);
|
||||
ret = MainApp.gs(R.string.waitingforpumpresult);
|
||||
} else if (enacted) {
|
||||
if (bolusDelivered > 0) {
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted;
|
||||
ret += "<br><b>" + MainApp.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.smb_shortname) + "</b>: " + bolusDelivered + " " + MainApp.gs(R.string.insulin_unit_shortname);
|
||||
ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + MainApp.gs(R.string.smb_shortname) + "</b>: " + bolusDelivered + " " + MainApp.gs(R.string.insulin_unit_shortname);
|
||||
} else if (isTempCancel) {
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted;
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment +
|
||||
"<br>" + MainApp.sResources.getString(R.string.canceltemp);
|
||||
ret += "<br><b>" + MainApp.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment +
|
||||
"<br>" + MainApp.gs(R.string.canceltemp);
|
||||
} else if (isPercent && percent != -1) {
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted;
|
||||
ret += "<br><b>" + MainApp.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.duration) + "</b>: " + duration + " min";
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.percent) + "</b>: " + percent + "%";
|
||||
ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + MainApp.gs(R.string.duration) + "</b>: " + duration + " min";
|
||||
ret += "<br><b>" + MainApp.gs(R.string.percent) + "</b>: " + percent + "%";
|
||||
} else if (absolute != -1) {
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted;
|
||||
ret += "<br><b>" + MainApp.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.duration) + "</b>: " + duration + " min";
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.absolute) + "</b>: " + DecimalFormatter.to2Decimal(absolute) + " U/h";
|
||||
ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + MainApp.gs(R.string.duration) + "</b>: " + duration + " min";
|
||||
ret += "<br><b>" + MainApp.gs(R.string.absolute) + "</b>: " + DecimalFormatter.to2Decimal(absolute) + " U/h";
|
||||
}
|
||||
} else {
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment;
|
||||
}
|
||||
return Html.fromHtml(ret);
|
||||
}
|
||||
|
||||
public PumpEnactResult() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public JSONObject json(Profile profile) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.Loop;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -95,8 +96,8 @@ public class LoopFragment extends SubscriberFragment {
|
|||
sourceView.setText(lastRun.source != null ? lastRun.source : "");
|
||||
lastRunView.setText(lastRun.lastAPSRun != null && lastRun.lastAPSRun.getTime() != 0 ? lastRun.lastAPSRun.toLocaleString() : "");
|
||||
lastEnactView.setText(lastRun.lastEnact != null && lastRun.lastEnact.getTime() != 0 ? lastRun.lastEnact.toLocaleString() : "");
|
||||
tbrSetByPumpView.setText(lastRun.tbrSetByPump != null ? lastRun.tbrSetByPump.toSpanned() : "");
|
||||
smbSetByPumpView.setText(lastRun.smbSetByPump != null ? lastRun.smbSetByPump.toSpanned() : "");
|
||||
tbrSetByPumpView.setText(lastRun.tbrSetByPump != null ? Html.fromHtml(lastRun.tbrSetByPump.toHtml()) : "");
|
||||
smbSetByPumpView.setText(lastRun.smbSetByPump != null ? Html.fromHtml(lastRun.smbSetByPump.toHtml()) : "");
|
||||
|
||||
String constraints = "";
|
||||
if (lastRun.constraintsProcessed != null) {
|
||||
|
|
|
@ -66,6 +66,16 @@ public class AAPSMocker {
|
|||
when(MainApp.gs(R.string.short_avgdelta)).thenReturn("Short avg. delta");
|
||||
when(MainApp.gs(R.string.long_avgdelta)).thenReturn("Long avg. delta");
|
||||
when(MainApp.gs(R.string.zerovalueinprofile)).thenReturn("Invalid profile: %s");
|
||||
when(MainApp.gs(R.string.success)).thenReturn("Success");
|
||||
when(MainApp.gs(R.string.enacted)).thenReturn("Enacted");
|
||||
when(MainApp.gs(R.string.comment)).thenReturn("Comment");
|
||||
when(MainApp.gs(R.string.smb_shortname)).thenReturn("SMB");
|
||||
when(MainApp.gs(R.string.canceltemp)).thenReturn("Cancel temp basal");
|
||||
when(MainApp.gs(R.string.duration)).thenReturn("Duration");
|
||||
when(MainApp.gs(R.string.percent)).thenReturn("Percent");
|
||||
when(MainApp.gs(R.string.absolute)).thenReturn("Absolute");
|
||||
when(MainApp.gs(R.string.waitingforpumpresult)).thenReturn("Waiting for result");
|
||||
when(MainApp.gs(R.string.insulin_unit_shortname)).thenReturn("U");
|
||||
}
|
||||
|
||||
public static MainApp mockMainApp() {
|
||||
|
|
|
@ -0,0 +1,182 @@
|
|||
package info.nightscout.androidaps.data;
|
||||
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.skyscreamer.jsonassert.JSONAssert;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
* Created by mike on 29.03.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, Html.class})
|
||||
public class PumpEnactResultTest {
|
||||
|
||||
PumpEnactResult per = new PumpEnactResult();
|
||||
|
||||
@Test
|
||||
public void successTest() throws Exception {
|
||||
per.success(true);
|
||||
Assert.assertEquals(true, per.success);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enactedTest() throws Exception {
|
||||
per.enacted(true);
|
||||
Assert.assertEquals(true, per.enacted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void commentTest() throws Exception {
|
||||
per.comment("SomeComment");
|
||||
Assert.assertEquals("SomeComment", per.comment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void durationTest() throws Exception {
|
||||
per.duration(10);
|
||||
Assert.assertEquals(10, per.duration);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void absoluteTest() throws Exception {
|
||||
per.absolute(11d);
|
||||
Assert.assertEquals(11d, per.absolute, 0.01d);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void percentTest() throws Exception {
|
||||
per.percent(10);
|
||||
Assert.assertEquals((int) 10, per.percent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPercentTest() throws Exception {
|
||||
per.isPercent(true);
|
||||
Assert.assertEquals(true, per.isPercent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isTempCancelTest() throws Exception {
|
||||
per.isTempCancel(true);
|
||||
Assert.assertEquals(true, per.isTempCancel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bolusDeliveredTest() throws Exception {
|
||||
per.bolusDelivered(11d);
|
||||
Assert.assertEquals(11d, per.bolusDelivered, 0.01d);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void carbsDeliveredTest() throws Exception {
|
||||
per.carbsDelivered(11d);
|
||||
Assert.assertEquals(11d, per.carbsDelivered, 0.01d);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queuedTest() throws Exception {
|
||||
per.queued(true);
|
||||
Assert.assertEquals(true, per.queued);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void logTest() throws Exception {
|
||||
per = new PumpEnactResult();
|
||||
Assert.assertEquals("Success: false Enacted: false Comment: Duration: -1 Absolute: -1.0 Percent: -1 IsPercent: false IsTempCancel: false bolusDelivered: 0.0 carbsDelivered: 0.0 Queued: false", per.log());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringTest() throws Exception {
|
||||
per = new PumpEnactResult().enacted(true).bolusDelivered(10).comment("AAA");
|
||||
Assert.assertEquals("Success: false\n" +
|
||||
"Enacted: true\n" +
|
||||
"Comment: AAA\n" +
|
||||
"SMB: 10.0 U", per.toString());
|
||||
|
||||
per = new PumpEnactResult().enacted(true).isTempCancel(true).comment("AAA");
|
||||
Assert.assertEquals("Success: false\n" +
|
||||
"Enacted: true\n" +
|
||||
"Comment: AAA\n" +
|
||||
"Cancel temp basal", per.toString());
|
||||
|
||||
per = new PumpEnactResult().enacted(true).isPercent(true).percent(90).duration(20).comment("AAA");
|
||||
Assert.assertEquals("Success: false\n" +
|
||||
"Enacted: true\n" +
|
||||
"Comment: AAA\n" +
|
||||
"Duration: 20 min\n" +
|
||||
"Percent: 90%", per.toString());
|
||||
|
||||
per = new PumpEnactResult().enacted(true).isPercent(false).absolute(1).duration(30).comment("AAA");
|
||||
Assert.assertEquals("Success: false\n" +
|
||||
"Enacted: true\n" +
|
||||
"Comment: AAA\n" +
|
||||
"Duration: 30 min\n" +
|
||||
"Absolute: 1.0 U/h", per.toString());
|
||||
|
||||
per = new PumpEnactResult().enacted(false).comment("AAA");
|
||||
Assert.assertEquals("Success: false\n" +
|
||||
"Comment: AAA", per.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toHtmlTest() throws Exception {
|
||||
per = new PumpEnactResult().enacted(true).bolusDelivered(10).comment("AAA");
|
||||
Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br><b>SMB</b>: 10.0 U", per.toHtml());
|
||||
|
||||
per = new PumpEnactResult().enacted(true).isTempCancel(true).comment("AAA");
|
||||
Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br>Cancel temp basal", per.toHtml());
|
||||
|
||||
per = new PumpEnactResult().enacted(true).isPercent(true).percent(90).duration(20).comment("AAA");
|
||||
Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br><b>Duration</b>: 20 min<br><b>Percent</b>: 90%", per.toHtml());
|
||||
|
||||
per = new PumpEnactResult().enacted(true).isPercent(false).absolute(1).duration(30).comment("AAA");
|
||||
Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br><b>Duration</b>: 30 min<br><b>Absolute</b>: 1.00 U/h", per.toHtml());
|
||||
|
||||
per = new PumpEnactResult().enacted(false).comment("AAA");
|
||||
Assert.assertEquals("<b>Success</b>: false<br><b>Comment</b>: AAA", per.toHtml());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsonTest() throws Exception {
|
||||
JSONObject o;
|
||||
per = new PumpEnactResult().enacted(true).bolusDelivered(10).comment("AAA");
|
||||
o = per.json(AAPSMocker.getValidProfile());
|
||||
JSONAssert.assertEquals("{\"smb\":10}", o, false);
|
||||
|
||||
per = new PumpEnactResult().enacted(true).isTempCancel(true).comment("AAA");
|
||||
o = per.json(AAPSMocker.getValidProfile());
|
||||
JSONAssert.assertEquals("{\"rate\":0,\"duration\":0}", o, false);
|
||||
|
||||
per = new PumpEnactResult().enacted(true).isPercent(true).percent(90).duration(20).comment("AAA");
|
||||
o = per.json(AAPSMocker.getValidProfile());
|
||||
JSONAssert.assertEquals("{\"rate\":0.9,\"duration\":20}", o, false);
|
||||
|
||||
per = new PumpEnactResult().enacted(true).isPercent(false).absolute(1).duration(30).comment("AAA");
|
||||
o = per.json(AAPSMocker.getValidProfile());
|
||||
JSONAssert.assertEquals("{\"rate\":1,\"duration\":30}", o, false);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepareMock() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockStrings();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue