From 44edc7ce9650c358c036d193075fb43c47b0fc92 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 1 Mar 2020 12:06:34 +0100 Subject: [PATCH] DanaRS tests --- .../DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt | 36 +++++----- .../pump/danaRS/comm/DanaRSTestBase.kt | 8 +++ ...anaRS_Packet_Basal_Set_Basal_RateTest.java | 61 ----------------- .../DanaRS_Packet_Basal_Set_Basal_RateTest.kt | 27 ++++++++ ..._Basal_Set_Cancel_Temporary_BasalTest.java | 49 -------------- ...et_Basal_Set_Cancel_Temporary_BasalTest.kt | 22 +++++++ ...cket_Basal_Set_Profile_Basal_RateTest.java | 64 ------------------ ...Packet_Basal_Set_Profile_Basal_RateTest.kt | 28 ++++++++ ...S_Packet_Basal_Set_Profile_NumberTest.java | 61 ----------------- ...aRS_Packet_Basal_Set_Profile_NumberTest.kt | 26 ++++++++ ...naRS_Packet_Basal_Set_Suspend_OffTest.java | 42 ------------ ...DanaRS_Packet_Basal_Set_Suspend_OffTest.kt | 22 +++++++ ...anaRS_Packet_Basal_Set_Suspend_OnTest.java | 42 ------------ .../DanaRS_Packet_Basal_Set_Suspend_OnTest.kt | 22 +++++++ ..._Packet_Basal_Set_Temporary_BasalTest.java | 49 -------------- ...RS_Packet_Basal_Set_Temporary_BasalTest.kt | 28 ++++++++ ...aRS_Packet_Bolus_Get_Bolus_OptionTest.java | 59 ----------------- ...anaRS_Packet_Bolus_Get_Bolus_OptionTest.kt | 35 ++++++++++ ...aRS_Packet_Bolus_Get_CIR_CF_ArrayTest.java | 65 ------------------- ...anaRS_Packet_Bolus_Get_CIR_CF_ArrayTest.kt | 27 ++++++++ ...Bolus_Get_Calculation_InformationTest.java | 61 ----------------- ...t_Bolus_Get_Calculation_InformationTest.kt | 25 +++++++ ...bohydrate_Calculation_InformationTest.java | 61 ----------------- ...arbohydrate_Calculation_InformationTest.kt | 25 +++++++ 24 files changed, 311 insertions(+), 634 deletions(-) delete mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.kt delete mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.kt delete mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_RateTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_RateTest.kt delete mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_NumberTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_NumberTest.kt delete mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_OffTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_OffTest.kt delete mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_OnTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_OnTest.kt delete mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_BasalTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_BasalTest.kt delete mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_OptionTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_OptionTest.kt delete mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_ArrayTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_ArrayTest.kt delete mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_InformationTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_InformationTest.kt delete mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_InformationTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_InformationTest.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt index 50f0c6425a..b157ad9978 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt @@ -2,8 +2,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import com.cozmo.danar.util.BleCommandUtil import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.logging.L -import info.nightscout.androidaps.logging.L.isEnabled import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -94,24 +92,22 @@ class DanaRS_Packet_Bolus_Get_CIR_CF_Array( danaRPump.nightCF = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0 } if (danaRPump.units < 0 || danaRPump.units > 1) failed = true - if (isEnabled(L.PUMPCOMM)) { - aapsLogger.debug(LTag.PUMPCOMM, "Language: $language") - aapsLogger.debug(LTag.PUMPCOMM, "Pump units: " + if (danaRPump.units == DanaRPump.UNITS_MGDL) "MGDL" else "MMOL") - aapsLogger.debug(LTag.PUMPCOMM, "Current pump morning CIR: " + danaRPump.morningCIR) - aapsLogger.debug(LTag.PUMPCOMM, "Current pump morning CF: " + danaRPump.morningCF) - aapsLogger.debug(LTag.PUMPCOMM, "Current pump afternoon CIR: " + danaRPump.afternoonCIR) - aapsLogger.debug(LTag.PUMPCOMM, "Current pump afternoon CF: " + danaRPump.afternoonCF) - aapsLogger.debug(LTag.PUMPCOMM, "Current pump evening CIR: " + danaRPump.eveningCIR) - aapsLogger.debug(LTag.PUMPCOMM, "Current pump evening CF: " + danaRPump.eveningCF) - aapsLogger.debug(LTag.PUMPCOMM, "Current pump night CIR: " + danaRPump.nightCIR) - aapsLogger.debug(LTag.PUMPCOMM, "Current pump night CF: " + danaRPump.nightCF) - aapsLogger.debug(LTag.PUMPCOMM, "cir02: $cir02") - aapsLogger.debug(LTag.PUMPCOMM, "cir04: $cir04") - aapsLogger.debug(LTag.PUMPCOMM, "cir06: $cir06") - aapsLogger.debug(LTag.PUMPCOMM, "cf02: $cf02") - aapsLogger.debug(LTag.PUMPCOMM, "cf04: $cf04") - aapsLogger.debug(LTag.PUMPCOMM, "cf06: $cf06") - } + aapsLogger.debug(LTag.PUMPCOMM, "Language: $language") + aapsLogger.debug(LTag.PUMPCOMM, "Pump units: " + if (danaRPump.units == DanaRPump.UNITS_MGDL) "MGDL" else "MMOL") + aapsLogger.debug(LTag.PUMPCOMM, "Current pump morning CIR: " + danaRPump.morningCIR) + aapsLogger.debug(LTag.PUMPCOMM, "Current pump morning CF: " + danaRPump.morningCF) + aapsLogger.debug(LTag.PUMPCOMM, "Current pump afternoon CIR: " + danaRPump.afternoonCIR) + aapsLogger.debug(LTag.PUMPCOMM, "Current pump afternoon CF: " + danaRPump.afternoonCF) + aapsLogger.debug(LTag.PUMPCOMM, "Current pump evening CIR: " + danaRPump.eveningCIR) + aapsLogger.debug(LTag.PUMPCOMM, "Current pump evening CF: " + danaRPump.eveningCF) + aapsLogger.debug(LTag.PUMPCOMM, "Current pump night CIR: " + danaRPump.nightCIR) + aapsLogger.debug(LTag.PUMPCOMM, "Current pump night CF: " + danaRPump.nightCF) + aapsLogger.debug(LTag.PUMPCOMM, "cir02: $cir02") + aapsLogger.debug(LTag.PUMPCOMM, "cir04: $cir04") + aapsLogger.debug(LTag.PUMPCOMM, "cir06: $cir06") + aapsLogger.debug(LTag.PUMPCOMM, "cf02: $cf02") + aapsLogger.debug(LTag.PUMPCOMM, "cf04: $cf04") + aapsLogger.debug(LTag.PUMPCOMM, "cf06: $cf06") } override fun getFriendlyName(): String { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSTestBase.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSTestBase.kt index b9d3457b35..22768c52cc 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSTestBase.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSTestBase.kt @@ -21,6 +21,14 @@ open class DanaRSTestBase : TestBase() { return ret } + fun createArray(length: Int, fillWith: Double): Array { + val ret = Array(length) {0.0} + for (i in 0 until length) { + ret[i] = fillWith + } + return ret + } + @Before fun setup() { danaRPump = DanaRPump(aapsLogger, sp) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.java deleted file mode 100644 index 443c467b53..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.java +++ /dev/null @@ -1,61 +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 01.08.2018 - */ - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, SP.class, L.class}) -public class DanaRS_Packet_Basal_Set_Basal_RateTest { - - @Test - public void runTest() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockSP(); - AAPSMocker.mockL(); - - // test message decoding - DanaRS_Packet_Basal_Set_Basal_Rate packet = new DanaRS_Packet_Basal_Set_Basal_Rate(createArray(24, 5)); - byte[] requested = packet.getRequestParams(); - byte lookingFor = (byte) ((5 * 100) & 0xff); - assertEquals(lookingFor, requested[24]); - lookingFor = (byte) ((500 >>> 8) & 0xff); - assertEquals(lookingFor, requested[25]); - packet.handleMessage(createArray(3, (byte) 0)); - assertEquals(false, packet.failed); - packet.handleMessage(createArray(3, (byte) 1)); - assertEquals(true, packet.failed); - - assertEquals("BASAL__SET_BASAL_RATE", packet.getFriendlyName()); - } - - double[] createArray(int length, double fillWith) { - double[] ret = new double[length]; - for (int i = 0; i < length; i++) { - ret[i] = fillWith; - } - return ret; - } - - byte[] createArray(int length, byte fillWith) { - byte[] ret = new byte[length]; - for (int i = 0; i < length; i++) { - ret[i] = fillWith; - } - return ret; - } -} diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.kt new file mode 100644 index 0000000000..d4e2b2de06 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.kt @@ -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_Basal_Set_Basal_RateTest : DanaRSTestBase() { + + @Test fun runTest() { + // test message decoding + val packet = DanaRS_Packet_Basal_Set_Basal_Rate(aapsLogger, createArray(24, 5.0)) + val requested = packet.requestParams + var lookingFor = (5 * 100 and 0xff).toByte() + Assert.assertEquals(lookingFor, requested[24]) + lookingFor = (500 ushr 8 and 0xff).toByte() + Assert.assertEquals(lookingFor, requested[25]) + packet.handleMessage(createArray(3, 0.toByte())) + Assert.assertEquals(false, packet.failed) + packet.handleMessage(createArray(3, 1.toByte())) + Assert.assertEquals(true, packet.failed) + Assert.assertEquals("BASAL__SET_BASAL_RATE", packet.friendlyName) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.java deleted file mode 100644 index 9595376aae..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.java +++ /dev/null @@ -1,49 +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 01.08.2018. - */ - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, SP.class, L.class}) -public class DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest { - - @Test - public void runTest() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockSP(); - AAPSMocker.mockL(); - - DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal packet = new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(); - - // test message decoding - packet.handleMessage(createArray(3,(byte) 0)); - assertEquals(false, packet.failed); - packet.handleMessage(createArray(3,(byte) 1)); - assertEquals(true, packet.failed); - - assertEquals("BASAL__CANCEL_TEMPORARY_BASAL", 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; - } -} diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.kt new file mode 100644 index 0000000000..4c127cf437 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.kt @@ -0,0 +1,22 @@ +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_Basal_Set_Cancel_Temporary_BasalTest : DanaRSTestBase() { + + @Test fun runTest() { + val packet = DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger) + // test message decoding + packet.handleMessage(createArray(3, 0.toByte())) + Assert.assertEquals(false, packet.failed) + packet.handleMessage(createArray(3, 1.toByte())) + Assert.assertEquals(true, packet.failed) + Assert.assertEquals("BASAL__CANCEL_TEMPORARY_BASAL", packet.friendlyName) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_RateTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_RateTest.java deleted file mode 100644 index 019661cc3c..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_RateTest.java +++ /dev/null @@ -1,64 +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_Basal_Set_Profile_Basal_RateTest { - - @Test - public void runTest() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockSP(); - AAPSMocker.mockL(); - DanaRS_Packet_Basal_Set_Profile_Basal_Rate packet = new DanaRS_Packet_Basal_Set_Profile_Basal_Rate(1, createArray(24,1)); - - // test params - byte[] testparams =packet.getRequestParams(); - // is profile 1 - assertEquals((byte) 1, testparams[0]); - // is value 100 - assertEquals((byte) 100, testparams[3]); - - - // test message decoding - packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0}); - assertEquals(false, packet.failed); - packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 1}); - assertEquals(true, packet.failed); - - assertEquals("BASAL__SET_PROFILE_BASAL_RATE", packet.getFriendlyName()); - } - - byte[] createArray(int length, byte fillWith){ - byte[] ret = new byte[length]; - for(int i = 0; i