parent
6dced9e724
commit
343e2fe6fb
1 changed files with 23 additions and 23 deletions
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.plugins.constraints.bgQualityCheck
|
package info.nightscout.plugins.constraints.bgQualityCheck
|
||||||
|
|
||||||
import app.aaps.shared.tests.TestBase
|
import app.aaps.shared.tests.TestBase
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.core.constraints.ConstraintObject
|
import info.nightscout.core.constraints.ConstraintObject
|
||||||
|
@ -15,7 +16,6 @@ import info.nightscout.plugins.constraints.R
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
import org.junit.jupiter.api.Assertions
|
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.ArgumentMatchers.any
|
import org.mockito.ArgumentMatchers.any
|
||||||
|
@ -62,16 +62,16 @@ class BgQualityCheckPluginTest : TestBase() {
|
||||||
fun runTest() {
|
fun runTest() {
|
||||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(null)
|
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(null)
|
||||||
plugin.processBgData()
|
plugin.processBgData()
|
||||||
Assertions.assertEquals(BgQualityCheck.State.UNKNOWN, plugin.state)
|
assertThat(plugin.state).isEqualTo(BgQualityCheck.State.UNKNOWN)
|
||||||
Assertions.assertEquals(0, plugin.icon())
|
assertThat(plugin.icon()).isEqualTo(0)
|
||||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
|
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
|
||||||
plugin.processBgData()
|
plugin.processBgData()
|
||||||
Assertions.assertEquals(BgQualityCheck.State.FIVE_MIN_DATA, plugin.state)
|
assertThat(plugin.state).isEqualTo(BgQualityCheck.State.FIVE_MIN_DATA)
|
||||||
Assertions.assertEquals(0, plugin.icon())
|
assertThat(plugin.icon()).isEqualTo(0)
|
||||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
|
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
|
||||||
plugin.processBgData()
|
plugin.processBgData()
|
||||||
Assertions.assertEquals(BgQualityCheck.State.RECALCULATED, plugin.state)
|
assertThat(plugin.state).isEqualTo(BgQualityCheck.State.RECALCULATED)
|
||||||
Assertions.assertEquals(R.drawable.ic_baseline_warning_24_yellow, plugin.icon())
|
assertThat(plugin.icon()).isEqualTo(R.drawable.ic_baseline_warning_24_yellow)
|
||||||
|
|
||||||
val superData: MutableList<GlucoseValue> = ArrayList()
|
val superData: MutableList<GlucoseValue> = ArrayList()
|
||||||
superData.add(
|
superData.add(
|
||||||
|
@ -118,10 +118,10 @@ class BgQualityCheckPluginTest : TestBase() {
|
||||||
|
|
||||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
|
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
|
||||||
plugin.processBgData()
|
plugin.processBgData()
|
||||||
Assertions.assertEquals(BgQualityCheck.State.FIVE_MIN_DATA, plugin.state)
|
assertThat(plugin.state).isEqualTo(BgQualityCheck.State.FIVE_MIN_DATA)
|
||||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
|
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
|
||||||
plugin.processBgData()
|
plugin.processBgData()
|
||||||
Assertions.assertEquals(BgQualityCheck.State.RECALCULATED, plugin.state)
|
assertThat(plugin.state).isEqualTo(BgQualityCheck.State.RECALCULATED)
|
||||||
|
|
||||||
val duplicatedData: MutableList<GlucoseValue> = ArrayList()
|
val duplicatedData: MutableList<GlucoseValue> = ArrayList()
|
||||||
duplicatedData.add(
|
duplicatedData.add(
|
||||||
|
@ -178,8 +178,8 @@ class BgQualityCheckPluginTest : TestBase() {
|
||||||
|
|
||||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
|
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
|
||||||
plugin.processBgData()
|
plugin.processBgData()
|
||||||
Assertions.assertEquals(BgQualityCheck.State.DOUBLED, plugin.state)
|
assertThat(plugin.state).isEqualTo(BgQualityCheck.State.DOUBLED)
|
||||||
Assertions.assertEquals(R.drawable.ic_baseline_warning_24_red, plugin.icon())
|
assertThat(plugin.icon()).isEqualTo(R.drawable.ic_baseline_warning_24_red)
|
||||||
|
|
||||||
val identicalData: MutableList<GlucoseValue> = ArrayList()
|
val identicalData: MutableList<GlucoseValue> = ArrayList()
|
||||||
identicalData.add(
|
identicalData.add(
|
||||||
|
@ -236,7 +236,7 @@ class BgQualityCheckPluginTest : TestBase() {
|
||||||
|
|
||||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
|
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
|
||||||
plugin.processBgData()
|
plugin.processBgData()
|
||||||
Assertions.assertEquals(BgQualityCheck.State.DOUBLED, plugin.state)
|
assertThat(plugin.state).isEqualTo(BgQualityCheck.State.DOUBLED)
|
||||||
|
|
||||||
// Flat data Libre
|
// Flat data Libre
|
||||||
val flatData: MutableList<GlucoseValue> = ArrayList()
|
val flatData: MutableList<GlucoseValue> = ArrayList()
|
||||||
|
@ -344,8 +344,8 @@ class BgQualityCheckPluginTest : TestBase() {
|
||||||
`when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(flatData[0]))
|
`when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(flatData[0]))
|
||||||
|
|
||||||
plugin.processBgData()
|
plugin.processBgData()
|
||||||
Assertions.assertEquals(BgQualityCheck.State.FLAT, plugin.state)
|
assertThat(plugin.state).isEqualTo(BgQualityCheck.State.FLAT)
|
||||||
Assertions.assertEquals(R.drawable.ic_baseline_trending_flat_24, plugin.icon())
|
assertThat(plugin.icon()).isEqualTo(R.drawable.ic_baseline_trending_flat_24)
|
||||||
|
|
||||||
// Flat data Libre
|
// Flat data Libre
|
||||||
val flatDataDexcom: MutableList<GlucoseValue> = ArrayList()
|
val flatDataDexcom: MutableList<GlucoseValue> = ArrayList()
|
||||||
|
@ -453,8 +453,8 @@ class BgQualityCheckPluginTest : TestBase() {
|
||||||
`when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(flatDataDexcom[0]))
|
`when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(flatDataDexcom[0]))
|
||||||
|
|
||||||
plugin.processBgData()
|
plugin.processBgData()
|
||||||
Assertions.assertNotEquals(BgQualityCheck.State.FLAT, plugin.state)
|
assertThat(plugin.state).isNotEqualTo(BgQualityCheck.State.FLAT)
|
||||||
Assertions.assertNotEquals(R.drawable.ic_baseline_trending_flat_24, plugin.icon())
|
assertThat(plugin.icon()).isNotEqualTo(R.drawable.ic_baseline_trending_flat_24)
|
||||||
|
|
||||||
// not enough data
|
// not enough data
|
||||||
val incompleteData: MutableList<GlucoseValue> = ArrayList()
|
val incompleteData: MutableList<GlucoseValue> = ArrayList()
|
||||||
|
@ -481,7 +481,7 @@ class BgQualityCheckPluginTest : TestBase() {
|
||||||
`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(incompleteData)
|
`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(incompleteData)
|
||||||
`when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(incompleteData[0]))
|
`when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(incompleteData[0]))
|
||||||
plugin.processBgData()// must be more than 5 values
|
plugin.processBgData()// must be more than 5 values
|
||||||
Assertions.assertNotEquals(BgQualityCheck.State.FLAT, plugin.state)
|
assertThat(plugin.state).isNotEqualTo(BgQualityCheck.State.FLAT)
|
||||||
flatData.add(
|
flatData.add(
|
||||||
GlucoseValue(
|
GlucoseValue(
|
||||||
raw = 0.0,
|
raw = 0.0,
|
||||||
|
@ -553,19 +553,19 @@ class BgQualityCheckPluginTest : TestBase() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
plugin.processBgData() // must be at least 45 min old
|
plugin.processBgData() // must be at least 45 min old
|
||||||
Assertions.assertNotEquals(BgQualityCheck.State.FLAT, plugin.state)
|
assertThat(plugin.state).isNotEqualTo(BgQualityCheck.State.FLAT)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun applyMaxIOBConstraintsTest() {
|
fun applyMaxIOBConstraintsTest() {
|
||||||
plugin.state = BgQualityCheck.State.UNKNOWN
|
plugin.state = BgQualityCheck.State.UNKNOWN
|
||||||
Assertions.assertEquals(10.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value(), 0.001)
|
assertThat(plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value()).isWithin(0.001).of(10.0)
|
||||||
plugin.state = BgQualityCheck.State.FIVE_MIN_DATA
|
plugin.state = BgQualityCheck.State.FIVE_MIN_DATA
|
||||||
Assertions.assertEquals(10.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value(), 0.001)
|
assertThat(plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value()).isWithin(0.001).of(10.0)
|
||||||
plugin.state = BgQualityCheck.State.RECALCULATED
|
plugin.state = BgQualityCheck.State.RECALCULATED
|
||||||
Assertions.assertEquals(10.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value(), 0.001)
|
assertThat(plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value()).isWithin(0.001).of(10.0)
|
||||||
plugin.state = BgQualityCheck.State.DOUBLED
|
plugin.state = BgQualityCheck.State.DOUBLED
|
||||||
Assertions.assertEquals(0.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value(), 0.001)
|
assertThat(plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value()).isWithin(0.001).of(0.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue