DanaRS tests

This commit is contained in:
Milos Kozak 2020-03-01 16:39:23 +01:00
parent 67a5c33f8d
commit 394ba420aa
14 changed files with 199 additions and 456 deletions

View file

@ -1,65 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.utils.SP;
import static org.junit.Assert.assertEquals;
/**
* Created by Rumen on 06.08.2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class})
public class DanaRS_Packet_Bolus_Get_Extended_BolusTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
DanaRS_Packet_Bolus_Get_Extended_Bolus packet = new DanaRS_Packet_Bolus_Get_Extended_Bolus();
// test params
assertEquals(null, packet.getRequestParams());
// test message decoding
double testValue = 0d;
packet.handleMessage(createArray(10, (byte) testValue));
assertEquals(testValue != 0d, packet.failed);
testValue = 1d;
packet.handleMessage(createArray(10, (byte) testValue));
// is pump.bolustep set to 1
DanaRPump pump = DanaRPump.getInstance();
assertEquals(testValue / 100d, pump.bolusStep, 0);
assertEquals(testValue != 0d, packet.failed);
assertEquals("BOLUS__GET_EXTENDED_BOLUS", packet.getFriendlyName());
}
byte[] createArray(int length, byte fillWith){
byte[] ret = new byte[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
double[] createArray(int length, double fillWith){
double[] ret = new double[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
}

View file

@ -0,0 +1,28 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_Bolus_Get_Extended_BolusTest : DanaRSTestBase() {
@Test fun runTest() {
val packet = DanaRS_Packet_Bolus_Get_Extended_Bolus(aapsLogger, danaRPump)
// test params
Assert.assertEquals(null, packet.requestParams)
// test message decoding
var testValue = 0.0
packet.handleMessage(createArray(10, testValue.toByte()))
Assert.assertEquals(testValue != 0.0, packet.failed)
testValue = 1.0
packet.handleMessage(createArray(10, testValue.toByte()))
// is pump.bolustep set to 1
Assert.assertEquals(testValue / 100.0, danaRPump.bolusStep, 0.0)
Assert.assertEquals(testValue != 0.0, packet.failed)
Assert.assertEquals("BOLUS__GET_EXTENDED_BOLUS", packet.friendlyName)
}
}

View file

@ -1,65 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.utils.SP;
import static org.junit.Assert.assertEquals;
/**
* Created by Rumen on 06.08.2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class})
public class DanaRS_Packet_Bolus_Get_Extended_Bolus_StateTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
DanaRS_Packet_Bolus_Get_Extended_Bolus_State packet = new DanaRS_Packet_Bolus_Get_Extended_Bolus_State();
// test params
assertEquals(null, packet.getRequestParams());
// test message decoding
double testValue = 0d;
packet.handleMessage(createArray(11, (byte) testValue));
assertEquals(testValue != 0d, packet.failed);
testValue = 1d;
packet.handleMessage(createArray(11, (byte) testValue));
// is extended bolus in progress
DanaRPump pump = DanaRPump.getInstance();
assertEquals(testValue == 1, pump.isExtendedInProgress);
assertEquals(testValue != 0d, packet.failed);
assertEquals("BOLUS__GET_EXTENDED_BOLUS_STATE", packet.getFriendlyName());
}
byte[] createArray(int length, byte fillWith){
byte[] ret = new byte[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
double[] createArray(int length, double fillWith){
double[] ret = new double[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
}

View file

@ -0,0 +1,31 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.utils.SP
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_Bolus_Get_Extended_Bolus_StateTest : DanaRSTestBase() {
@Test fun runTest() {
val packet = DanaRS_Packet_Bolus_Get_Extended_Bolus_State(aapsLogger, danaRPump)
// test params
Assert.assertEquals(null, packet.requestParams)
// test message decoding
var testValue = 0.0
packet.handleMessage(createArray(11, testValue.toByte()))
Assert.assertEquals(testValue != 0.0, packet.failed)
testValue = 1.0
packet.handleMessage(createArray(11, testValue.toByte()))
// is extended bolus in progress
Assert.assertEquals(testValue == 1.0, danaRPump.isExtendedInProgress)
Assert.assertEquals(testValue != 0.0, packet.failed)
Assert.assertEquals("BOLUS__GET_EXTENDED_BOLUS_STATE", packet.friendlyName)
}
}

View file

@ -1,66 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.utils.SP;
import static org.junit.Assert.assertEquals;
/**
* Created by Rumen on 06.08.2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class})
public class DanaRS_Packet_Bolus_Get_Extended_Menu_Option_StateTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State packet = new DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State();
// test params
byte[] testparams = packet.getRequestParams();
assertEquals(null, packet.getRequestParams());
// test message decoding
packet.handleMessage(createArray(34, (byte) 0));
// isExtendedinprogres should be false
DanaRPump testPump = DanaRPump.getInstance();
assertEquals(false, testPump.isExtendedInProgress);
// assertEquals(false, packet.failed);
packet.handleMessage(createArray(34, (byte) 1));
testPump = DanaRPump.getInstance();
assertEquals(true, testPump.isExtendedInProgress);
assertEquals("BOLUS__GET_EXTENDED_MENU_OPTION_STATE", packet.getFriendlyName());
}
byte[] createArray(int length, byte fillWith){
byte[] ret = new byte[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
double[] createArray(int length, double fillWith){
double[] ret = new double[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
}

View file

@ -0,0 +1,27 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_Bolus_Get_Extended_Menu_Option_StateTest : DanaRSTestBase() {
@Test fun runTest() {
val packet = DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State(aapsLogger, danaRPump)
// test params
val testparams = packet.requestParams
Assert.assertEquals(null, packet.requestParams)
// test message decoding
packet.handleMessage(createArray(34, 0.toByte()))
// isExtendedinprogres should be false
Assert.assertEquals(false, danaRPump.isExtendedInProgress)
// assertEquals(false, packet.failed);
packet.handleMessage(createArray(34, 1.toByte()))
Assert.assertEquals(true, danaRPump.isExtendedInProgress)
Assert.assertEquals("BOLUS__GET_EXTENDED_MENU_OPTION_STATE", packet.friendlyName)
}
}

View file

@ -1,65 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.utils.SP;
import static org.junit.Assert.assertEquals;
/**
* Created by Rumen on 06.08.2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class})
public class DanaRS_Packet_Bolus_Get_Initial_BolusTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
DanaRS_Packet_Bolus_Get_Initial_Bolus packet = new DanaRS_Packet_Bolus_Get_Initial_Bolus();
// test params
byte[] testparams = packet.getRequestParams();
assertEquals(null, packet.getRequestParams());
// test message decoding
packet.handleMessage(createArray(34, (byte) 0));
// should fail only if all the initialbolusses are 0
// DanaRPump testPump = DanaRPump.getInstance();
assertEquals(false, !packet.failed);
// assertEquals(false, packet.failed);
packet.handleMessage(createArray(34, (byte) 1));
int valueRequested = (((byte) 1 & 0x000000FF) << 8) + (((byte) 1) & 0x000000FF);
assertEquals(valueRequested /100d, packet.initialBolusValue04, 0);
assertEquals(true, !packet.failed);
assertEquals("BOLUS__GET_BOLUS_RATE", packet.getFriendlyName());
}
byte[] createArray(int length, byte fillWith){
byte[] ret = new byte[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
double[] createArray(int length, double fillWith){
double[] ret = new double[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
}

View file

@ -0,0 +1,28 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_Bolus_Get_Initial_BolusTest : DanaRSTestBase() {
@Test fun runTest() {
val packet = DanaRS_Packet_Bolus_Get_Initial_Bolus(aapsLogger)
// test params
val testparams = packet.requestParams
Assert.assertEquals(null, packet.requestParams)
// test message decoding
packet.handleMessage(createArray(34, 0.toByte()))
// should fail only if all the initialbolusses are 0
// DanaRPump testPump = DanaRPump.getInstance();
Assert.assertEquals(false, !packet.failed)
// assertEquals(false, packet.failed);
packet.handleMessage(createArray(34, 1.toByte()))
Assert.assertEquals(true, !packet.failed)
Assert.assertEquals("BOLUS__GET_BOLUS_RATE", packet.friendlyName)
}
}

View file

@ -1,65 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.utils.SP;
import static org.junit.Assert.assertEquals;
/**
* Created by Rumen on 06.08.2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class})
public class DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
DanaRS_Packet_Bolus_Get_Step_Bolus_Information packet = new DanaRS_Packet_Bolus_Get_Step_Bolus_Information();
// test params
byte[] testparams = packet.getRequestParams();
assertEquals(null, packet.getRequestParams());
// test message decoding
packet.handleMessage(createArray(34, (byte) 0));
DanaRPump testPump = DanaRPump.getInstance();
assertEquals(false, packet.failed);
packet.handleMessage(createArray(34, (byte) 1));
int valueRequested = (((byte) 1 & 0x000000FF) << 8) + (((byte) 1) & 0x000000FF);
assertEquals(valueRequested /100d, testPump.lastBolusAmount, 0);
assertEquals(true, packet.failed);
assertEquals("BOLUS__GET_STEP_BOLUS_INFORMATION", packet.getFriendlyName());
}
byte[] createArray(int length, byte fillWith){
byte[] ret = new byte[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
double[] createArray(int length, double fillWith){
double[] ret = new double[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
}

View file

@ -0,0 +1,27 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest : DanaRSTestBase() {
@Test fun runTest() {
val packet = DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump)
// test params
val testparams = packet.requestParams
Assert.assertEquals(null, packet.requestParams)
// test message decoding
packet.handleMessage(createArray(34, 0.toByte()))
Assert.assertEquals(false, packet.failed)
packet.handleMessage(createArray(34, 1.toByte()))
val valueRequested: Int = (1 and 0x000000FF shl 8) + (1 and 0x000000FF)
Assert.assertEquals(valueRequested / 100.0, danaRPump.lastBolusAmount, 0.0)
Assert.assertEquals(true, packet.failed)
Assert.assertEquals("BOLUS__GET_STEP_BOLUS_INFORMATION", packet.friendlyName)
}
}

View file

@ -1,65 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.utils.SP;
import static org.junit.Assert.assertEquals;
/**
* Created by Rumen on 06.08.2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class})
public class DanaRS_Packet_Bolus_Set_Bolus_OptionTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
DanaRS_Packet_Bolus_Set_Bolus_Option packet = new DanaRS_Packet_Bolus_Set_Bolus_Option(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
// test params
byte[] testparams = packet.getRequestParams();
assertEquals(0, testparams[0]);
assertEquals(0, testparams[18]);
// test message decoding
packet.handleMessage(createArray(34, (byte) 0));
// DanaRPump testPump = DanaRPump.getInstance();
assertEquals(false, packet.failed);
packet.handleMessage(createArray(34, (byte) 1));
// int valueRequested = (((byte) 1 & 0x000000FF) << 8) + (((byte) 1) & 0x000000FF);
// assertEquals(valueRequested /100d, testPump.lastBolusAmount, 0);
assertEquals(true, packet.failed);
assertEquals("BOLUS__SET_BOLUS_OPTION", packet.getFriendlyName());
}
byte[] createArray(int length, byte fillWith){
byte[] ret = new byte[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
double[] createArray(int length, double fillWith){
double[] ret = new double[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
}

View file

@ -0,0 +1,29 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_Bolus_Set_Bolus_OptionTest : DanaRSTestBase() {
@Test fun runTest() {
val packet = DanaRS_Packet_Bolus_Set_Bolus_Option(aapsLogger, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
// test params
val testparams = packet.requestParams
Assert.assertEquals(0.toByte(), testparams[0])
Assert.assertEquals(0.toByte(), testparams[18])
// test message decoding
packet.handleMessage(createArray(34, 0.toByte()))
// DanaRPump testPump = DanaRPump.getInstance();
Assert.assertEquals(false, packet.failed)
packet.handleMessage(createArray(34, 1.toByte()))
// int valueRequested = (((byte) 1 & 0x000000FF) << 8) + (((byte) 1) & 0x000000FF);
// assertEquals(valueRequested /100d, testPump.lastBolusAmount, 0);
Assert.assertEquals(true, packet.failed)
Assert.assertEquals("BOLUS__SET_BOLUS_OPTION", packet.friendlyName)
}
}

View file

@ -1,65 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.utils.SP;
import static org.junit.Assert.assertEquals;
/**
* Created by Rumen on 06.08.2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class})
public class DanaRS_Packet_Bolus_Set_CIR_CF_ArrayTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
DanaRS_Packet_Bolus_Set_CIR_CF_Array packet = new DanaRS_Packet_Bolus_Set_CIR_CF_Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0);
// test params
byte[] testparams = packet.getRequestParams();
assertEquals(0, testparams[0]);
assertEquals(0, testparams[18]);
// test message decoding
packet.handleMessage(createArray(34, (byte) 0));
// DanaRPump testPump = DanaRPump.getInstance();
assertEquals(false, packet.failed);
packet.handleMessage(createArray(34, (byte) 1));
// int valueRequested = (((byte) 1 & 0x000000FF) << 8) + (((byte) 1) & 0x000000FF);
// assertEquals(valueRequested /100d, testPump.lastBolusAmount, 0);
assertEquals(true, packet.failed);
assertEquals("BOLUS__SET_CIR_CF_ARRAY", packet.getFriendlyName());
}
byte[] createArray(int length, byte fillWith){
byte[] ret = new byte[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
double[] createArray(int length, double fillWith){
double[] ret = new double[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
}

View file

@ -0,0 +1,29 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_Bolus_Set_CIR_CF_ArrayTest : DanaRSTestBase() {
@Test fun runTest() {
val packet = DanaRS_Packet_Bolus_Set_CIR_CF_Array(aapsLogger, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
// test params
val testparams = packet.requestParams
Assert.assertEquals(0.toByte(), testparams[0])
Assert.assertEquals(0.toByte(), testparams[18])
// test message decoding
packet.handleMessage(createArray(34, 0.toByte()))
// DanaRPump testPump = DanaRPump.getInstance();
Assert.assertEquals(false, packet.failed)
packet.handleMessage(createArray(34, 1.toByte()))
// int valueRequested = (((byte) 1 & 0x000000FF) << 8) + (((byte) 1) & 0x000000FF);
// assertEquals(valueRequested /100d, testPump.lastBolusAmount, 0);
Assert.assertEquals(true, packet.failed)
Assert.assertEquals("BOLUS__SET_CIR_CF_ARRAY", packet.friendlyName)
}
}