ProfileTest
This commit is contained in:
parent
2c3313ca54
commit
89d1de9710
7 changed files with 161 additions and 158 deletions
|
@ -35,6 +35,7 @@ public class Profile {
|
||||||
@Inject public ActivePluginProvider activePlugin;
|
@Inject public ActivePluginProvider activePlugin;
|
||||||
@Inject public ResourceHelper resourceHelper;
|
@Inject public ResourceHelper resourceHelper;
|
||||||
@Inject public RxBusWrapper rxBus;
|
@Inject public RxBusWrapper rxBus;
|
||||||
|
@Inject public FabricPrivacy fabricPrivacy;
|
||||||
|
|
||||||
private HasAndroidInjector injector;
|
private HasAndroidInjector injector;
|
||||||
|
|
||||||
|
@ -85,7 +86,7 @@ public class Profile {
|
||||||
if (units != null)
|
if (units != null)
|
||||||
this.units = units;
|
this.units = units;
|
||||||
else {
|
else {
|
||||||
FabricPrivacy.getInstance().log("Profile failover failed too");
|
fabricPrivacy.log("Profile failover failed too");
|
||||||
this.units = Constants.MGDL;
|
this.units = Constants.MGDL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,7 +200,7 @@ public class Profile {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
aapsLogger.error("Unhandled exception", e);
|
aapsLogger.error("Unhandled exception", e);
|
||||||
aapsLogger.error(json.toString());
|
aapsLogger.error(json.toString());
|
||||||
FabricPrivacy.getInstance().logException(e);
|
fabricPrivacy.logException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ class FabricPrivacy @Inject constructor(
|
||||||
private lateinit var instance: FabricPrivacy
|
private lateinit var instance: FabricPrivacy
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@Deprecated("use dagger")
|
||||||
fun getInstance(): FabricPrivacy = instance
|
fun getInstance(): FabricPrivacy = instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,16 +9,20 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
|
||||||
|
@PrepareForTest(FabricPrivacy::class)
|
||||||
open class TestBaseWithProfile : TestBase() {
|
open class TestBaseWithProfile : TestBase() {
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
@Mock lateinit var aapsLogger: AAPSLogger
|
||||||
@Mock lateinit var activePluginProvider: ActivePluginProvider
|
@Mock lateinit var activePluginProvider: ActivePluginProvider
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var treatmentsPlugin :TreatmentsPlugin
|
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||||
|
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||||
|
|
||||||
val rxBus = RxBusWrapper()
|
val rxBus = RxBusWrapper()
|
||||||
|
|
||||||
|
@ -29,6 +33,7 @@ open class TestBaseWithProfile : TestBase() {
|
||||||
it.activePlugin = activePluginProvider
|
it.activePlugin = activePluginProvider
|
||||||
it.resourceHelper = resourceHelper
|
it.resourceHelper = resourceHelper
|
||||||
it.rxBus = rxBus
|
it.rxBus = rxBus
|
||||||
|
it.fabricPrivacy = fabricPrivacy
|
||||||
}
|
}
|
||||||
if (it is ProfileSwitch) {
|
if (it is ProfileSwitch) {
|
||||||
it.treatmentsPlugin = treatmentsPlugin
|
it.treatmentsPlugin = treatmentsPlugin
|
||||||
|
@ -39,7 +44,7 @@ open class TestBaseWithProfile : TestBase() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lateinit var validProfileJSON : String
|
lateinit var validProfileJSON: String
|
||||||
lateinit var validProfile: Profile
|
lateinit var validProfile: Profile
|
||||||
val TESTPROFILENAME = "someProfile"
|
val TESTPROFILENAME = "someProfile"
|
||||||
|
|
||||||
|
|
|
@ -1,152 +0,0 @@
|
||||||
package info.nightscout.androidaps.data;
|
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
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 java.util.Calendar;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import info.AAPSMocker;
|
|
||||||
import info.nightscout.androidaps.Constants;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
|
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 18.03.2018.
|
|
||||||
*/
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, VirtualPumpPlugin.class, FabricPrivacy.class})
|
|
||||||
public class ProfileTest {
|
|
||||||
|
|
||||||
PumpInterface pump = new VirtualPumpPlugin();
|
|
||||||
String validProfile = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"},{\"time\":\"2:00\",\"value\":\"110\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}";
|
|
||||||
String belowLimitValidProfile = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.001\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}";
|
|
||||||
String notAllignedBasalValidProfile = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:30\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}";
|
|
||||||
String notStartingAtZeroValidProfile = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:30\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}";
|
|
||||||
String noUnitsValidProfile = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\"}";
|
|
||||||
String wrongProfile = "{\"dia\":\"3\",\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}";
|
|
||||||
|
|
||||||
//String profileStore = "{\"defaultProfile\":\"Default\",\"store\":{\"Default\":" + validProfile + "}}";
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void doTests() throws Exception {
|
|
||||||
Profile p = new Profile();
|
|
||||||
|
|
||||||
// Test valid profile
|
|
||||||
p = new Profile(new JSONObject(validProfile), 100, 0);
|
|
||||||
Assert.assertEquals(true, p.isValid("Test"));
|
|
||||||
Assert.assertEquals(true, p.log().contains("NS units: mmol"));
|
|
||||||
JSONAssert.assertEquals(validProfile, p.getData(), false);
|
|
||||||
Assert.assertEquals(3.0d, p.getDia(), 0.01d);
|
|
||||||
Assert.assertEquals(TimeZone.getTimeZone("UTC"), p.getTimeZone());
|
|
||||||
Assert.assertEquals("00:30", p.format_HH_MM(30 * 60));
|
|
||||||
Calendar c = Calendar.getInstance();
|
|
||||||
c.set(Calendar.HOUR_OF_DAY, 1);
|
|
||||||
c.set(Calendar.MINUTE, 0);
|
|
||||||
c.set(Calendar.SECOND, 0);
|
|
||||||
c.set(Calendar.MILLISECOND, 0);
|
|
||||||
Assert.assertEquals(1800d, p.getIsfMgdl(c.getTimeInMillis()), 0.01d);
|
|
||||||
c.set(Calendar.HOUR_OF_DAY, 2);
|
|
||||||
Assert.assertEquals(1980d, p.getIsfMgdl(c.getTimeInMillis()), 0.01d);
|
|
||||||
Assert.assertEquals(110d, p.getIsfTimeFromMidnight(2 * 60 * 60), 0.01d);
|
|
||||||
Assert.assertEquals("00:00 100,0 mmol/U\n" + "02:00 110,0 mmol/U", p.getIsfList().replace(".", ","));
|
|
||||||
Assert.assertEquals(30d, p.getIc(c.getTimeInMillis()), 0.01d);
|
|
||||||
Assert.assertEquals(30d, p.getIcTimeFromMidnight(2 * 60 * 60), 0.01d);
|
|
||||||
Assert.assertEquals("00:00 30,0 g/U", p.getIcList().replace(".", ","));
|
|
||||||
Assert.assertEquals(0.1d, p.getBasal(c.getTimeInMillis()), 0.01d);
|
|
||||||
Assert.assertEquals(0.1d, p.getBasalTimeFromMidnight(2 * 60 * 60), 0.01d);
|
|
||||||
Assert.assertEquals("00:00 0,10 U/h", p.getBasalList().replace(".", ","));
|
|
||||||
Assert.assertEquals(0.1d, p.getBasalValues()[0].value);
|
|
||||||
Assert.assertEquals(0.1d, p.getMaxDailyBasal());
|
|
||||||
Assert.assertEquals(2.4d, p.percentageBasalSum(), 0.01d);
|
|
||||||
Assert.assertEquals(2.4d, p.baseBasalSum(), 0.01d);
|
|
||||||
Assert.assertEquals(81d, p.getTargetMgdl(2 * 60 * 60), 0.01d);
|
|
||||||
Assert.assertEquals(72d, p.getTargetLowMgdl(c.getTimeInMillis()), 0.01d);
|
|
||||||
Assert.assertEquals(4d, p.getTargetLowTimeFromMidnight(2 * 60 * 60), 0.01d);
|
|
||||||
Assert.assertEquals(90d, p.getTargetHighMgdl(c.getTimeInMillis()), 0.01d);
|
|
||||||
Assert.assertEquals(5d, p.getTargetHighTimeFromMidnight(2 * 60 * 60), 0.01d);
|
|
||||||
Assert.assertEquals("00:00 4,0 - 5,0 mmol", p.getTargetList().replace(".", ","));
|
|
||||||
Assert.assertEquals(100, p.getPercentage());
|
|
||||||
Assert.assertEquals(0, p.getTimeshift());
|
|
||||||
|
|
||||||
Assert.assertEquals(0.1d, p.toMgdl(0.1d, Constants.MGDL));
|
|
||||||
Assert.assertEquals(18d, p.toMgdl(1d, Constants.MMOL));
|
|
||||||
Assert.assertEquals(1d, p.toMmol(18d, Constants.MGDL));
|
|
||||||
Assert.assertEquals(18d, p.toMmol(18d, Constants.MMOL));
|
|
||||||
Assert.assertEquals(18d, p.fromMgdlToUnits(18d, Constants.MGDL));
|
|
||||||
Assert.assertEquals(1d, p.fromMgdlToUnits(18d, Constants.MMOL));
|
|
||||||
Assert.assertEquals(18d, p.toUnits(18d, 1d, Constants.MGDL));
|
|
||||||
Assert.assertEquals(1d, p.toUnits(18d, 1d, Constants.MMOL));
|
|
||||||
Assert.assertEquals("18", p.toUnitsString(18d, 1d, Constants.MGDL));
|
|
||||||
Assert.assertEquals("1,0", p.toUnitsString(18d, 1d, Constants.MMOL).replace(".", ","));
|
|
||||||
Assert.assertEquals("5 - 6", p.toTargetRangeString(5d, 6d, Constants.MGDL, Constants.MGDL));
|
|
||||||
Assert.assertEquals("4", p.toTargetRangeString(4d, 4d, Constants.MGDL, Constants.MGDL));
|
|
||||||
|
|
||||||
//Test basal profile below limit
|
|
||||||
p = new Profile(new JSONObject(belowLimitValidProfile), 100, 0);
|
|
||||||
p.isValid("Test");
|
|
||||||
//Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent);
|
|
||||||
|
|
||||||
// Test profile w/o units
|
|
||||||
p = new Profile(new JSONObject(noUnitsValidProfile), 100, 0);
|
|
||||||
Assert.assertEquals(null, p.getUnits());
|
|
||||||
p = new Profile(new JSONObject(noUnitsValidProfile), Constants.MMOL);
|
|
||||||
Assert.assertEquals(Constants.MMOL, p.getUnits());
|
|
||||||
// failover to MGDL
|
|
||||||
p = new Profile(new JSONObject(noUnitsValidProfile), null);
|
|
||||||
Assert.assertEquals(Constants.MGDL, p.getUnits());
|
|
||||||
|
|
||||||
//Test profile not starting at midnight
|
|
||||||
p = new Profile(new JSONObject(notStartingAtZeroValidProfile), 100, 0);
|
|
||||||
Assert.assertEquals(30.0d, p.getIc(0), 0.01d);
|
|
||||||
|
|
||||||
// Test wrong profile
|
|
||||||
p = new Profile(new JSONObject(wrongProfile), 100, 0);
|
|
||||||
Assert.assertEquals(false, p.isValid("Test"));
|
|
||||||
|
|
||||||
// Test percentage functionality
|
|
||||||
p = new Profile(new JSONObject(validProfile), 50, 0);
|
|
||||||
Assert.assertEquals(0.05d, p.getBasal(c.getTimeInMillis()), 0.01d);
|
|
||||||
Assert.assertEquals(1.2d, p.percentageBasalSum(), 0.01d);
|
|
||||||
Assert.assertEquals(60d, p.getIc(c.getTimeInMillis()), 0.01d);
|
|
||||||
Assert.assertEquals(3960d, p.getIsfMgdl(c.getTimeInMillis()), 0.01d);
|
|
||||||
|
|
||||||
// Test timeshift functionality
|
|
||||||
p = new Profile(new JSONObject(validProfile), 100, 1);
|
|
||||||
Assert.assertEquals(
|
|
||||||
"00:00 110.0 mmol/U\n" +
|
|
||||||
"01:00 100.0 mmol/U\n" +
|
|
||||||
"03:00 110.0 mmol/U", p.getIsfList());
|
|
||||||
|
|
||||||
// Test hour alignment
|
|
||||||
ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().is30minBasalRatesCapable = false;
|
|
||||||
//((AAPSMocker.MockedBus) MainApp.bus()).notificationSent = false;
|
|
||||||
p = new Profile(new JSONObject(notAllignedBasalValidProfile), 100, 0);
|
|
||||||
p.isValid("Test");
|
|
||||||
//Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void prepareMock() {
|
|
||||||
AAPSMocker.mockMainApp();
|
|
||||||
AAPSMocker.mockConfigBuilder();
|
|
||||||
AAPSMocker.mockStrings();
|
|
||||||
|
|
||||||
when(ConfigBuilderPlugin.getPlugin().getActivePump()).thenReturn(pump);
|
|
||||||
|
|
||||||
PowerMockito.mockStatic(FabricPrivacy.class);
|
|
||||||
}
|
|
||||||
}
|
|
150
app/src/test/java/info/nightscout/androidaps/data/ProfileTest.kt
Normal file
150
app/src/test/java/info/nightscout/androidaps/data/ProfileTest.kt
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
package info.nightscout.androidaps.data
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.Constants
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.TestBaseWithProfile
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpDescription
|
||||||
|
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
|
||||||
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 18.03.2018.
|
||||||
|
*/
|
||||||
|
@RunWith(PowerMockRunner::class)
|
||||||
|
@PrepareForTest(VirtualPumpPlugin::class, FabricPrivacy::class)
|
||||||
|
class ProfileTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
|
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
|
||||||
|
|
||||||
|
var okProfile = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"},{\"time\":\"2:00\",\"value\":\"110\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
||||||
|
var belowLimitValidProfile = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.001\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
||||||
|
var notAllignedBasalValidProfile = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:30\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
||||||
|
var notStartingAtZeroValidProfile = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:30\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
||||||
|
var noUnitsValidProfile = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\"}"
|
||||||
|
var wrongProfile = "{\"dia\":\"3\",\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
||||||
|
|
||||||
|
//String profileStore = "{\"defaultProfile\":\"Default\",\"store\":{\"Default\":" + validProfile + "}}";
|
||||||
|
|
||||||
|
val pumpDescription = PumpDescription()
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun prepare() {
|
||||||
|
`when`(activePluginProvider.getActivePump()).thenReturn(virtualPumpPlugin)
|
||||||
|
`when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription)
|
||||||
|
`when`(resourceHelper.gs(R.string.profile_per_unit)).thenReturn("/U")
|
||||||
|
`when`(resourceHelper.gs(R.string.profile_carbs_per_unit)).thenReturn("g/U")
|
||||||
|
`when`(resourceHelper.gs(R.string.profile_ins_units_per_hour)).thenReturn("U/h")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun doTests() {
|
||||||
|
|
||||||
|
// Test valid profile
|
||||||
|
var p: Profile = Profile(profileInjector, JSONObject(okProfile), 100, 0)
|
||||||
|
Assert.assertEquals(true, p.isValid("Test"))
|
||||||
|
Assert.assertEquals(true, p.log().contains("NS units: mmol"))
|
||||||
|
JSONAssert.assertEquals(okProfile, p.data, false)
|
||||||
|
Assert.assertEquals(3.0, p.dia, 0.01)
|
||||||
|
Assert.assertEquals(TimeZone.getTimeZone("UTC"), p.timeZone)
|
||||||
|
Assert.assertEquals("00:30", p.format_HH_MM(30 * 60))
|
||||||
|
val c = Calendar.getInstance()
|
||||||
|
c[Calendar.HOUR_OF_DAY] = 1
|
||||||
|
c[Calendar.MINUTE] = 0
|
||||||
|
c[Calendar.SECOND] = 0
|
||||||
|
c[Calendar.MILLISECOND] = 0
|
||||||
|
Assert.assertEquals(1800.0, p.getIsfMgdl(c.timeInMillis), 0.01)
|
||||||
|
c[Calendar.HOUR_OF_DAY] = 2
|
||||||
|
Assert.assertEquals(1980.0, p.getIsfMgdl(c.timeInMillis), 0.01)
|
||||||
|
Assert.assertEquals(110.0, p.getIsfTimeFromMidnight(2 * 60 * 60), 0.01)
|
||||||
|
Assert.assertEquals("""
|
||||||
|
00:00 100,0 mmol/U
|
||||||
|
02:00 110,0 mmol/U
|
||||||
|
""".trimIndent(), p.isfList.replace(".", ","))
|
||||||
|
Assert.assertEquals(30.0, p.getIc(c.timeInMillis), 0.01)
|
||||||
|
Assert.assertEquals(30.0, p.getIcTimeFromMidnight(2 * 60 * 60), 0.01)
|
||||||
|
Assert.assertEquals("00:00 30,0 g/U", p.icList.replace(".", ","))
|
||||||
|
Assert.assertEquals(0.1, p.getBasal(c.timeInMillis), 0.01)
|
||||||
|
Assert.assertEquals(0.1, p.getBasalTimeFromMidnight(2 * 60 * 60), 0.01)
|
||||||
|
Assert.assertEquals("00:00 0,10 U/h", p.basalList.replace(".", ","))
|
||||||
|
Assert.assertEquals(0.1, p.basalValues[0].value, 0.01)
|
||||||
|
Assert.assertEquals(0.1, p.maxDailyBasal, 0.01)
|
||||||
|
Assert.assertEquals(2.4, p.percentageBasalSum(), 0.01)
|
||||||
|
Assert.assertEquals(2.4, p.baseBasalSum(), 0.01)
|
||||||
|
Assert.assertEquals(81.0, p.getTargetMgdl(2 * 60 * 60), 0.01)
|
||||||
|
Assert.assertEquals(72.0, p.getTargetLowMgdl(c.timeInMillis), 0.01)
|
||||||
|
Assert.assertEquals(4.0, p.getTargetLowTimeFromMidnight(2 * 60 * 60), 0.01)
|
||||||
|
Assert.assertEquals(90.0, p.getTargetHighMgdl(c.timeInMillis), 0.01)
|
||||||
|
Assert.assertEquals(5.0, p.getTargetHighTimeFromMidnight(2 * 60 * 60), 0.01)
|
||||||
|
Assert.assertEquals("00:00 4,0 - 5,0 mmol", p.targetList.replace(".", ","))
|
||||||
|
Assert.assertEquals(100, p.percentage)
|
||||||
|
Assert.assertEquals(0, p.timeshift)
|
||||||
|
Assert.assertEquals(0.1, Profile.toMgdl(0.1, Constants.MGDL), 0.01)
|
||||||
|
Assert.assertEquals(18.0, Profile.toMgdl(1.0, Constants.MMOL), 0.01)
|
||||||
|
Assert.assertEquals(1.0, Profile.toMmol(18.0, Constants.MGDL), 0.01)
|
||||||
|
Assert.assertEquals(18.0, Profile.toMmol(18.0, Constants.MMOL), 0.01)
|
||||||
|
Assert.assertEquals(18.0, Profile.fromMgdlToUnits(18.0, Constants.MGDL), 0.01)
|
||||||
|
Assert.assertEquals(1.0, Profile.fromMgdlToUnits(18.0, Constants.MMOL), 0.01)
|
||||||
|
Assert.assertEquals(18.0, Profile.toUnits(18.0, 1.0, Constants.MGDL), 0.01)
|
||||||
|
Assert.assertEquals(1.0, Profile.toUnits(18.0, 1.0, Constants.MMOL), 0.01)
|
||||||
|
Assert.assertEquals("18", Profile.toUnitsString(18.0, 1.0, Constants.MGDL))
|
||||||
|
Assert.assertEquals("1,0", Profile.toUnitsString(18.0, 1.0, Constants.MMOL).replace(".", ","))
|
||||||
|
Assert.assertEquals("5 - 6", Profile.toTargetRangeString(5.0, 6.0, Constants.MGDL, Constants.MGDL))
|
||||||
|
Assert.assertEquals("4", Profile.toTargetRangeString(4.0, 4.0, Constants.MGDL, Constants.MGDL))
|
||||||
|
|
||||||
|
//Test basal profile below limit
|
||||||
|
p = Profile(profileInjector, JSONObject(belowLimitValidProfile), 100, 0)
|
||||||
|
p.isValid("Test")
|
||||||
|
//Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent);
|
||||||
|
|
||||||
|
// Test profile w/o units
|
||||||
|
p = Profile(profileInjector, JSONObject(noUnitsValidProfile), 100, 0)
|
||||||
|
Assert.assertEquals(null, p.units)
|
||||||
|
p = Profile(profileInjector, JSONObject(noUnitsValidProfile), Constants.MMOL)
|
||||||
|
Assert.assertEquals(Constants.MMOL, p.units)
|
||||||
|
// failover to MGDL
|
||||||
|
p = Profile(profileInjector, JSONObject(noUnitsValidProfile), null)
|
||||||
|
Assert.assertEquals(Constants.MGDL, p.units)
|
||||||
|
|
||||||
|
//Test profile not starting at midnight
|
||||||
|
p = Profile(profileInjector, JSONObject(notStartingAtZeroValidProfile), 100, 0)
|
||||||
|
Assert.assertEquals(30.0, p.getIc(0), 0.01)
|
||||||
|
|
||||||
|
// Test wrong profile
|
||||||
|
p = Profile(profileInjector, JSONObject(wrongProfile), 100, 0)
|
||||||
|
Assert.assertEquals(false, p.isValid("Test"))
|
||||||
|
|
||||||
|
// Test percentage functionality
|
||||||
|
p = Profile(profileInjector, JSONObject(okProfile), 50, 0)
|
||||||
|
Assert.assertEquals(0.05, p.getBasal(c.timeInMillis), 0.01)
|
||||||
|
Assert.assertEquals(1.2, p.percentageBasalSum(), 0.01)
|
||||||
|
Assert.assertEquals(60.0, p.getIc(c.timeInMillis), 0.01)
|
||||||
|
Assert.assertEquals(3960.0, p.getIsfMgdl(c.timeInMillis), 0.01)
|
||||||
|
|
||||||
|
// Test timeshift functionality
|
||||||
|
p = Profile(profileInjector, JSONObject(okProfile), 100, 1)
|
||||||
|
Assert.assertEquals(
|
||||||
|
"""
|
||||||
|
00:00 110.0 mmol/U
|
||||||
|
01:00 100.0 mmol/U
|
||||||
|
03:00 110.0 mmol/U
|
||||||
|
""".trimIndent(), p.isfList)
|
||||||
|
|
||||||
|
// Test hour alignment
|
||||||
|
pumpDescription.is30minBasalRatesCapable = false
|
||||||
|
//((AAPSMocker.MockedBus) MainApp.bus()).notificationSent = false;
|
||||||
|
p = Profile(profileInjector, JSONObject(notAllignedBasalValidProfile), 100, 0)
|
||||||
|
p.isValid("Test")
|
||||||
|
//Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent);
|
||||||
|
}
|
||||||
|
}
|
|
@ -55,7 +55,6 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
@Mock lateinit var constraintChecker: ConstraintChecker
|
@Mock lateinit var constraintChecker: ConstraintChecker
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
|
||||||
@Mock lateinit var activePlugin: ActivePluginProvider
|
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||||
@Mock lateinit var commandQueue: CommandQueueProvider
|
@Mock lateinit var commandQueue: CommandQueueProvider
|
||||||
@Mock lateinit var loopPlugin: LoopPlugin
|
@Mock lateinit var loopPlugin: LoopPlugin
|
||||||
|
|
|
@ -42,7 +42,6 @@ class CommandQueueTest : TestBaseWithProfile() {
|
||||||
@Mock lateinit var context: Context
|
@Mock lateinit var context: Context
|
||||||
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
|
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
|
||||||
|
|
||||||
private val buildHelper = BuildHelper()
|
private val buildHelper = BuildHelper()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue