More tests
This commit is contained in:
parent
a895c8f53a
commit
e8af7b5ffc
|
@ -1,12 +1,12 @@
|
|||
package info.nightscout.androidaps.plugins.general.maintenance
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.core.content.FileProvider
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.BuildConfig
|
||||
import info.nightscout.androidaps.Config
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.interfaces.PluginBase
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||
|
@ -26,7 +26,7 @@ import javax.inject.Singleton
|
|||
@Singleton
|
||||
class MaintenancePlugin @Inject constructor(
|
||||
injector: HasAndroidInjector,
|
||||
private val mainApp: MainApp,
|
||||
private val context: Context,
|
||||
resourceHelper: ResourceHelper,
|
||||
private val sp: SP,
|
||||
private val nsSettingsStatus: NSSettingsStatus,
|
||||
|
@ -49,14 +49,14 @@ class MaintenancePlugin @Inject constructor(
|
|||
val amount = sp.getInt(R.string.key_maintenance_logs_amount, 2)
|
||||
val logDirectory = LoggerUtils.getLogDirectory()
|
||||
val logs = getLogFiles(logDirectory, amount)
|
||||
val zipDir = mainApp.getExternalFilesDir("exports")
|
||||
val zipDir = context.getExternalFilesDir("exports")
|
||||
val zipFile = File(zipDir, constructName())
|
||||
aapsLogger.debug("zipFile: ${zipFile.absolutePath}")
|
||||
val zip = zipLogs(zipFile, logs)
|
||||
val attachmentUri = FileProvider.getUriForFile(mainApp, BuildConfig.APPLICATION_ID + ".fileprovider", zip)
|
||||
val attachmentUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", zip)
|
||||
val emailIntent: Intent = this.sendMail(attachmentUri, recipient, "Log Export")
|
||||
aapsLogger.debug("sending emailIntent")
|
||||
mainApp.startActivity(emailIntent)
|
||||
context.startActivity(emailIntent)
|
||||
}
|
||||
|
||||
//todo replace this with a call on startup of the application, specifically to remove
|
||||
|
@ -108,7 +108,7 @@ class MaintenancePlugin @Inject constructor(
|
|||
}
|
||||
Arrays.sort(files) { f1: File, f2: File -> f2.name.compareTo(f1.name) }
|
||||
val result = listOf(*files)
|
||||
var toIndex = amount + 1
|
||||
var toIndex = amount
|
||||
if (toIndex > result.size) {
|
||||
toIndex = result.size
|
||||
}
|
||||
|
|
|
@ -342,7 +342,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
long timeDiffToNew = newer.date - currentTime;
|
||||
|
||||
double currentBg = newer.value - (double) timeDiffToNew / (newer.date - older.date) * bgDelta;
|
||||
BgReading newBgreading = new BgReading();
|
||||
BgReading newBgreading = new BgReading(injector);
|
||||
newBgreading.date = currentTime;
|
||||
newBgreading.value = Math.round(currentBg);
|
||||
bucketed_data.add(newBgreading);
|
||||
|
@ -382,7 +382,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
while (elapsed_minutes > 5) {
|
||||
nextbgTime = lastbgTime - 5 * 60 * 1000;
|
||||
j++;
|
||||
BgReading newBgreading = new BgReading();
|
||||
BgReading newBgreading = new BgReading(injector);
|
||||
newBgreading.date = nextbgTime;
|
||||
double gapDelta = bgReadings.get(i).value - lastbg;
|
||||
//console.error(gapDelta, lastbg, elapsed_minutes);
|
||||
|
@ -397,14 +397,14 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
lastbgTime = nextbgTime;
|
||||
}
|
||||
j++;
|
||||
BgReading newBgreading = new BgReading();
|
||||
BgReading newBgreading = new BgReading(injector);
|
||||
newBgreading.value = bgReadings.get(i).value;
|
||||
newBgreading.date = bgTime;
|
||||
bucketed_data.add(newBgreading);
|
||||
getAapsLogger().debug(LTag.AUTOSENS, "Adding. bgTime: " + DateUtil.toISOString(bgTime) + " lastbgTime: " + DateUtil.toISOString(lastbgTime) + " " + newBgreading.toString());
|
||||
} else if (Math.abs(elapsed_minutes) > 2) {
|
||||
j++;
|
||||
BgReading newBgreading = new BgReading();
|
||||
BgReading newBgreading = new BgReading(injector);
|
||||
newBgreading.value = bgReadings.get(i).value;
|
||||
newBgreading.date = bgTime;
|
||||
bucketed_data.add(newBgreading);
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
package info.nightscout.androidaps.data;
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
/**
|
||||
* Created by mike on 26.03.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public class DetailedBolusInfoTest {
|
||||
|
||||
@Test
|
||||
public void toStringShouldBeOverloaded() {
|
||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||
Assert.assertEquals(true, detailedBolusInfo.toString().contains("insulin"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyShouldCopyAllProperties() {
|
||||
DetailedBolusInfo d1 = new DetailedBolusInfo();
|
||||
d1.deliverAt = 123;
|
||||
DetailedBolusInfo d2 = d1.copy();
|
||||
Assert.assertEquals(true, EqualsBuilder.reflectionEquals(d2, d1));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package info.nightscout.androidaps.data
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
class DetailedBolusInfoTest {
|
||||
|
||||
@Test fun toStringShouldBeOverloaded() {
|
||||
val detailedBolusInfo = DetailedBolusInfo()
|
||||
Assert.assertEquals(true, detailedBolusInfo.toString().contains("insulin"))
|
||||
}
|
||||
|
||||
@Test fun copyShouldCopyAllProperties() {
|
||||
val d1 = DetailedBolusInfo()
|
||||
d1.deliverAt = 123
|
||||
val d2 = d1.copy()
|
||||
Assert.assertEquals(true, EqualsBuilder.reflectionEquals(d2, d1))
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package info.nightscout.androidaps.data;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
/**
|
||||
* Created by mike on 26.03.2018.
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public class MealDataTest {
|
||||
@Test
|
||||
public void canCreateObject() {
|
||||
MealData md = new MealData();
|
||||
Assert.assertEquals(0d, md.boluses, 0.01d);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package info.nightscout.androidaps.data
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
class MealDataTest {
|
||||
|
||||
@Test fun canCreateObject() {
|
||||
val md = MealData()
|
||||
Assert.assertEquals(0.0, md.boluses, 0.01)
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.aps.loop;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
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.R;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
* Created by mike on 23.03.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, SP.class, Context.class})
|
||||
public class LoopPluginTest {
|
||||
|
||||
VirtualPumpPlugin virtualPumpPlugin;
|
||||
LoopPlugin loopPlugin;
|
||||
|
||||
@Test
|
||||
public void testPluginInterface() {
|
||||
Assert.assertEquals(LoopFragment.class.getName(), loopPlugin.pluginDescription.getFragmentClass());
|
||||
Assert.assertEquals(PluginType.LOOP, loopPlugin.getType());
|
||||
Assert.assertEquals("Loop", loopPlugin.getName());
|
||||
Assert.assertEquals("LOOP", loopPlugin.getNameShort());
|
||||
Assert.assertEquals(true, loopPlugin.hasFragment());
|
||||
Assert.assertEquals(true, loopPlugin.showInList(PluginType.LOOP));
|
||||
Assert.assertEquals(R.xml.pref_loop, loopPlugin.getPreferencesId());
|
||||
|
||||
// Plugin is disabled by default
|
||||
Assert.assertEquals(false, loopPlugin.isEnabled(PluginType.LOOP));
|
||||
loopPlugin.setPluginEnabled(PluginType.LOOP, true);
|
||||
Assert.assertEquals(true, loopPlugin.isEnabled(PluginType.LOOP));
|
||||
|
||||
// No temp basal capable pump should disable plugin
|
||||
virtualPumpPlugin.getPumpDescription().isTempBasalCapable = false;
|
||||
Assert.assertEquals(false, loopPlugin.isEnabled(PluginType.LOOP));
|
||||
virtualPumpPlugin.getPumpDescription().isTempBasalCapable = true;
|
||||
|
||||
|
||||
// Fragment is hidden by default
|
||||
Assert.assertEquals(false, loopPlugin.isFragmentVisible());
|
||||
loopPlugin.setFragmentVisible(PluginType.LOOP, true);
|
||||
Assert.assertEquals(true, loopPlugin.isFragmentVisible());
|
||||
|
||||
}
|
||||
|
||||
/* *********** not working
|
||||
@Test
|
||||
public void eventTreatmentChangeShouldTriggerInvoke() {
|
||||
|
||||
// Unregister tested plugin to prevent calling real invoke
|
||||
MainApp.bus().unregister(loopPlugin);
|
||||
|
||||
class MockedLoopPlugin extends LoopPlugin {
|
||||
boolean invokeCalled = false;
|
||||
|
||||
@Override
|
||||
public void invoke(String initiator, boolean allowNotification) {
|
||||
invokeCalled = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MockedLoopPlugin mockedLoopPlugin = new MockedLoopPlugin();
|
||||
Treatment t = new Treatment();
|
||||
bus.post(new EventTreatmentChange(t));
|
||||
Assert.assertEquals(true, mockedLoopPlugin.invokeCalled);
|
||||
}
|
||||
*/
|
||||
@Before
|
||||
public void prepareMock() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockConfigBuilder();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockStrings();
|
||||
|
||||
loopPlugin = LoopPlugin.getPlugin();
|
||||
virtualPumpPlugin = VirtualPumpPlugin.getPlugin();
|
||||
|
||||
when(ConfigBuilderPlugin.getPlugin().getActivePump()).thenReturn(virtualPumpPlugin);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
package info.nightscout.androidaps.plugins.aps.loop
|
||||
|
||||
import android.content.Context
|
||||
import dagger.Lazy
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
||||
import info.nightscout.androidaps.interfaces.PluginType
|
||||
import info.nightscout.androidaps.interfaces.PumpDescription
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||
import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
||||
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
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
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest(ConstraintChecker::class, VirtualPumpPlugin::class)
|
||||
class LoopPluginTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var sp: SP
|
||||
private val rxBus: RxBusWrapper = RxBusWrapper()
|
||||
@Mock lateinit var constraintChecker: ConstraintChecker
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var context: Context
|
||||
@Mock lateinit var commandQueue: CommandQueueProvider
|
||||
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
|
||||
@Mock lateinit var actionStringHandler: Lazy<ActionStringHandler>
|
||||
@Mock lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
||||
|
||||
lateinit var loopPlugin: LoopPlugin
|
||||
|
||||
val injector = HasAndroidInjector { AndroidInjector { } }
|
||||
@Before fun prepareMock() {
|
||||
loopPlugin = LoopPlugin(injector, aapsLogger, rxBus, sp, constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, treatmentsPlugin, virtualPumpPlugin, actionStringHandler, iobCobCalculatorPlugin)
|
||||
`when`(activePlugin.getActivePump()).thenReturn(virtualPumpPlugin)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPluginInterface() {
|
||||
`when`(resourceHelper.gs(R.string.loop)).thenReturn("Loop")
|
||||
`when`(resourceHelper.gs(R.string.loop_shortname)).thenReturn("LOOP")
|
||||
val pumpDescription = PumpDescription()
|
||||
`when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription)
|
||||
Assert.assertEquals(LoopFragment::class.java.name, loopPlugin.pluginDescription.fragmentClass)
|
||||
Assert.assertEquals(PluginType.LOOP, loopPlugin.getType())
|
||||
Assert.assertEquals("Loop", loopPlugin.name)
|
||||
Assert.assertEquals("LOOP", loopPlugin.nameShort)
|
||||
Assert.assertEquals(true, loopPlugin.hasFragment())
|
||||
Assert.assertEquals(true, loopPlugin.showInList(PluginType.LOOP))
|
||||
Assert.assertEquals(R.xml.pref_loop.toLong(), loopPlugin.preferencesId.toLong())
|
||||
|
||||
// Plugin is disabled by default
|
||||
Assert.assertEquals(false, loopPlugin.isEnabled(PluginType.LOOP))
|
||||
loopPlugin.setPluginEnabled(PluginType.LOOP, true)
|
||||
Assert.assertEquals(true, loopPlugin.isEnabled(PluginType.LOOP))
|
||||
|
||||
// No temp basal capable pump should disable plugin
|
||||
virtualPumpPlugin.pumpDescription.isTempBasalCapable = false
|
||||
Assert.assertEquals(false, loopPlugin.isEnabled(PluginType.LOOP))
|
||||
virtualPumpPlugin.pumpDescription.isTempBasalCapable = true
|
||||
|
||||
// Fragment is hidden by default
|
||||
Assert.assertEquals(false, loopPlugin.isFragmentVisible())
|
||||
loopPlugin.setFragmentVisible(PluginType.LOOP, true)
|
||||
Assert.assertEquals(true, loopPlugin.isFragmentVisible())
|
||||
}
|
||||
|
||||
/* *********** not working
|
||||
@Test
|
||||
public void eventTreatmentChangeShouldTriggerInvoke() {
|
||||
|
||||
// Unregister tested plugin to prevent calling real invoke
|
||||
MainApp.bus().unregister(loopPlugin);
|
||||
|
||||
class MockedLoopPlugin extends LoopPlugin {
|
||||
boolean invokeCalled = false;
|
||||
|
||||
@Override
|
||||
public void invoke(String initiator, boolean allowNotification) {
|
||||
invokeCalled = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MockedLoopPlugin mockedLoopPlugin = new MockedLoopPlugin();
|
||||
Treatment t = new Treatment();
|
||||
bus.post(new EventTreatmentChange(t));
|
||||
Assert.assertEquals(true, mockedLoopPlugin.invokeCalled);
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.constraints.dstHelper;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, SP.class, Context.class})
|
||||
public class DstHelperPluginTest {
|
||||
DstHelperPlugin plugin = new DstHelperPlugin();
|
||||
|
||||
@Test
|
||||
public void runTest() throws Exception {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
|
||||
TimeZone tz = TimeZone.getTimeZone("Europe/Rome");
|
||||
TimeZone.setDefault(tz);
|
||||
Calendar cal = Calendar.getInstance(tz, Locale.ITALIAN);
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ITALIAN);
|
||||
Date dateBeforeDST = df.parse("2018-03-25 01:55");
|
||||
cal.setTime(dateBeforeDST);
|
||||
Assert.assertEquals(false, plugin.wasDST(cal));
|
||||
Assert.assertEquals(true, plugin.willBeDST(cal));
|
||||
|
||||
|
||||
TimeZone.setDefault(tz);
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN);
|
||||
dateBeforeDST = df.parse("2018-03-25 03:05");
|
||||
cal.setTime(dateBeforeDST);
|
||||
Assert.assertEquals(true, plugin.wasDST(cal));
|
||||
Assert.assertEquals(false, plugin.willBeDST(cal));
|
||||
|
||||
|
||||
TimeZone.setDefault(tz);
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN);
|
||||
dateBeforeDST = df.parse("2018-03-25 02:05"); //Cannot happen!!!
|
||||
cal.setTime(dateBeforeDST);
|
||||
Assert.assertEquals(true, plugin.wasDST(cal));
|
||||
Assert.assertEquals(false, plugin.willBeDST(cal));
|
||||
|
||||
TimeZone.setDefault(tz);
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN);
|
||||
dateBeforeDST = df.parse("2018-03-25 05:55"); //Cannot happen!!!
|
||||
cal.setTime(dateBeforeDST);
|
||||
Assert.assertEquals(true, plugin.wasDST(cal));
|
||||
Assert.assertEquals(false, plugin.willBeDST(cal));
|
||||
|
||||
TimeZone.setDefault(tz);
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN);
|
||||
dateBeforeDST = df.parse("2018-03-25 06:05"); //Cannot happen!!!
|
||||
cal.setTime(dateBeforeDST);
|
||||
Assert.assertEquals(false, plugin.wasDST(cal));
|
||||
Assert.assertEquals(false, plugin.willBeDST(cal));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package info.nightscout.androidaps.plugins.constraints.dstHelper
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
import java.text.DateFormat
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
class DstHelperPluginTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||
@Mock lateinit var loopPlugin: LoopPlugin
|
||||
|
||||
lateinit var plugin: DstHelperPlugin
|
||||
|
||||
val injector = HasAndroidInjector { AndroidInjector { } }
|
||||
|
||||
@Before
|
||||
fun mock() {
|
||||
plugin = DstHelperPlugin(injector, aapsLogger, RxBusWrapper(), resourceHelper, sp, activePlugin, loopPlugin)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
val tz = TimeZone.getTimeZone("Europe/Rome")
|
||||
TimeZone.setDefault(tz)
|
||||
var cal = Calendar.getInstance(tz, Locale.ITALIAN)
|
||||
val df: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ITALIAN)
|
||||
var dateBeforeDST = df.parse("2018-03-25 01:55")
|
||||
cal.time = dateBeforeDST
|
||||
Assert.assertEquals(false, plugin.wasDST(cal))
|
||||
Assert.assertEquals(true, plugin.willBeDST(cal))
|
||||
TimeZone.setDefault(tz)
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN)
|
||||
dateBeforeDST = df.parse("2018-03-25 03:05")
|
||||
cal.time = dateBeforeDST
|
||||
Assert.assertEquals(true, plugin.wasDST(cal))
|
||||
Assert.assertEquals(false, plugin.willBeDST(cal))
|
||||
TimeZone.setDefault(tz)
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN)
|
||||
dateBeforeDST = df.parse("2018-03-25 02:05") //Cannot happen!!!
|
||||
cal.time = dateBeforeDST
|
||||
Assert.assertEquals(true, plugin.wasDST(cal))
|
||||
Assert.assertEquals(false, plugin.willBeDST(cal))
|
||||
TimeZone.setDefault(tz)
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN)
|
||||
dateBeforeDST = df.parse("2018-03-25 05:55") //Cannot happen!!!
|
||||
cal.time = dateBeforeDST
|
||||
Assert.assertEquals(true, plugin.wasDST(cal))
|
||||
Assert.assertEquals(false, plugin.willBeDST(cal))
|
||||
TimeZone.setDefault(tz)
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN)
|
||||
dateBeforeDST = df.parse("2018-03-25 06:05") //Cannot happen!!!
|
||||
cal.time = dateBeforeDST
|
||||
Assert.assertEquals(false, plugin.wasDST(cal))
|
||||
Assert.assertEquals(false, plugin.willBeDST(cal))
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.general.maintenance;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class MaintenancePluginTest {
|
||||
|
||||
private MaintenancePlugin sut = new MaintenancePlugin();
|
||||
|
||||
@Test
|
||||
public void getLogfilesTest() {
|
||||
String logDirectory = "src/test/res/logger";
|
||||
|
||||
List<File> logs = sut.getLogFiles(logDirectory, 2);
|
||||
assertEquals(2, logs.size());
|
||||
assertEquals("AndroidAPS.log", logs.get(0).getName());
|
||||
assertEquals("AndroidAPS.2018-01-03_01-01-00.1.zip", logs.get(1).getName());
|
||||
|
||||
logs = sut.getLogFiles(logDirectory, 10);
|
||||
assertEquals(4, logs.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void zipLogsTest() {
|
||||
String logDirectory = "src/test/res/logger";
|
||||
List<File> logs = sut.getLogFiles(logDirectory, 2);
|
||||
|
||||
String name = "AndroidAPS.log.zip";
|
||||
|
||||
File zipFile = new File("build/" + name);
|
||||
zipFile = sut.zipLogs(zipFile, logs);
|
||||
|
||||
assertTrue(zipFile.exists());
|
||||
assertTrue(zipFile.isFile());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package info.nightscout.androidaps.plugins.general.maintenance
|
||||
|
||||
import android.content.Context
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus
|
||||
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
import java.io.File
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest(NSSettingsStatus::class, BuildHelper::class)
|
||||
class MaintenancePluginTest : TestBase() {
|
||||
|
||||
@Mock lateinit var injector: HasAndroidInjector
|
||||
@Mock lateinit var context: Context
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var nsSettingsStatus: NSSettingsStatus
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var buildHelper: BuildHelper
|
||||
|
||||
lateinit var sut: MaintenancePlugin
|
||||
|
||||
@Before
|
||||
fun mock() {
|
||||
sut = MaintenancePlugin(injector, context, resourceHelper, sp, nsSettingsStatus, aapsLogger, buildHelper)
|
||||
}
|
||||
|
||||
@Test fun logfilesTest() {
|
||||
val logDirectory = "src/test/res/logger"
|
||||
var logs = sut.getLogFiles(logDirectory, 2)
|
||||
Assert.assertEquals(2, logs.size)
|
||||
Assert.assertEquals("AndroidAPS.log", logs[0].name)
|
||||
Assert.assertEquals("AndroidAPS.2018-01-03_01-01-00.1.zip", logs[1].name)
|
||||
logs = sut.getLogFiles(logDirectory, 10)
|
||||
Assert.assertEquals(4, logs.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun zipLogsTest() {
|
||||
val logDirectory = "src/test/res/logger"
|
||||
val logs = sut.getLogFiles(logDirectory, 2)
|
||||
val name = "AndroidAPS.log.zip"
|
||||
var zipFile = File("build/$name")
|
||||
zipFile = sut.zipLogs(zipFile, logs)
|
||||
Assert.assertTrue(zipFile.exists())
|
||||
Assert.assertTrue(zipFile.isFile)
|
||||
}
|
||||
}
|
|
@ -1,218 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.iob.iobCobCalculatorPlugin;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Assert;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSgv;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.T;
|
||||
|
||||
import static org.powermock.api.mockito.PowerMockito.mock;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
* Created by mike on 26.03.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, IobCobCalculatorPlugin.class, DateUtil.class})
|
||||
public class GlucoseStatusTest {
|
||||
IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
||||
|
||||
@Test
|
||||
public void toStringShouldBeOverloaded() {
|
||||
GlucoseStatus glucoseStatus = new GlucoseStatus();
|
||||
Assert.assertEquals(true, glucoseStatus.log().contains("Delta"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roundtest() {
|
||||
GlucoseStatus glucoseStatus = new GlucoseStatus();
|
||||
glucoseStatus.glucose = 100.11111;
|
||||
Assert.assertEquals(100.1, glucoseStatus.round().glucose, 0.0001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateValidGlucoseStatus() {
|
||||
when(iobCobCalculatorPlugin.getBgReadings()).thenReturn(generateValidBgData());
|
||||
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||
Assert.assertEquals(214d, glucoseStatus.glucose, 0.001d);
|
||||
Assert.assertEquals(-2d, glucoseStatus.delta, 0.001d);
|
||||
Assert.assertEquals(-2.5d, glucoseStatus.short_avgdelta, 0.001d); // -2 -2.5 -3 deltas are relative to current value
|
||||
Assert.assertEquals(-2.5d, glucoseStatus.avgdelta, 0.001d); // the same as short_avgdelta
|
||||
Assert.assertEquals(-2d, glucoseStatus.long_avgdelta, 0.001d); // -2 -2 -2 -2
|
||||
Assert.assertEquals(1514766900000L, glucoseStatus.date); // latest date
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateMostRecentGlucoseStatus() {
|
||||
when(iobCobCalculatorPlugin.getBgReadings()).thenReturn(generateMostRecentBgData());
|
||||
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||
Assert.assertEquals(215d, glucoseStatus.glucose, 0.001d); // (214+216) / 2
|
||||
Assert.assertEquals(-1.0d, glucoseStatus.delta, 0.001d);
|
||||
Assert.assertEquals(-1.0d, glucoseStatus.short_avgdelta, 0.001d);
|
||||
Assert.assertEquals(-1.0d, glucoseStatus.avgdelta, 0.001d);
|
||||
Assert.assertEquals(0d, glucoseStatus.long_avgdelta, 0.001d);
|
||||
Assert.assertEquals(1514766900000L, glucoseStatus.date); // latest date, even when averaging
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneRecordShouldProduceZeroDeltas() {
|
||||
when(iobCobCalculatorPlugin.getBgReadings()).thenReturn(generateOneCurrentRecordBgData());
|
||||
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||
|
||||
Assert.assertEquals(214d, glucoseStatus.glucose, 0.001d);
|
||||
Assert.assertEquals(0d, glucoseStatus.delta, 0.001d);
|
||||
Assert.assertEquals(0d, glucoseStatus.short_avgdelta, 0.001d); // -2 -2.5 -3 deltas are relative to current value
|
||||
Assert.assertEquals(0d, glucoseStatus.avgdelta, 0.001d); // the same as short_avgdelta
|
||||
Assert.assertEquals(0d, glucoseStatus.long_avgdelta, 0.001d); // -2 -2 -2 -2
|
||||
Assert.assertEquals(1514766900000L, glucoseStatus.date); // latest date
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insuffientDataShouldReturnNull() {
|
||||
when(iobCobCalculatorPlugin.getBgReadings()).thenReturn(generateInsufficientBgData());
|
||||
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||
Assert.assertEquals(null, glucoseStatus);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oldDataShouldReturnNull() {
|
||||
when(iobCobCalculatorPlugin.getBgReadings()).thenReturn(generateOldBgData());
|
||||
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||
Assert.assertEquals(null, glucoseStatus);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnOldDataIfAllowed() {
|
||||
when(iobCobCalculatorPlugin.getBgReadings()).thenReturn(generateOldBgData());
|
||||
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(true);
|
||||
Assert.assertNotEquals(null, glucoseStatus);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void averageShouldNotFailOnEmptyArray() {
|
||||
Assert.assertEquals(0d, GlucoseStatus.average(new ArrayList<>()), 0.001d);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateGlucoseStatusForLibreTestBgData() {
|
||||
when(iobCobCalculatorPlugin.getBgReadings()).thenReturn(generateLibreTestData());
|
||||
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||
|
||||
Assert.assertEquals(100d, glucoseStatus.glucose, 0.001d); //
|
||||
Assert.assertEquals(-10d, glucoseStatus.delta, 0.001d);
|
||||
Assert.assertEquals(-10d, glucoseStatus.short_avgdelta, 0.001d);
|
||||
Assert.assertEquals(-10d, glucoseStatus.avgdelta, 0.001d);
|
||||
Assert.assertEquals(-10d, glucoseStatus.long_avgdelta, 0.001d);
|
||||
Assert.assertEquals(1514766900000L, glucoseStatus.date); // latest date
|
||||
}
|
||||
|
||||
@Before
|
||||
public void initMocking() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockStrings();
|
||||
iobCobCalculatorPlugin = AAPSMocker.mockIobCobCalculatorPlugin();
|
||||
|
||||
PowerMockito.mockStatic(DateUtil.class);
|
||||
when(DateUtil.now()).thenReturn(1514766900000L + T.mins(1).msecs());
|
||||
}
|
||||
|
||||
// [{"mgdl":214,"mills":1521895773113,"device":"xDrip-DexcomG5","direction":"Flat","filtered":191040,"unfiltered":205024,"noise":1,"rssi":100},{"mgdl":219,"mills":1521896073352,"device":"xDrip-DexcomG5","direction":"Flat","filtered":200160,"unfiltered":209760,"noise":1,"rssi":100},{"mgdl":222,"mills":1521896372890,"device":"xDrip-DexcomG5","direction":"Flat","filtered":207360,"unfiltered":212512,"noise":1,"rssi":100},{"mgdl":220,"mills":1521896673062,"device":"xDrip-DexcomG5","direction":"Flat","filtered":211488,"unfiltered":210688,"noise":1,"rssi":100},{"mgdl":193,"mills":1521896972933,"device":"xDrip-DexcomG5","direction":"Flat","filtered":212384,"unfiltered":208960,"noise":1,"rssi":100},{"mgdl":181,"mills":1521897273336,"device":"xDrip-DexcomG5","direction":"SingleDown","filtered":210592,"unfiltered":204320,"noise":1,"rssi":100},{"mgdl":176,"mills":1521897572875,"device":"xDrip-DexcomG5","direction":"FortyFiveDown","filtered":206720,"unfiltered":197440,"noise":1,"rssi":100},{"mgdl":168,"mills":1521897872929,"device":"xDrip-DexcomG5","direction":"FortyFiveDown","filtered":201024,"unfiltered":187904,"noise":1,"rssi":100},{"mgdl":161,"mills":1521898172814,"device":"xDrip-DexcomG5","direction":"FortyFiveDown","filtered":193376,"unfiltered":178144,"noise":1,"rssi":100},{"mgdl":148,"mills":1521898472879,"device":"xDrip-DexcomG5","direction":"SingleDown","filtered":183264,"unfiltered":161216,"noise":1,"rssi":100},{"mgdl":139,"mills":1521898772862,"device":"xDrip-DexcomG5","direction":"FortyFiveDown","filtered":170784,"unfiltered":148928,"noise":1,"rssi":100},{"mgdl":132,"mills":1521899072896,"device":"xDrip-DexcomG5","direction":"FortyFiveDown","filtered":157248,"unfiltered":139552,"noise":1,"rssi":100},{"mgdl":125,"mills":1521899372834,"device":"xDrip-DexcomG5","direction":"FortyFiveDown","filtered":144416,"unfiltered":129616.00000000001,"noise":1,"rssi":100},{"mgdl":128,"mills":1521899973456,"device":"xDrip-DexcomG5","direction":"Flat","filtered":130240.00000000001,"unfiltered":133536,"noise":1,"rssi":100},{"mgdl":132,"mills":1521900573287,"device":"xDrip-DexcomG5","direction":"Flat","filtered":133504,"unfiltered":138720,"noise":1,"rssi":100},{"mgdl":127,"mills":1521900873711,"device":"xDrip-DexcomG5","direction":"Flat","filtered":136480,"unfiltered":132992,"noise":1,"rssi":100},{"mgdl":127,"mills":1521901180151,"device":"xDrip-DexcomG5","direction":"Flat","filtered":136896,"unfiltered":132128,"noise":1,"rssi":100},{"mgdl":125,"mills":1521901473582,"device":"xDrip-DexcomG5","direction":"Flat","filtered":134624,"unfiltered":129696,"noise":1,"rssi":100},{"mgdl":120,"mills":1521901773597,"device":"xDrip-DexcomG5","direction":"Flat","filtered":130704.00000000001,"unfiltered":123376,"noise":1,"rssi":100},{"mgdl":116,"mills":1521902075855,"device":"xDrip-DexcomG5","direction":"Flat","filtered":126272,"unfiltered":118448,"noise":1,"rssi":100}]
|
||||
List<BgReading> generateValidBgData() {
|
||||
List<BgReading> list = new ArrayList<>();
|
||||
try {
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}"))));
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":216,\"mills\":1514766600000,\"direction\":\"Flat\"}")))); // +2
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":219,\"mills\":1514766300000,\"direction\":\"Flat\"}")))); // +3
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":223,\"mills\":1514766000000,\"direction\":\"Flat\"}")))); // +4
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":222,\"mills\":1514765700000,\"direction\":\"Flat\"}"))));
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":224,\"mills\":1514765400000,\"direction\":\"Flat\"}"))));
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":226,\"mills\":1514765100000,\"direction\":\"Flat\"}"))));
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}"))));
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
List<BgReading> generateMostRecentBgData() {
|
||||
List<BgReading> list = new ArrayList<>();
|
||||
try {
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}"))));
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":216,\"mills\":1514766800000,\"direction\":\"Flat\"}")))); // +2
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":216,\"mills\":1514766600000,\"direction\":\"Flat\"}"))));
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
List<BgReading> generateInsufficientBgData() {
|
||||
List<BgReading> list = new ArrayList<>();
|
||||
return list;
|
||||
}
|
||||
|
||||
List<BgReading> generateOldBgData() {
|
||||
List<BgReading> list = new ArrayList<>();
|
||||
try {
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}"))));
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
List<BgReading> generateOneCurrentRecordBgData() {
|
||||
List<BgReading> list = new ArrayList<>();
|
||||
try {
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}"))));
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
List<BgReading> generateLibreTestData() {
|
||||
List<BgReading> list = new ArrayList<>();
|
||||
try {
|
||||
long end_time = 1514766900000L;
|
||||
double latest_reading = 100d;
|
||||
// Now
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":" + (latest_reading) + ",\"mills\":" + (end_time) + ",\"direction\":\"Flat\"}"))));
|
||||
// One minute ago
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":" + (latest_reading) + ",\"mills\":" + (end_time - (1000 * 60 * 1)) + ",\"direction\":\"Flat\"}"))));
|
||||
// Two minutes ago
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":" + (latest_reading) + ",\"mills\":" + (end_time - (1000 * 60 * 2)) + ",\"direction\":\"Flat\"}"))));
|
||||
|
||||
// Three minutes and beyond at constant rate
|
||||
for (int i=3; i < 50; i++) {
|
||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":" + (latest_reading + (i*2)) + ",\"mills\":" + (end_time - (1000 * 60 * i)) + ",\"direction\":\"Flat\"}"))));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,204 @@
|
|||
package info.nightscout.androidaps.plugins.iob.iobCobCalculatorPlugin
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.db.BgReading
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSgv
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import org.json.JSONException
|
||||
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.api.mockito.PowerMockito
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by mike on 26.03.2018.
|
||||
*/
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest(IobCobCalculatorPlugin::class, DateUtil::class)
|
||||
class GlucoseStatusTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
||||
|
||||
val injector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is GlucoseStatus) {
|
||||
it.aapsLogger = aapsLogger
|
||||
it.iobCobCalculatorPlugin = iobCobCalculatorPlugin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun toStringShouldBeOverloaded() {
|
||||
val glucoseStatus = GlucoseStatus(injector)
|
||||
Assert.assertEquals(true, glucoseStatus.log().contains("Delta"))
|
||||
}
|
||||
|
||||
@Test fun roundTest() {
|
||||
val glucoseStatus = GlucoseStatus(injector)
|
||||
glucoseStatus.glucose = 100.11111
|
||||
Assert.assertEquals(100.1, glucoseStatus.round().glucose, 0.0001)
|
||||
}
|
||||
|
||||
@Test fun calculateValidGlucoseStatus() {
|
||||
PowerMockito.`when`(iobCobCalculatorPlugin.bgReadings).thenReturn(generateValidBgData())
|
||||
val glucoseStatus = GlucoseStatus(injector).glucoseStatusData!!
|
||||
Assert.assertEquals(214.0, glucoseStatus.glucose, 0.001)
|
||||
Assert.assertEquals(-2.0, glucoseStatus.delta, 0.001)
|
||||
Assert.assertEquals(-2.5, glucoseStatus.short_avgdelta, 0.001) // -2 -2.5 -3 deltas are relative to current value
|
||||
Assert.assertEquals(-2.5, glucoseStatus.avgdelta, 0.001) // the same as short_avgdelta
|
||||
Assert.assertEquals(-2.0, glucoseStatus.long_avgdelta, 0.001) // -2 -2 -2 -2
|
||||
Assert.assertEquals(1514766900000L, glucoseStatus.date) // latest date
|
||||
}
|
||||
|
||||
@Test fun calculateMostRecentGlucoseStatus() {
|
||||
PowerMockito.`when`(iobCobCalculatorPlugin.bgReadings).thenReturn(generateMostRecentBgData())
|
||||
val glucoseStatus: GlucoseStatus = GlucoseStatus(injector).glucoseStatusData!!
|
||||
Assert.assertEquals(215.0, glucoseStatus.glucose, 0.001) // (214+216) / 2
|
||||
Assert.assertEquals(-1.0, glucoseStatus.delta, 0.001)
|
||||
Assert.assertEquals(-1.0, glucoseStatus.short_avgdelta, 0.001)
|
||||
Assert.assertEquals(-1.0, glucoseStatus.avgdelta, 0.001)
|
||||
Assert.assertEquals(0.0, glucoseStatus.long_avgdelta, 0.001)
|
||||
Assert.assertEquals(1514766900000L, glucoseStatus.date) // latest date, even when averaging
|
||||
}
|
||||
|
||||
@Test fun oneRecordShouldProduceZeroDeltas() {
|
||||
PowerMockito.`when`(iobCobCalculatorPlugin.bgReadings).thenReturn(generateOneCurrentRecordBgData())
|
||||
val glucoseStatus: GlucoseStatus = GlucoseStatus(injector).glucoseStatusData!!
|
||||
Assert.assertEquals(214.0, glucoseStatus.glucose, 0.001)
|
||||
Assert.assertEquals(0.0, glucoseStatus.delta, 0.001)
|
||||
Assert.assertEquals(0.0, glucoseStatus.short_avgdelta, 0.001) // -2 -2.5 -3 deltas are relative to current value
|
||||
Assert.assertEquals(0.0, glucoseStatus.avgdelta, 0.001) // the same as short_avgdelta
|
||||
Assert.assertEquals(0.0, glucoseStatus.long_avgdelta, 0.001) // -2 -2 -2 -2
|
||||
Assert.assertEquals(1514766900000L, glucoseStatus.date) // latest date
|
||||
}
|
||||
|
||||
@Test fun insuffientDataShouldReturnNull() {
|
||||
PowerMockito.`when`(iobCobCalculatorPlugin.bgReadings).thenReturn(generateInsufficientBgData())
|
||||
val glucoseStatus: GlucoseStatus? = GlucoseStatus(injector).glucoseStatusData
|
||||
Assert.assertEquals(null, glucoseStatus)
|
||||
}
|
||||
|
||||
@Test fun oldDataShouldReturnNull() {
|
||||
PowerMockito.`when`(iobCobCalculatorPlugin.bgReadings).thenReturn(generateOldBgData())
|
||||
val glucoseStatus: GlucoseStatus? = GlucoseStatus(injector).glucoseStatusData
|
||||
Assert.assertEquals(null, glucoseStatus)
|
||||
}
|
||||
|
||||
@Test fun returnOldDataIfAllowed() {
|
||||
PowerMockito.`when`(iobCobCalculatorPlugin.bgReadings).thenReturn(generateOldBgData())
|
||||
val glucoseStatus: GlucoseStatus? = GlucoseStatus(injector).getGlucoseStatusData(true)
|
||||
Assert.assertNotEquals(null, glucoseStatus)
|
||||
}
|
||||
|
||||
@Test fun averageShouldNotFailOnEmptyArray() {
|
||||
Assert.assertEquals(0.0, GlucoseStatus.average(ArrayList()), 0.001)
|
||||
}
|
||||
|
||||
@Test fun calculateGlucoseStatusForLibreTestBgData() {
|
||||
PowerMockito.`when`(iobCobCalculatorPlugin.bgReadings).thenReturn(generateLibreTestData())
|
||||
val glucoseStatus: GlucoseStatus = GlucoseStatus(injector).glucoseStatusData!!
|
||||
Assert.assertEquals(100.0, glucoseStatus.glucose, 0.001) //
|
||||
Assert.assertEquals(-10.0, glucoseStatus.delta, 0.001)
|
||||
Assert.assertEquals(-10.0, glucoseStatus.short_avgdelta, 0.001)
|
||||
Assert.assertEquals(-10.0, glucoseStatus.avgdelta, 0.001)
|
||||
Assert.assertEquals(-10.0, glucoseStatus.long_avgdelta, 0.001)
|
||||
Assert.assertEquals(1514766900000L, glucoseStatus.date) // latest date
|
||||
}
|
||||
|
||||
@Before
|
||||
fun initMocking() {
|
||||
PowerMockito.mockStatic(DateUtil::class.java)
|
||||
PowerMockito.`when`(DateUtil.now()).thenReturn(1514766900000L + T.mins(1).msecs())
|
||||
`when`(iobCobCalculatorPlugin.dataLock).thenReturn(Unit)
|
||||
}
|
||||
|
||||
// [{"mgdl":214,"mills":1521895773113,"device":"xDrip-DexcomG5","direction":"Flat","filtered":191040,"unfiltered":205024,"noise":1,"rssi":100},{"mgdl":219,"mills":1521896073352,"device":"xDrip-DexcomG5","direction":"Flat","filtered":200160,"unfiltered":209760,"noise":1,"rssi":100},{"mgdl":222,"mills":1521896372890,"device":"xDrip-DexcomG5","direction":"Flat","filtered":207360,"unfiltered":212512,"noise":1,"rssi":100},{"mgdl":220,"mills":1521896673062,"device":"xDrip-DexcomG5","direction":"Flat","filtered":211488,"unfiltered":210688,"noise":1,"rssi":100},{"mgdl":193,"mills":1521896972933,"device":"xDrip-DexcomG5","direction":"Flat","filtered":212384,"unfiltered":208960,"noise":1,"rssi":100},{"mgdl":181,"mills":1521897273336,"device":"xDrip-DexcomG5","direction":"SingleDown","filtered":210592,"unfiltered":204320,"noise":1,"rssi":100},{"mgdl":176,"mills":1521897572875,"device":"xDrip-DexcomG5","direction":"FortyFiveDown","filtered":206720,"unfiltered":197440,"noise":1,"rssi":100},{"mgdl":168,"mills":1521897872929,"device":"xDrip-DexcomG5","direction":"FortyFiveDown","filtered":201024,"unfiltered":187904,"noise":1,"rssi":100},{"mgdl":161,"mills":1521898172814,"device":"xDrip-DexcomG5","direction":"FortyFiveDown","filtered":193376,"unfiltered":178144,"noise":1,"rssi":100},{"mgdl":148,"mills":1521898472879,"device":"xDrip-DexcomG5","direction":"SingleDown","filtered":183264,"unfiltered":161216,"noise":1,"rssi":100},{"mgdl":139,"mills":1521898772862,"device":"xDrip-DexcomG5","direction":"FortyFiveDown","filtered":170784,"unfiltered":148928,"noise":1,"rssi":100},{"mgdl":132,"mills":1521899072896,"device":"xDrip-DexcomG5","direction":"FortyFiveDown","filtered":157248,"unfiltered":139552,"noise":1,"rssi":100},{"mgdl":125,"mills":1521899372834,"device":"xDrip-DexcomG5","direction":"FortyFiveDown","filtered":144416,"unfiltered":129616.00000000001,"noise":1,"rssi":100},{"mgdl":128,"mills":1521899973456,"device":"xDrip-DexcomG5","direction":"Flat","filtered":130240.00000000001,"unfiltered":133536,"noise":1,"rssi":100},{"mgdl":132,"mills":1521900573287,"device":"xDrip-DexcomG5","direction":"Flat","filtered":133504,"unfiltered":138720,"noise":1,"rssi":100},{"mgdl":127,"mills":1521900873711,"device":"xDrip-DexcomG5","direction":"Flat","filtered":136480,"unfiltered":132992,"noise":1,"rssi":100},{"mgdl":127,"mills":1521901180151,"device":"xDrip-DexcomG5","direction":"Flat","filtered":136896,"unfiltered":132128,"noise":1,"rssi":100},{"mgdl":125,"mills":1521901473582,"device":"xDrip-DexcomG5","direction":"Flat","filtered":134624,"unfiltered":129696,"noise":1,"rssi":100},{"mgdl":120,"mills":1521901773597,"device":"xDrip-DexcomG5","direction":"Flat","filtered":130704.00000000001,"unfiltered":123376,"noise":1,"rssi":100},{"mgdl":116,"mills":1521902075855,"device":"xDrip-DexcomG5","direction":"Flat","filtered":126272,"unfiltered":118448,"noise":1,"rssi":100}]
|
||||
private fun generateValidBgData(): List<BgReading> {
|
||||
val list: MutableList<BgReading> = ArrayList()
|
||||
try {
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}"))))
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":216,\"mills\":1514766600000,\"direction\":\"Flat\"}")))) // +2
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":219,\"mills\":1514766300000,\"direction\":\"Flat\"}")))) // +3
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":223,\"mills\":1514766000000,\"direction\":\"Flat\"}")))) // +4
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":222,\"mills\":1514765700000,\"direction\":\"Flat\"}"))))
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":224,\"mills\":1514765400000,\"direction\":\"Flat\"}"))))
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":226,\"mills\":1514765100000,\"direction\":\"Flat\"}"))))
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}"))))
|
||||
} catch (e: JSONException) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
private fun generateMostRecentBgData(): List<BgReading> {
|
||||
val list: MutableList<BgReading> = ArrayList()
|
||||
try {
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}"))))
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":216,\"mills\":1514766800000,\"direction\":\"Flat\"}")))) // +2
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":216,\"mills\":1514766600000,\"direction\":\"Flat\"}"))))
|
||||
} catch (e: JSONException) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
private fun generateInsufficientBgData(): List<BgReading> {
|
||||
return ArrayList()
|
||||
}
|
||||
|
||||
private fun generateOldBgData(): List<BgReading> {
|
||||
val list: MutableList<BgReading> = ArrayList()
|
||||
try {
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}"))))
|
||||
} catch (e: JSONException) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
private fun generateOneCurrentRecordBgData(): List<BgReading> {
|
||||
val list: MutableList<BgReading> = ArrayList()
|
||||
try {
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}"))))
|
||||
} catch (e: JSONException) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
private fun generateLibreTestData(): List<BgReading> {
|
||||
val list: MutableList<BgReading> = ArrayList()
|
||||
try {
|
||||
val endTime = 1514766900000L
|
||||
val latestReading = 100.0
|
||||
// Now
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":$latestReading,\"mills\":$endTime,\"direction\":\"Flat\"}"))))
|
||||
// One minute ago
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":" + latestReading + ",\"mills\":" + (endTime - 1000 * 60 * 1) + ",\"direction\":\"Flat\"}"))))
|
||||
// Two minutes ago
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":" + latestReading + ",\"mills\":" + (endTime - 1000 * 60 * 2) + ",\"direction\":\"Flat\"}"))))
|
||||
|
||||
// Three minutes and beyond at constant rate
|
||||
for (i in 3..49) {
|
||||
list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":" + (latestReading + i * 2) + ",\"mills\":" + (endTime - 1000 * 60 * i) + ",\"direction\":\"Flat\"}"))))
|
||||
}
|
||||
} catch (e: JSONException) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
return list
|
||||
}
|
||||
}
|
|
@ -1,457 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.iob.iobCobCalculatorPlugin;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import info.nightscout.androidaps.utils.T;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, SP.class, Context.class, L.class})
|
||||
public class IobCobCalculatorPluginTest {
|
||||
|
||||
IobCobCalculatorPlugin iobCobCalculatorPlugin = IobCobCalculatorPlugin.getPlugin();
|
||||
|
||||
@Test
|
||||
public void isAbout5minDataTest() {
|
||||
List<BgReading> bgReadingList = new ArrayList<>();
|
||||
|
||||
// Super data should not be touched
|
||||
bgReadingList.clear();
|
||||
bgReadingList.add(new BgReading().date(T.mins(20).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(15).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(10).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(5).msecs()).value(100));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData());
|
||||
|
||||
// too much shifted data should return false
|
||||
bgReadingList.clear();
|
||||
bgReadingList.add(new BgReading().date(T.mins(20).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(15).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(9).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(5).msecs()).value(100));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
|
||||
Assert.assertEquals(false, iobCobCalculatorPlugin.isAbout5minData());
|
||||
|
||||
// too much shifted and missing data should return false
|
||||
bgReadingList.clear();
|
||||
bgReadingList.add(new BgReading().date(T.mins(20).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(9).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(5).msecs()).value(100));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
|
||||
Assert.assertEquals(false, iobCobCalculatorPlugin.isAbout5minData());
|
||||
|
||||
// too much shifted and missing data should return false
|
||||
bgReadingList.clear();
|
||||
bgReadingList.add(new BgReading().date(T.mins(83).plus(T.secs(40)).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(78).plus(T.secs(40)).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(73).plus(T.secs(40)).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(68).plus(T.secs(40)).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(63).plus(T.secs(40)).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(58).plus(T.secs(40)).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(53).plus(T.secs(40)).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(48).plus(T.secs(40)).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(43).plus(T.secs(40)).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(38).plus(T.secs(33)).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(33).plus(T.secs(1)).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(28).plus(T.secs(0)).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(23).plus(T.secs(0)).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(16).plus(T.secs(36)).msecs()).value(100));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
|
||||
Assert.assertEquals(false, iobCobCalculatorPlugin.isAbout5minData());
|
||||
|
||||
// slighly shifted data should return true
|
||||
bgReadingList.clear();
|
||||
bgReadingList.add(new BgReading().date(T.mins(20).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(15).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(10).msecs() - T.secs(10).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(5).msecs()).value(100));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData());
|
||||
|
||||
// slighly shifted and missing data should return true
|
||||
bgReadingList.clear();
|
||||
bgReadingList.add(new BgReading().date(T.mins(20).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(10).msecs() - T.secs(10).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(5).msecs()).value(100));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createBucketedData5minTest() throws Exception {
|
||||
List<BgReading> bgReadingList = new ArrayList<>();
|
||||
|
||||
// Super data should not be touched
|
||||
bgReadingList.clear();
|
||||
bgReadingList.add(new BgReading().date(T.mins(20).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(15).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(10).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(5).msecs()).value(100));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData());
|
||||
|
||||
iobCobCalculatorPlugin.createBucketedData();
|
||||
|
||||
Assert.assertEquals(bgReadingList.get(0).date, iobCobCalculatorPlugin.getBucketedData().get(0).date);
|
||||
Assert.assertEquals(bgReadingList.get(3).date, iobCobCalculatorPlugin.getBucketedData().get(3).date);
|
||||
Assert.assertEquals(bgReadingList.size(), iobCobCalculatorPlugin.getBucketedData().size());
|
||||
|
||||
// Missing value should be replaced
|
||||
bgReadingList.clear();
|
||||
bgReadingList.add(new BgReading().date(T.mins(20).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(10).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(5).msecs()).value(100));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData());
|
||||
|
||||
iobCobCalculatorPlugin.createBucketedData();
|
||||
|
||||
Assert.assertEquals(bgReadingList.get(0).date, iobCobCalculatorPlugin.getBucketedData().get(0).date);
|
||||
Assert.assertEquals(bgReadingList.get(2).date, iobCobCalculatorPlugin.getBucketedData().get(3).date);
|
||||
Assert.assertEquals(bgReadingList.size() + 1, iobCobCalculatorPlugin.getBucketedData().size());
|
||||
|
||||
// drift should be cleared
|
||||
bgReadingList.clear();
|
||||
bgReadingList.add(new BgReading().date(T.mins(20).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(15).msecs() + T.secs(10).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(10).msecs() + T.secs(10).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(5).msecs() - T.secs(10).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(0).msecs()).value(100));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData());
|
||||
|
||||
iobCobCalculatorPlugin.createBucketedData();
|
||||
|
||||
Assert.assertEquals(T.mins(20).msecs(), iobCobCalculatorPlugin.getBucketedData().get(0).date);
|
||||
Assert.assertEquals(T.mins(15).msecs(), iobCobCalculatorPlugin.getBucketedData().get(1).date);
|
||||
Assert.assertEquals(T.mins(10).msecs(), iobCobCalculatorPlugin.getBucketedData().get(2).date);
|
||||
Assert.assertEquals(T.mins(5).msecs(), iobCobCalculatorPlugin.getBucketedData().get(3).date);
|
||||
Assert.assertEquals(bgReadingList.size(), iobCobCalculatorPlugin.getBucketedData().size());
|
||||
|
||||
// bucketed data should return null if not enough bg data
|
||||
bgReadingList.clear();
|
||||
bgReadingList.add(new BgReading().date(T.mins(30).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(5).msecs()).value(100));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData());
|
||||
|
||||
iobCobCalculatorPlugin.createBucketedData();
|
||||
|
||||
Assert.assertEquals(null, iobCobCalculatorPlugin.getBucketedData());
|
||||
|
||||
// data should be reconstructed
|
||||
bgReadingList.clear();
|
||||
bgReadingList.add(new BgReading().date(T.mins(50).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(45).msecs()).value(90));
|
||||
bgReadingList.add(new BgReading().date(T.mins(20).msecs()).value(40));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData());
|
||||
|
||||
iobCobCalculatorPlugin.createBucketedData();
|
||||
|
||||
Assert.assertEquals(T.mins(50).msecs(), iobCobCalculatorPlugin.getBucketedData().get(0).date);
|
||||
Assert.assertEquals(T.mins(20).msecs(), iobCobCalculatorPlugin.getBucketedData().get(6).date);
|
||||
Assert.assertEquals(7, iobCobCalculatorPlugin.getBucketedData().size());
|
||||
|
||||
Assert.assertEquals(100, iobCobCalculatorPlugin.getBucketedData().get(0).value, 1);
|
||||
Assert.assertEquals(90, iobCobCalculatorPlugin.getBucketedData().get(1).value, 1);
|
||||
Assert.assertEquals(50, iobCobCalculatorPlugin.getBucketedData().get(5).value, 1);
|
||||
Assert.assertEquals(40, iobCobCalculatorPlugin.getBucketedData().get(6).value, 1);
|
||||
|
||||
// non 5min data should be reconstructed
|
||||
bgReadingList.clear();
|
||||
bgReadingList.add(new BgReading().date(T.mins(50).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(48).msecs()).value(96));
|
||||
bgReadingList.add(new BgReading().date(T.mins(20).msecs()).value(40));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
Assert.assertEquals(false, iobCobCalculatorPlugin.isAbout5minData());
|
||||
|
||||
iobCobCalculatorPlugin.createBucketedData();
|
||||
|
||||
Assert.assertEquals(T.mins(50).msecs(), iobCobCalculatorPlugin.getBucketedData().get(0).date);
|
||||
Assert.assertEquals(T.mins(20).msecs(), iobCobCalculatorPlugin.getBucketedData().get(6).date);
|
||||
Assert.assertEquals(7, iobCobCalculatorPlugin.getBucketedData().size());
|
||||
|
||||
Assert.assertEquals(100, iobCobCalculatorPlugin.getBucketedData().get(0).value, 1);
|
||||
Assert.assertEquals(90, iobCobCalculatorPlugin.getBucketedData().get(1).value, 1);
|
||||
Assert.assertEquals(50, iobCobCalculatorPlugin.getBucketedData().get(5).value, 1);
|
||||
Assert.assertEquals(40, iobCobCalculatorPlugin.getBucketedData().get(6).value, 1);
|
||||
|
||||
//bucketed data should be null if no bg data available
|
||||
iobCobCalculatorPlugin.setBgReadings(null);
|
||||
iobCobCalculatorPlugin.createBucketedData();
|
||||
Assert.assertEquals(null, iobCobCalculatorPlugin.getBucketedData());
|
||||
|
||||
// real data gap test
|
||||
bgReadingList.clear();
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T13:34:55Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T13:14:55Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T13:09:55Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T13:04:55Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T12:59:55Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T12:54:55Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T12:49:55Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T12:44:55Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T12:39:55Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T12:34:55Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T12:29:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T12:24:55Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T12:19:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T12:14:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T12:09:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T12:04:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T11:59:55Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T11:54:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T11:49:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T11:44:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T11:39:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T11:34:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T11:29:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T11:24:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T11:19:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T11:14:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T11:09:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T11:04:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T10:59:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T10:54:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T10:49:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T10:44:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T10:39:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T10:34:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T10:29:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T10:24:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T10:19:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T10:14:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T10:09:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T10:04:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T09:59:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T09:54:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T09:49:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T09:44:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T09:39:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T09:35:05Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T09:30:17Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T09:24:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T09:19:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T09:14:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T09:09:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T09:04:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T08:59:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T08:54:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T08:49:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T08:44:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T08:40:02Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T08:34:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T08:29:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T08:24:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T08:19:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T08:14:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T08:09:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T08:04:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T07:59:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T07:54:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T07:49:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T07:44:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T07:39:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T07:34:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T07:30:03Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T07:25:17Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T07:19:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T07:14:58Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T07:09:58Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T07:04:58Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T06:59:58Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T06:54:58Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T06:49:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T06:44:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T06:39:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T06:34:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T06:29:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T06:24:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T06:19:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T06:14:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T06:10:03Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T06:04:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T05:59:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T05:54:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T05:49:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T05:44:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T05:39:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T05:34:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T05:29:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T05:24:57Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T05:19:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T05:14:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T05:09:57Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T05:04:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T04:59:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T04:54:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T04:50:03Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T04:44:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T04:39:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T04:34:57Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T04:29:57Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T04:24:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T04:19:57Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T04:14:57Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T04:10:03Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T04:04:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T03:59:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T03:54:56Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T03:50:03Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-09-05T03:44:57Z")).value(100));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData());
|
||||
|
||||
iobCobCalculatorPlugin.createBucketedData();
|
||||
Assert.assertEquals(DateUtil.fromISODateString("2018-09-05T13:34:57Z").getTime(), iobCobCalculatorPlugin.getBucketedData().get(0).date);
|
||||
Assert.assertEquals(DateUtil.fromISODateString("2018-09-05T03:44:57Z").getTime(), iobCobCalculatorPlugin.getBucketedData().get(iobCobCalculatorPlugin.getBucketedData().size() - 1).date);
|
||||
|
||||
// 5min 4sec data
|
||||
bgReadingList.clear();
|
||||
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T06:33:40Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T06:28:36Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T06:23:32Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T06:18:28Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T06:13:24Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T06:08:19Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T06:03:16Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T05:58:11Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T05:53:07Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T05:48:03Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T05:42:58Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T05:37:54Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T05:32:51Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T05:27:46Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T05:22:42Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T05:17:38Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T05:12:33Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T05:07:29Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T05:02:26Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T04:57:21Z")).value(100));
|
||||
bgReadingList.add(new BgReading().date(DateUtil.fromISODateString("2018-10-05T04:52:17Z")).value(100));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
|
||||
Assert.assertEquals(false, iobCobCalculatorPlugin.isAbout5minData());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBgReadingsTest() {
|
||||
List<BgReading> bgReadingList = new ArrayList<>();
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
|
||||
Assert.assertEquals(bgReadingList, iobCobCalculatorPlugin.getBgReadings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roundUpTimeTest() {
|
||||
Assert.assertEquals(T.mins(3).msecs(), iobCobCalculatorPlugin.roundUpTime(T.secs(155).msecs()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findNewerTest() {
|
||||
List<BgReading> bgReadingList = new ArrayList<>();
|
||||
|
||||
bgReadingList.add(new BgReading().date(T.mins(20).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(15).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(10).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(5).msecs()).value(100));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
|
||||
Assert.assertEquals(T.mins(10).msecs(), iobCobCalculatorPlugin.findNewer(T.mins(8).msecs()).date);
|
||||
Assert.assertEquals(T.mins(5).msecs(), iobCobCalculatorPlugin.findNewer(T.mins(5).msecs()).date);
|
||||
Assert.assertEquals(T.mins(10).msecs(), iobCobCalculatorPlugin.findNewer(T.mins(10).msecs()).date);
|
||||
Assert.assertEquals(T.mins(20).msecs(), iobCobCalculatorPlugin.findNewer(T.mins(20).msecs()).date);
|
||||
Assert.assertEquals(null, iobCobCalculatorPlugin.findNewer(T.mins(22).msecs()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOlderTest() {
|
||||
List<BgReading> bgReadingList = new ArrayList<>();
|
||||
|
||||
bgReadingList.add(new BgReading().date(T.mins(20).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(15).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(10).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(5).msecs()).value(100));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
|
||||
Assert.assertEquals(T.mins(5).msecs(), iobCobCalculatorPlugin.findOlder(T.mins(8).msecs()).date);
|
||||
Assert.assertEquals(T.mins(5).msecs(), iobCobCalculatorPlugin.findOlder(T.mins(5).msecs()).date);
|
||||
Assert.assertEquals(T.mins(10).msecs(), iobCobCalculatorPlugin.findOlder(T.mins(10).msecs()).date);
|
||||
Assert.assertEquals(T.mins(20).msecs(), iobCobCalculatorPlugin.findOlder(T.mins(20).msecs()).date);
|
||||
Assert.assertEquals(null, iobCobCalculatorPlugin.findOlder(T.mins(4).msecs()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findPreviousTimeFromBucketedDataTest() {
|
||||
List<BgReading> bgReadingList = new ArrayList<>();
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
iobCobCalculatorPlugin.createBucketedData();
|
||||
Assert.assertEquals(null, iobCobCalculatorPlugin.findPreviousTimeFromBucketedData(1000));
|
||||
|
||||
// Super data should not be touched
|
||||
bgReadingList.clear();
|
||||
bgReadingList.add(new BgReading().date(T.mins(20).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(15).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(10).msecs()).value(100));
|
||||
bgReadingList.add(new BgReading().date(T.mins(5).msecs()).value(100));
|
||||
|
||||
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
|
||||
iobCobCalculatorPlugin.createBucketedData();
|
||||
|
||||
Assert.assertEquals(null, iobCobCalculatorPlugin.findPreviousTimeFromBucketedData(T.mins(4).msecs()));
|
||||
Assert.assertEquals((Long) T.mins(5).msecs(), iobCobCalculatorPlugin.findPreviousTimeFromBucketedData(T.mins(6).msecs()));
|
||||
Assert.assertEquals((Long) T.mins(20).msecs(), iobCobCalculatorPlugin.findPreviousTimeFromBucketedData(T.mins(20).msecs()));
|
||||
Assert.assertEquals((Long) T.mins(20).msecs(), iobCobCalculatorPlugin.findPreviousTimeFromBucketedData(T.mins(25).msecs()));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void doMock() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockL();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,438 @@
|
|||
package info.nightscout.androidaps.plugins.iob.iobCobCalculatorPlugin
|
||||
|
||||
import android.content.Context
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.db.BgReading
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.L
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
import java.util.*
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
class IobCobCalculatorPluginTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var sp: SP
|
||||
private val rxBus: RxBusWrapper = RxBusWrapper()
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||
@Mock lateinit var sensitivityOref1Plugin: SensitivityOref1Plugin
|
||||
@Mock lateinit var sensitivityAAPSPlugin: SensitivityAAPSPlugin
|
||||
@Mock lateinit var sensitivityWeightedAveragePlugin: SensitivityWeightedAveragePlugin
|
||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||
|
||||
lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
||||
|
||||
val injector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is BgReading) {
|
||||
it.aapsLogger = aapsLogger
|
||||
it.defaultValueHelper = defaultValueHelper
|
||||
it.resourceHelper = resourceHelper
|
||||
it.profileFunction = profileFunction
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
fun mock() {
|
||||
iobCobCalculatorPlugin = IobCobCalculatorPlugin(injector, aapsLogger, rxBus, sp, resourceHelper, profileFunction, activePlugin, treatmentsPlugin, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isAbout5minDataTest() {
|
||||
val bgReadingList: MutableList<BgReading> = ArrayList()
|
||||
|
||||
// Super data should not be touched
|
||||
bgReadingList.clear()
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(20).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(15).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(10).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(5).msecs()).value(100.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData)
|
||||
|
||||
// too much shifted data should return false
|
||||
bgReadingList.clear()
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(20).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(15).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(9).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(5).msecs()).value(100.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(false, iobCobCalculatorPlugin.isAbout5minData)
|
||||
|
||||
// too much shifted and missing data should return false
|
||||
bgReadingList.clear()
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(20).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(9).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(5).msecs()).value(100.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(false, iobCobCalculatorPlugin.isAbout5minData)
|
||||
|
||||
// too much shifted and missing data should return false
|
||||
bgReadingList.clear()
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(83).plus(T.secs(40)).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(78).plus(T.secs(40)).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(73).plus(T.secs(40)).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(68).plus(T.secs(40)).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(63).plus(T.secs(40)).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(58).plus(T.secs(40)).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(53).plus(T.secs(40)).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(48).plus(T.secs(40)).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(43).plus(T.secs(40)).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(38).plus(T.secs(33)).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(33).plus(T.secs(1)).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(28).plus(T.secs(0)).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(23).plus(T.secs(0)).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(16).plus(T.secs(36)).msecs()).value(100.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(false, iobCobCalculatorPlugin.isAbout5minData)
|
||||
|
||||
// slightly shifted data should return true
|
||||
bgReadingList.clear()
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(20).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(15).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(10).msecs() - T.secs(10).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(5).msecs()).value(100.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData)
|
||||
|
||||
// slightly shifted and missing data should return true
|
||||
bgReadingList.clear()
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(20).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(10).msecs() - T.secs(10).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(5).msecs()).value(100.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun createBucketedData5minTest() {
|
||||
val bgReadingList: MutableList<BgReading> = ArrayList()
|
||||
|
||||
// Super data should not be touched
|
||||
bgReadingList.clear()
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(20).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(15).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(10).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(5).msecs()).value(100.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData)
|
||||
iobCobCalculatorPlugin.createBucketedData()
|
||||
Assert.assertEquals(bgReadingList[0].date, iobCobCalculatorPlugin.bucketedData[0].date)
|
||||
Assert.assertEquals(bgReadingList[3].date, iobCobCalculatorPlugin.bucketedData[3].date)
|
||||
Assert.assertEquals(bgReadingList.size.toLong(), iobCobCalculatorPlugin.bucketedData.size.toLong())
|
||||
|
||||
// Missing value should be replaced
|
||||
bgReadingList.clear()
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(20).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(10).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(5).msecs()).value(100.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData)
|
||||
iobCobCalculatorPlugin.createBucketedData()
|
||||
Assert.assertEquals(bgReadingList[0].date, iobCobCalculatorPlugin.bucketedData[0].date)
|
||||
Assert.assertEquals(bgReadingList[2].date, iobCobCalculatorPlugin.bucketedData[3].date)
|
||||
Assert.assertEquals(bgReadingList.size + 1.toLong(), iobCobCalculatorPlugin.bucketedData.size.toLong())
|
||||
|
||||
// drift should be cleared
|
||||
bgReadingList.clear()
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(20).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(15).msecs() + T.secs(10).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(10).msecs() + T.secs(10).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(5).msecs() - T.secs(10).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(0).msecs()).value(100.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData)
|
||||
iobCobCalculatorPlugin.createBucketedData()
|
||||
Assert.assertEquals(T.mins(20).msecs(), iobCobCalculatorPlugin.bucketedData[0].date)
|
||||
Assert.assertEquals(T.mins(15).msecs(), iobCobCalculatorPlugin.bucketedData[1].date)
|
||||
Assert.assertEquals(T.mins(10).msecs(), iobCobCalculatorPlugin.bucketedData[2].date)
|
||||
Assert.assertEquals(T.mins(5).msecs(), iobCobCalculatorPlugin.bucketedData[3].date)
|
||||
Assert.assertEquals(bgReadingList.size.toLong(), iobCobCalculatorPlugin.bucketedData.size.toLong())
|
||||
|
||||
// bucketed data should return null if not enough bg data
|
||||
bgReadingList.clear()
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(30).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(5).msecs()).value(100.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData)
|
||||
iobCobCalculatorPlugin.createBucketedData()
|
||||
Assert.assertEquals(null, iobCobCalculatorPlugin.bucketedData)
|
||||
|
||||
// data should be reconstructed
|
||||
bgReadingList.clear()
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(50).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(45).msecs()).value(90.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(20).msecs()).value(40.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData)
|
||||
iobCobCalculatorPlugin.createBucketedData()
|
||||
Assert.assertEquals(T.mins(50).msecs(), iobCobCalculatorPlugin.bucketedData[0].date)
|
||||
Assert.assertEquals(T.mins(20).msecs(), iobCobCalculatorPlugin.bucketedData[6].date)
|
||||
Assert.assertEquals(7, iobCobCalculatorPlugin.bucketedData.size.toLong())
|
||||
Assert.assertEquals(100.0, iobCobCalculatorPlugin.bucketedData[0].value, 1.0)
|
||||
Assert.assertEquals(90.0, iobCobCalculatorPlugin.bucketedData[1].value, 1.0)
|
||||
Assert.assertEquals(50.0, iobCobCalculatorPlugin.bucketedData[5].value, 1.0)
|
||||
Assert.assertEquals(40.0, iobCobCalculatorPlugin.bucketedData[6].value, 1.0)
|
||||
|
||||
// non 5min data should be reconstructed
|
||||
bgReadingList.clear()
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(50).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(48).msecs()).value(96.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(20).msecs()).value(40.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(false, iobCobCalculatorPlugin.isAbout5minData)
|
||||
iobCobCalculatorPlugin.createBucketedData()
|
||||
Assert.assertEquals(T.mins(50).msecs(), iobCobCalculatorPlugin.bucketedData[0].date)
|
||||
Assert.assertEquals(T.mins(20).msecs(), iobCobCalculatorPlugin.bucketedData[6].date)
|
||||
Assert.assertEquals(7, iobCobCalculatorPlugin.bucketedData.size.toLong())
|
||||
Assert.assertEquals(100.0, iobCobCalculatorPlugin.bucketedData[0].value, 1.0)
|
||||
Assert.assertEquals(90.0, iobCobCalculatorPlugin.bucketedData[1].value, 1.0)
|
||||
Assert.assertEquals(50.0, iobCobCalculatorPlugin.bucketedData[5].value, 1.0)
|
||||
Assert.assertEquals(40.0, iobCobCalculatorPlugin.bucketedData[6].value, 1.0)
|
||||
|
||||
//bucketed data should be null if no bg data available
|
||||
iobCobCalculatorPlugin.bgReadings = null
|
||||
iobCobCalculatorPlugin.createBucketedData()
|
||||
Assert.assertEquals(null, iobCobCalculatorPlugin.bucketedData)
|
||||
|
||||
// real data gap test
|
||||
bgReadingList.clear()
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T13:34:55Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T13:14:55Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T13:09:55Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T13:04:55Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T12:59:55Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T12:54:55Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T12:49:55Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T12:44:55Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T12:39:55Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T12:34:55Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T12:29:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T12:24:55Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T12:19:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T12:14:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T12:09:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T12:04:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T11:59:55Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T11:54:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T11:49:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T11:44:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T11:39:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T11:34:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T11:29:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T11:24:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T11:19:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T11:14:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T11:09:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T11:04:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T10:59:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T10:54:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T10:49:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T10:44:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T10:39:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T10:34:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T10:29:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T10:24:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T10:19:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T10:14:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T10:09:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T10:04:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T09:59:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T09:54:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T09:49:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T09:44:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T09:39:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T09:35:05Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T09:30:17Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T09:24:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T09:19:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T09:14:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T09:09:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T09:04:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T08:59:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T08:54:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T08:49:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T08:44:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T08:40:02Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T08:34:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T08:29:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T08:24:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T08:19:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T08:14:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T08:09:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T08:04:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T07:59:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T07:54:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T07:49:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T07:44:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T07:39:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T07:34:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T07:30:03Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T07:25:17Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T07:19:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T07:14:58Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T07:09:58Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T07:04:58Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T06:59:58Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T06:54:58Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T06:49:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T06:44:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T06:39:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T06:34:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T06:29:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T06:24:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T06:19:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T06:14:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T06:10:03Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T06:04:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T05:59:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T05:54:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T05:49:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T05:44:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T05:39:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T05:34:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T05:29:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T05:24:57Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T05:19:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T05:14:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T05:09:57Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T05:04:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T04:59:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T04:54:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T04:50:03Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T04:44:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T04:39:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T04:34:57Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T04:29:57Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T04:24:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T04:19:57Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T04:14:57Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T04:10:03Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T04:04:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T03:59:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T03:54:56Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T03:50:03Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-09-05T03:44:57Z")).value(100.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData)
|
||||
iobCobCalculatorPlugin.createBucketedData()
|
||||
Assert.assertEquals(DateUtil.fromISODateString("2018-09-05T13:34:57Z").time, iobCobCalculatorPlugin.bucketedData[0].date)
|
||||
Assert.assertEquals(DateUtil.fromISODateString("2018-09-05T03:44:57Z").time, iobCobCalculatorPlugin.bucketedData[iobCobCalculatorPlugin.bucketedData.size - 1].date)
|
||||
|
||||
// 5min 4sec data
|
||||
bgReadingList.clear()
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T06:33:40Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T06:28:36Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T06:23:32Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T06:18:28Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T06:13:24Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T06:08:19Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T06:03:16Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T05:58:11Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T05:53:07Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T05:48:03Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T05:42:58Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T05:37:54Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T05:32:51Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T05:27:46Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T05:22:42Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T05:17:38Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T05:12:33Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T05:07:29Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T05:02:26Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T04:57:21Z")).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(DateUtil.fromISODateString("2018-10-05T04:52:17Z")).value(100.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(false, iobCobCalculatorPlugin.isAbout5minData)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun bgReadingsTest() {
|
||||
val bgReadingList: List<BgReading> = ArrayList()
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(bgReadingList, iobCobCalculatorPlugin.bgReadings)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun roundUpTimeTest() {
|
||||
Assert.assertEquals(T.mins(3).msecs(), IobCobCalculatorPlugin.roundUpTime(T.secs(155).msecs()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findNewerTest() {
|
||||
val bgReadingList: MutableList<BgReading> = ArrayList()
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(20).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(15).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(10).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(5).msecs()).value(100.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(T.mins(10).msecs(), iobCobCalculatorPlugin.findNewer(T.mins(8).msecs())!!.date)
|
||||
Assert.assertEquals(T.mins(5).msecs(), iobCobCalculatorPlugin.findNewer(T.mins(5).msecs())!!.date)
|
||||
Assert.assertEquals(T.mins(10).msecs(), iobCobCalculatorPlugin.findNewer(T.mins(10).msecs())!!.date)
|
||||
Assert.assertEquals(T.mins(20).msecs(), iobCobCalculatorPlugin.findNewer(T.mins(20).msecs())!!.date)
|
||||
Assert.assertEquals(null, iobCobCalculatorPlugin.findNewer(T.mins(22).msecs()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findOlderTest() {
|
||||
val bgReadingList: MutableList<BgReading> = ArrayList()
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(20).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(15).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(10).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(5).msecs()).value(100.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
Assert.assertEquals(T.mins(5).msecs(), iobCobCalculatorPlugin.findOlder(T.mins(8).msecs())!!.date)
|
||||
Assert.assertEquals(T.mins(5).msecs(), iobCobCalculatorPlugin.findOlder(T.mins(5).msecs())!!.date)
|
||||
Assert.assertEquals(T.mins(10).msecs(), iobCobCalculatorPlugin.findOlder(T.mins(10).msecs())!!.date)
|
||||
Assert.assertEquals(T.mins(20).msecs(), iobCobCalculatorPlugin.findOlder(T.mins(20).msecs())!!.date)
|
||||
Assert.assertEquals(null, iobCobCalculatorPlugin.findOlder(T.mins(4).msecs()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findPreviousTimeFromBucketedDataTest() {
|
||||
val bgReadingList: MutableList<BgReading> = ArrayList()
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
iobCobCalculatorPlugin.createBucketedData()
|
||||
Assert.assertEquals(null, iobCobCalculatorPlugin.findPreviousTimeFromBucketedData(1000))
|
||||
|
||||
// Super data should not be touched
|
||||
bgReadingList.clear()
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(20).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(15).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(10).msecs()).value(100.0))
|
||||
bgReadingList.add(BgReading(injector).date(T.mins(5).msecs()).value(100.0))
|
||||
iobCobCalculatorPlugin.bgReadings = bgReadingList
|
||||
iobCobCalculatorPlugin.createBucketedData()
|
||||
Assert.assertEquals(null, iobCobCalculatorPlugin.findPreviousTimeFromBucketedData(T.mins(4).msecs()))
|
||||
Assert.assertEquals(T.mins(5).msecs(), iobCobCalculatorPlugin.findPreviousTimeFromBucketedData(T.mins(6).msecs()))
|
||||
Assert.assertEquals(T.mins(20).msecs(), iobCobCalculatorPlugin.findPreviousTimeFromBucketedData(T.mins(20).msecs()))
|
||||
Assert.assertEquals(T.mins(20).msecs(), iobCobCalculatorPlugin.findPreviousTimeFromBucketedData(T.mins(25).msecs()))
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue