fix test coverage
This commit is contained in:
parent
ce0730793f
commit
12883a407e
1 changed files with 40 additions and 43 deletions
|
@ -1,8 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
|
package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
@ -10,9 +8,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
import info.AAPSMocker;
|
import info.AAPSMocker;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.ToastUtils;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -22,7 +18,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({MainApp.class, SP.class})
|
@PrepareForTest({MainApp.class, SP.class})
|
||||||
public class DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest extends DanaRS_Packet_APS_Basal_Set_Temporary_Basal {
|
public class DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void runTest() {
|
public void runTest() {
|
||||||
|
@ -30,57 +26,58 @@ public class DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest extends DanaRS_Pack
|
||||||
AAPSMocker.mockApplicationContext();
|
AAPSMocker.mockApplicationContext();
|
||||||
AAPSMocker.mockSP();
|
AAPSMocker.mockSP();
|
||||||
// under 100% should last 30 min
|
// under 100% should last 30 min
|
||||||
setParams(0);
|
DanaRS_Packet_APS_Basal_Set_Temporary_Basal packet = new DanaRS_Packet_APS_Basal_Set_Temporary_Basal();
|
||||||
assertEquals(0, temporaryBasalRatio);
|
packet.setParams(0);
|
||||||
assertEquals(PARAM30MIN, temporaryBasalDuration);
|
assertEquals(0, packet.temporaryBasalRatio);
|
||||||
|
assertEquals(packet.PARAM30MIN, packet.temporaryBasalDuration);
|
||||||
// over 100% should last 15 min
|
// over 100% should last 15 min
|
||||||
setParams(150);
|
packet.setParams(150);
|
||||||
assertEquals(150, temporaryBasalRatio);
|
assertEquals(150, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM15MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
|
||||||
// test low hard limit
|
// test low hard limit
|
||||||
setParams(-1);
|
packet.setParams(-1);
|
||||||
assertEquals(0, temporaryBasalRatio);
|
assertEquals(0, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM30MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM30MIN, packet.temporaryBasalDuration);
|
||||||
// test high hard limit
|
// test high hard limit
|
||||||
setParams(550);
|
packet.setParams(550);
|
||||||
assertEquals(500, temporaryBasalRatio);
|
assertEquals(500, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM15MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
|
||||||
// test setting 15 min
|
// test setting 15 min
|
||||||
setParams(50, true, false);
|
packet.setParams(50, true, false);
|
||||||
assertEquals(50, temporaryBasalRatio);
|
assertEquals(50, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM15MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
|
||||||
// test setting 30 min
|
// test setting 30 min
|
||||||
setParams(50, false, true);
|
packet.setParams(50, false, true);
|
||||||
assertEquals(50, temporaryBasalRatio);
|
assertEquals(50, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM30MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM30MIN, packet.temporaryBasalDuration);
|
||||||
// over 200% set always 15 min
|
// over 200% set always 15 min
|
||||||
setParams(250, false, true);
|
packet.setParams(250, false, true);
|
||||||
assertEquals(250, temporaryBasalRatio);
|
assertEquals(250, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM15MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
|
||||||
// test low hard limit
|
// test low hard limit
|
||||||
setParams(-1, false, true);
|
packet.setParams(-1, false, true);
|
||||||
assertEquals(0, temporaryBasalRatio);
|
assertEquals(0, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM30MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM30MIN, packet.temporaryBasalDuration);
|
||||||
// test high hard limit
|
// test high hard limit
|
||||||
setParams(550, false,true);
|
packet.setParams(550, false, true);
|
||||||
assertEquals(500, temporaryBasalRatio);
|
assertEquals(500, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM15MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
|
||||||
|
|
||||||
// test message generation
|
// test message generation
|
||||||
setParams(260, true, false);
|
packet.setParams(260, true, false);
|
||||||
byte[] generatedCode = getRequestParams();
|
byte[] generatedCode = packet.getRequestParams();
|
||||||
assertEquals(3 , generatedCode.length);
|
assertEquals(3, generatedCode.length);
|
||||||
assertEquals((byte)4 , generatedCode[0]);
|
assertEquals((byte) 4, generatedCode[0]);
|
||||||
assertEquals((byte)1 , generatedCode[1]);
|
assertEquals((byte) 1, generatedCode[1]);
|
||||||
assertEquals((byte)PARAM15MIN, generatedCode[2]);
|
assertEquals((byte) packet.PARAM15MIN, generatedCode[2]);
|
||||||
|
|
||||||
// test message decoding
|
// test message decoding
|
||||||
handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0});
|
packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0});
|
||||||
assertEquals(false, failed);
|
assertEquals(false, packet.failed);
|
||||||
handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 1});
|
packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 1});
|
||||||
assertEquals(true, failed);
|
assertEquals(true, packet.failed);
|
||||||
|
|
||||||
assertEquals("BASAL__APS_SET_TEMPORARY_BASAL", getFriendlyName());
|
assertEquals("BASAL__APS_SET_TEMPORARY_BASAL", packet.getFriendlyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue