iobplugin tests

This commit is contained in:
Milos Kozak 2018-08-17 19:49:39 +02:00
parent c98ffb2df1
commit 1b6e54f8a8
2 changed files with 26 additions and 2 deletions

View file

@ -351,11 +351,11 @@ public class IobCobCalculatorPlugin extends PluginBase {
}
@Nullable
private Long findPreviousTimeFromBucketedData(long time) {
public Long findPreviousTimeFromBucketedData(long time) {
if (bucketed_data == null)
return null;
for (int index = 0; index < bucketed_data.size(); index++) {
if (bucketed_data.get(index).date < time)
if (bucketed_data.get(index).date <= time)
return bucketed_data.get(index).date;
}
return null;

View file

@ -242,6 +242,30 @@ public class IobCobCalculatorPluginTest {
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();