Skip to content

Commit

Permalink
shared-tests #13
Browse files Browse the repository at this point in the history
  • Loading branch information
MilosKozak committed Sep 4, 2023
1 parent a2fb04c commit 22c1f8f
Show file tree
Hide file tree
Showing 34 changed files with 591 additions and 712 deletions.
1 change: 1 addition & 0 deletions pump/omnipod-eros/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
api "androidx.room:room-rxjava3:$room_version"
kapt "androidx.room:room-compiler:$room_version"

testImplementation project(':app-wear-shared:shared-tests')
// optional - Test helpers
testImplementation("androidx.room:room-testing:$room_version")
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package info.nightscout.androidaps.plugins.pump.omnipod.eros

import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryDatabase
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.pump.PumpEnactResult
import info.nightscout.interfaces.pump.PumpSync
Expand All @@ -17,12 +15,12 @@ import info.nightscout.pump.common.defs.TempBasalPair
import info.nightscout.rx.TestAapsSchedulers
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.sharedtests.TestBase
import org.joda.time.DateTimeZone
import org.joda.time.tz.UTCProvider
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Answers
import org.mockito.ArgumentMatchers
import org.mockito.Mock
import org.mockito.Mockito
Expand All @@ -33,7 +31,6 @@ class OmnipodErosPumpPluginTest : TestBase() {

@Mock lateinit var injector: HasAndroidInjector
@Mock lateinit var rh: ResourceHelper
@Mock(answer = Answers.RETURNS_DEEP_STUBS) lateinit var activePlugin: ActivePlugin
@Mock lateinit var aapsOmnipodErosManager: AapsOmnipodErosManager
@Mock lateinit var uiInteraction: UiInteraction
@Mock lateinit var commandQueue: CommandQueue
Expand Down Expand Up @@ -101,17 +98,17 @@ class OmnipodErosPumpPluginTest : TestBase() {
val result5 =
plugin.setTempBasalPercent(-50, 60, profile, false, PumpSync.TemporaryBasalType.NORMAL)
// Then return correct values
Assert.assertEquals(result1.absolute, 0.4, 0.01)
Assert.assertEquals(result1.duration, 30)
Assert.assertEquals(result2.absolute, 25.0, 0.01)
Assert.assertEquals(result2.duration, 30000)
Assert.assertEquals(result3.absolute, 0.0, 0.01)
Assert.assertEquals(result3.duration, 30)
Assert.assertEquals(result4.absolute, -1.0, 0.01)
Assert.assertEquals(result4.duration, -1)
Assertions.assertEquals(result1.absolute, 0.4, 0.01)
Assertions.assertEquals(result1.duration, 30)
Assertions.assertEquals(result2.absolute, 25.0, 0.01)
Assertions.assertEquals(result2.duration, 30000)
Assertions.assertEquals(result3.absolute, 0.0, 0.01)
Assertions.assertEquals(result3.duration, 30)
Assertions.assertEquals(result4.absolute, -1.0, 0.01)
Assertions.assertEquals(result4.duration, -1)
// this is validated downstream, see TempBasalExtraCommand
Assert.assertEquals(result5.absolute, -0.25, 0.01)
Assert.assertEquals(result5.duration, 60)
Assertions.assertEquals(result5.absolute, -0.25, 0.01)
Assertions.assertEquals(result5.duration, 60)

// Given zero basal
`when`(profile.getBasal()).thenReturn(0.0)
Expand All @@ -121,40 +118,40 @@ class OmnipodErosPumpPluginTest : TestBase() {
result2 =
plugin.setTempBasalPercent(0, 0, profile, false, PumpSync.TemporaryBasalType.NORMAL)
// Then return zero values
Assert.assertEquals(result1.absolute, 0.0, 0.01)
Assert.assertEquals(result1.duration, 90)
Assert.assertEquals(result2.absolute, -1.0, 0.01)
Assert.assertEquals(result2.duration, -1)
Assertions.assertEquals(result1.absolute, 0.0, 0.01)
Assertions.assertEquals(result1.duration, 90)
Assertions.assertEquals(result2.absolute, -1.0, 0.01)
Assertions.assertEquals(result2.duration, -1)

// Given unhealthy basal
`when`(profile.getBasal()).thenReturn(500.0)
// When treatment
result1 =
plugin.setTempBasalPercent(80, 30, profile, false, PumpSync.TemporaryBasalType.NORMAL)
// Then return sane values
Assert.assertEquals(
Assertions.assertEquals(
result1.absolute,
PumpType.OMNIPOD_EROS.determineCorrectBasalSize(500.0 * 0.8),
0.01
)
Assert.assertEquals(result1.duration, 30)
Assertions.assertEquals(result1.duration, 30)

// Given weird basal
`when`(profile.getBasal()).thenReturn(1.234567)
// When treatment
result1 =
plugin.setTempBasalPercent(280, 600, profile, false, PumpSync.TemporaryBasalType.NORMAL)
// Then return sane values
Assert.assertEquals(result1.absolute, 3.4567876, 0.01)
Assert.assertEquals(result1.duration, 600)
Assertions.assertEquals(result1.absolute, 3.4567876, 0.01)
Assertions.assertEquals(result1.duration, 600)

// Given negative basal
`when`(profile.getBasal()).thenReturn(-1.234567)
// When treatment
result1 =
plugin.setTempBasalPercent(280, 510, profile, false, PumpSync.TemporaryBasalType.NORMAL)
// Then return negative value (this is validated further downstream, see TempBasalExtraCommand)
Assert.assertEquals(result1.absolute, -3.4567876, 0.01)
Assert.assertEquals(result1.duration, 510)
Assertions.assertEquals(result1.absolute, -3.4567876, 0.01)
Assertions.assertEquals(result1.duration, 510)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication

import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager
import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.profile.Profile.ProfileValue
import org.joda.time.Duration
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito

internal class AapsOmnipodErosManagerTest {

@Test fun validProfile() {
val profile = Mockito.mock(Profile::class.java)
Mockito.`when`(profile.getBasalValues()).thenReturn(
arrayOf(
ProfileValue(0, 0.5),
ProfileValue(18000, 1.0),
ProfileValue(50400, 3.05)
)
)
val basalSchedule = AapsOmnipodErosManager.mapProfileToBasalSchedule(profile)
val entries = basalSchedule.entries
Assertions.assertEquals(3, entries.size)
val entry1 = entries[0]
Assertions.assertEquals(Duration.standardSeconds(0), entry1.startTime)
Assertions.assertEquals(0.5, entry1.rate, 0.000001)
val entry2 = entries[1]
Assertions.assertEquals(Duration.standardSeconds(18000), entry2.startTime)
Assertions.assertEquals(1.0, entry2.rate, 0.000001)
val entry3 = entries[2]
Assertions.assertEquals(Duration.standardSeconds(50400), entry3.startTime)
Assertions.assertEquals(3.05, entry3.rate, 0.000001)
}

@Test fun invalidProfileNullProfile() {
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(null) }
}

@Test fun invalidProfileNullEntries() {
Assertions.assertThrows(IllegalArgumentException::class.java) {
AapsOmnipodErosManager.mapProfileToBasalSchedule(Mockito.mock(Profile::class.java))
}
}

@Test fun invalidProfileZeroEntries() {
val profile = Mockito.mock(Profile::class.java)
Mockito.`when`(profile.getBasalValues()).thenReturn(emptyArray())
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
}

@Test fun invalidProfileNonZeroOffset() {
val profile = Mockito.mock(Profile::class.java)
Mockito.`when`(profile.getBasalValues()).thenReturn(
arrayOf(
ProfileValue(1800, 0.5)
)
)
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
}

@Test fun invalidProfileMoreThan24Hours() {
val profile = Mockito.mock(Profile::class.java)
Mockito.`when`(profile.getBasalValues()).thenReturn(
arrayOf(
ProfileValue(0, 0.5),
ProfileValue(86400, 0.5)
)
)
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
}

@Test fun invalidProfileNegativeOffset() {
val profile = Mockito.mock(Profile::class.java)
Mockito.`when`(profile.getBasalValues()).thenReturn(
arrayOf(
ProfileValue(-1, 0.5)
)
)
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
}

@Test fun roundsToSupportedPrecision() {
val profile = Mockito.mock(Profile::class.java)
Mockito.`when`(profile.getBasalValues()).thenReturn(
arrayOf(
ProfileValue(0, 0.04)
)
)
val basalSchedule = AapsOmnipodErosManager.mapProfileToBasalSchedule(profile)
val basalScheduleEntry = basalSchedule.entries[0]
Assertions.assertEquals(0.05, basalScheduleEntry.rate, 0.000001)
}
}

0 comments on commit 22c1f8f

Please sign in to comment.