Merge pull request #2816 from ryanhaining/assertthat_plugins
Rewrites plugins/aps/ tests to use matchers
This commit is contained in:
commit
2707ff8ed3
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.plugins.aps.loop
|
package info.nightscout.plugins.aps.loop
|
||||||
|
|
||||||
import app.aaps.shared.tests.TestBaseWithProfile
|
import app.aaps.shared.tests.TestBaseWithProfile
|
||||||
|
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
|
||||||
|
@ -11,7 +12,6 @@ import info.nightscout.interfaces.constraints.Constraint
|
||||||
import info.nightscout.interfaces.constraints.ConstraintsChecker
|
import info.nightscout.interfaces.constraints.ConstraintsChecker
|
||||||
import info.nightscout.interfaces.pump.defs.PumpType
|
import info.nightscout.interfaces.pump.defs.PumpType
|
||||||
import info.nightscout.plugins.aps.APSResultObject
|
import info.nightscout.plugins.aps.APSResultObject
|
||||||
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
|
import org.mockito.ArgumentMatchers
|
||||||
|
@ -75,21 +75,21 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
closedLoopEnabled.set(true)
|
closedLoopEnabled.set(true)
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
|
||||||
apsResult.tempBasalRequested(false)
|
apsResult.tempBasalRequested(false)
|
||||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isFalse()
|
||||||
apsResult.tempBasalRequested(true).percent(200).duration(30)
|
apsResult.tempBasalRequested(true).percent(200).duration(30)
|
||||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isTrue()
|
||||||
|
|
||||||
// open loop
|
// open loop
|
||||||
closedLoopEnabled.set(false)
|
closedLoopEnabled.set(false)
|
||||||
// no change requested
|
// no change requested
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
|
||||||
apsResult.tempBasalRequested(false)
|
apsResult.tempBasalRequested(false)
|
||||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isFalse()
|
||||||
|
|
||||||
// request 100% when no temp is running
|
// request 100% when no temp is running
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
|
||||||
apsResult.tempBasalRequested(true).percent(100).duration(30)
|
apsResult.tempBasalRequested(true).percent(100).duration(30)
|
||||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isFalse()
|
||||||
|
|
||||||
// request equal temp
|
// request equal temp
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||||
|
@ -102,7 +102,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
apsResult.tempBasalRequested(true).percent(70).duration(30)
|
apsResult.tempBasalRequested(true).percent(70).duration(30)
|
||||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isFalse()
|
||||||
|
|
||||||
// request zero temp
|
// request zero temp
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||||
|
@ -115,7 +115,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
apsResult.tempBasalRequested(true).percent(0).duration(30)
|
apsResult.tempBasalRequested(true).percent(0).duration(30)
|
||||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isTrue()
|
||||||
|
|
||||||
// request high temp
|
// request high temp
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||||
|
@ -128,7 +128,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
apsResult.tempBasalRequested(true).percent(200).duration(30)
|
apsResult.tempBasalRequested(true).percent(200).duration(30)
|
||||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isTrue()
|
||||||
|
|
||||||
// request slightly different temp
|
// request slightly different temp
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||||
|
@ -141,7 +141,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
apsResult.tempBasalRequested(true).percent(80).duration(30)
|
apsResult.tempBasalRequested(true).percent(80).duration(30)
|
||||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isFalse()
|
||||||
|
|
||||||
// request different temp
|
// request different temp
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||||
|
@ -154,7 +154,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
apsResult.tempBasalRequested(true).percent(120).duration(30)
|
apsResult.tempBasalRequested(true).percent(120).duration(30)
|
||||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isTrue()
|
||||||
|
|
||||||
// it should work with absolute temps too
|
// it should work with absolute temps too
|
||||||
// request different temp
|
// request different temp
|
||||||
|
@ -168,7 +168,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
apsResult.tempBasalRequested(true).percent(100).duration(30)
|
apsResult.tempBasalRequested(true).percent(100).duration(30)
|
||||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isFalse()
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||||
TemporaryBasal(
|
TemporaryBasal(
|
||||||
timestamp = 0,
|
timestamp = 0,
|
||||||
|
@ -179,7 +179,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
apsResult.tempBasalRequested(true).percent(50).duration(30)
|
apsResult.tempBasalRequested(true).percent(50).duration(30)
|
||||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isTrue()
|
||||||
|
|
||||||
// **** ABSOLUTE pump ****
|
// **** ABSOLUTE pump ****
|
||||||
testPumpPlugin.pumpDescription.fillFor(PumpType.MEDTRONIC_515_715) // U/h based
|
testPumpPlugin.pumpDescription.fillFor(PumpType.MEDTRONIC_515_715) // U/h based
|
||||||
|
@ -190,7 +190,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
// request 100% when no temp is running
|
// request 100% when no temp is running
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
|
||||||
apsResult.tempBasalRequested(true).rate(1.0).duration(30)
|
apsResult.tempBasalRequested(true).rate(1.0).duration(30)
|
||||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isFalse()
|
||||||
|
|
||||||
// request equal temp
|
// request equal temp
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||||
|
@ -203,7 +203,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
apsResult.tempBasalRequested(true).rate(2.0).duration(30)
|
apsResult.tempBasalRequested(true).rate(2.0).duration(30)
|
||||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isFalse()
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||||
TemporaryBasal(
|
TemporaryBasal(
|
||||||
timestamp = 0,
|
timestamp = 0,
|
||||||
|
@ -214,7 +214,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
apsResult.tempBasalRequested(true).rate(2.0).duration(30)
|
apsResult.tempBasalRequested(true).rate(2.0).duration(30)
|
||||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isFalse()
|
||||||
|
|
||||||
// request zero temp
|
// request zero temp
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||||
|
@ -227,7 +227,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
apsResult.tempBasalRequested(true).rate(0.0).duration(30)
|
apsResult.tempBasalRequested(true).rate(0.0).duration(30)
|
||||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isTrue()
|
||||||
|
|
||||||
// request high temp
|
// request high temp
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||||
|
@ -240,7 +240,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
apsResult.tempBasalRequested(true).rate(35.0).duration(30)
|
apsResult.tempBasalRequested(true).rate(35.0).duration(30)
|
||||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isTrue()
|
||||||
|
|
||||||
// request slightly different temp
|
// request slightly different temp
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||||
|
@ -253,7 +253,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
apsResult.tempBasalRequested(true).rate(1.2).duration(30)
|
apsResult.tempBasalRequested(true).rate(1.2).duration(30)
|
||||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isFalse()
|
||||||
|
|
||||||
// request different temp
|
// request different temp
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||||
|
@ -266,7 +266,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
apsResult.tempBasalRequested(true).rate(1.5).duration(30)
|
apsResult.tempBasalRequested(true).rate(1.5).duration(30)
|
||||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isTrue()
|
||||||
|
|
||||||
// it should work with percent temps too
|
// it should work with percent temps too
|
||||||
// request different temp
|
// request different temp
|
||||||
|
@ -280,7 +280,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
apsResult.tempBasalRequested(true).rate(1.1).duration(30)
|
apsResult.tempBasalRequested(true).rate(1.1).duration(30)
|
||||||
Assertions.assertEquals(false, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isFalse()
|
||||||
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
|
||||||
TemporaryBasal(
|
TemporaryBasal(
|
||||||
timestamp = 0,
|
timestamp = 0,
|
||||||
|
@ -291,7 +291,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
apsResult.tempBasalRequested(true).rate(0.5).duration(30)
|
apsResult.tempBasalRequested(true).rate(0.5).duration(30)
|
||||||
Assertions.assertEquals(true, apsResult.isChangeRequested)
|
assertThat(apsResult.isChangeRequested).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun cloneTest() {
|
@Test fun cloneTest() {
|
||||||
|
@ -307,7 +307,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
}
|
}
|
||||||
apsResult.rate(10.0)
|
apsResult.rate(10.0)
|
||||||
val apsResult2 = apsResult.newAndClone(injector)
|
val apsResult2 = apsResult.newAndClone(injector)
|
||||||
Assertions.assertEquals(apsResult.rate, apsResult2.rate, 0.0)
|
assertThat(apsResult2.rate).isEqualTo(apsResult.rate)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun jsonTest() {
|
@Test fun jsonTest() {
|
||||||
|
@ -323,9 +323,9 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
it.rh = rh
|
it.rh = rh
|
||||||
}
|
}
|
||||||
apsResult.rate(20.0).tempBasalRequested(true)
|
apsResult.rate(20.0).tempBasalRequested(true)
|
||||||
Assertions.assertEquals(20.0, safeGetDouble(apsResult.json(), "rate"), 0.0)
|
assertThat(safeGetDouble(apsResult.json(), "rate")).isEqualTo(20.0)
|
||||||
apsResult.rate(20.0).tempBasalRequested(false)
|
apsResult.rate(20.0).tempBasalRequested(false)
|
||||||
Assertions.assertEquals(false, apsResult.json()?.has("rate"))
|
assertThat(apsResult.json()?.has("rate")).isFalse()
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.plugins.general.autotune
|
package info.nightscout.plugins.general.autotune
|
||||||
|
|
||||||
import app.aaps.shared.tests.TestBaseWithProfile
|
import app.aaps.shared.tests.TestBaseWithProfile
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import info.nightscout.core.profile.ProfileSealed
|
import info.nightscout.core.profile.ProfileSealed
|
||||||
import info.nightscout.core.utils.JsonHelper
|
import info.nightscout.core.utils.JsonHelper
|
||||||
import info.nightscout.database.entities.data.Block
|
import info.nightscout.database.entities.data.Block
|
||||||
|
@ -13,7 +14,6 @@ import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
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.Mock
|
import org.mockito.Mock
|
||||||
|
@ -47,15 +47,13 @@ class AutotuneCoreTest : TestBaseWithProfile() {
|
||||||
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_autosens_min, 0.7)).thenReturn(autotuneMin)
|
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_autosens_min, 0.7)).thenReturn(autotuneMin)
|
||||||
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact, 3.0)).thenReturn(min5mCarbImpact)
|
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact, 3.0)).thenReturn(min5mCarbImpact)
|
||||||
val oapsOutputProfileJson = File("src/test/res/autotune/test1/aapsorefprofile.json").readText()
|
val oapsOutputProfileJson = File("src/test/res/autotune/test1/aapsorefprofile.json").readText()
|
||||||
val oapsOutputProfile = atProfileFromOapsJson(JSONObject(oapsOutputProfileJson), dateUtil)
|
val oapsOutputProfile = atProfileFromOapsJson(JSONObject(oapsOutputProfileJson), dateUtil)!!
|
||||||
val outProfile = autotuneCore.tuneAllTheThings(prep, inputProfile, inputProfile)
|
val outProfile = autotuneCore.tuneAllTheThings(prep, inputProfile, inputProfile)
|
||||||
oapsOutputProfile?.let {
|
assertThat(outProfile.isf).isEqualTo(oapsOutputProfile.isf)
|
||||||
Assertions.assertEquals(oapsOutputProfile.isf, outProfile.isf, 0.0)
|
assertThat(outProfile.ic).isEqualTo(oapsOutputProfile.ic)
|
||||||
Assertions.assertEquals(oapsOutputProfile.ic, outProfile.ic, 0.0)
|
for (i in 0..23) {
|
||||||
for (i in 0..23)
|
assertThat(outProfile.basal[i]).isEqualTo(oapsOutputProfile.basal[i])
|
||||||
Assertions.assertEquals(oapsOutputProfile.basal[i], outProfile.basal[i], 0.0)
|
|
||||||
}
|
}
|
||||||
?: Assertions.fail()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
@Suppress("SpellCheckingInspection")
|
||||||
|
@ -71,15 +69,13 @@ class AutotuneCoreTest : TestBaseWithProfile() {
|
||||||
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_autosens_min, 0.7)).thenReturn(autotuneMin)
|
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_autosens_min, 0.7)).thenReturn(autotuneMin)
|
||||||
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact, 3.0)).thenReturn(min5mCarbImpact)
|
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact, 3.0)).thenReturn(min5mCarbImpact)
|
||||||
val oapsOutputProfileJson = File("src/test/res/autotune/test4/newprofile.2022-05-30.json").readText()
|
val oapsOutputProfileJson = File("src/test/res/autotune/test4/newprofile.2022-05-30.json").readText()
|
||||||
val oapsOutputProfile = atProfileFromOapsJson(JSONObject(oapsOutputProfileJson), dateUtil)
|
val oapsOutputProfile = atProfileFromOapsJson(JSONObject(oapsOutputProfileJson), dateUtil)!!
|
||||||
val outProfile = autotuneCore.tuneAllTheThings(prep, inputProfile, pumpProfile)
|
val outProfile = autotuneCore.tuneAllTheThings(prep, inputProfile, pumpProfile)
|
||||||
oapsOutputProfile?.let {
|
assertThat(outProfile.isf).isEqualTo(oapsOutputProfile.isf)
|
||||||
Assertions.assertEquals(oapsOutputProfile.isf, outProfile.isf, 0.0)
|
assertThat(outProfile.ic).isEqualTo(oapsOutputProfile.ic)
|
||||||
Assertions.assertEquals(oapsOutputProfile.ic, outProfile.ic, 0.0)
|
for (i in 0..23) {
|
||||||
for (i in 0..23)
|
assertThat(outProfile.basal[i]).isEqualTo(oapsOutputProfile.basal[i])
|
||||||
Assertions.assertEquals(oapsOutputProfile.basal[i], outProfile.basal[i], 0.0)
|
|
||||||
}
|
}
|
||||||
?: Assertions.fail()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.plugins.general.autotune
|
package info.nightscout.plugins.general.autotune
|
||||||
|
|
||||||
import app.aaps.shared.tests.TestBaseWithProfile
|
import app.aaps.shared.tests.TestBaseWithProfile
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import info.nightscout.core.extensions.shiftBlock
|
import info.nightscout.core.extensions.shiftBlock
|
||||||
import info.nightscout.core.profile.ProfileSealed
|
import info.nightscout.core.profile.ProfileSealed
|
||||||
import info.nightscout.core.utils.JsonHelper
|
import info.nightscout.core.utils.JsonHelper
|
||||||
|
@ -21,7 +22,6 @@ import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
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.Mock
|
import org.mockito.Mock
|
||||||
|
@ -63,26 +63,20 @@ class AutotunePrepTest : TestBaseWithProfile() {
|
||||||
autotuneIob.boluses = buildBoluses(oapsPreppedGlucose) //Values from oapsPrepData because linked to iob calculation method for TBR
|
autotuneIob.boluses = buildBoluses(oapsPreppedGlucose) //Values from oapsPrepData because linked to iob calculation method for TBR
|
||||||
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact, 3.0)).thenReturn(min5mCarbImpact)
|
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact, 3.0)).thenReturn(min5mCarbImpact)
|
||||||
`when`(sp.getBoolean(info.nightscout.core.utils.R.string.key_autotune_categorize_uam_as_basal, false)).thenReturn(false)
|
`when`(sp.getBoolean(info.nightscout.core.utils.R.string.key_autotune_categorize_uam_as_basal, false)).thenReturn(false)
|
||||||
val aapsPreppedGlucose = autotunePrep.categorizeBGDatums(inputProfile, inputProfile.localInsulin, false)
|
val aapsPreppedGlucose = autotunePrep.categorizeBGDatums(inputProfile, inputProfile.localInsulin, false)!!
|
||||||
try {
|
// compare all categorization calculated by aaps plugin (aapsPreppedGlucose) with categorization calculated by OpenAPS (oapsPreppedGlucose)
|
||||||
aapsPreppedGlucose?.let { // compare all categorization calculated by aaps plugin (aapsPreppedGlucose) with categorization calculated by OpenAPS (oapsPreppedGlucose)
|
|
||||||
for (i in aapsPreppedGlucose.crData.indices)
|
for (i in aapsPreppedGlucose.crData.indices)
|
||||||
Assertions.assertTrue(oapsPreppedGlucose.crData[i].equals(aapsPreppedGlucose.crData[i]))
|
assertThat(oapsPreppedGlucose.crData[i].equals(aapsPreppedGlucose.crData[i])).isTrue()
|
||||||
for (i in aapsPreppedGlucose.csfGlucoseData.indices)
|
for (i in aapsPreppedGlucose.csfGlucoseData.indices)
|
||||||
Assertions.assertTrue(oapsPreppedGlucose.csfGlucoseData[i].equals(aapsPreppedGlucose.csfGlucoseData[i]))
|
assertThat(oapsPreppedGlucose.csfGlucoseData[i].equals(aapsPreppedGlucose.csfGlucoseData[i])).isTrue()
|
||||||
oapsPreppedGlucose.isfGlucoseData = oapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
|
oapsPreppedGlucose.isfGlucoseData = oapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
|
||||||
aapsPreppedGlucose.isfGlucoseData = aapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
|
aapsPreppedGlucose.isfGlucoseData = aapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
|
||||||
for (i in aapsPreppedGlucose.isfGlucoseData.indices)
|
for (i in aapsPreppedGlucose.isfGlucoseData.indices)
|
||||||
Assertions.assertTrue(oapsPreppedGlucose.isfGlucoseData[i].equals(aapsPreppedGlucose.isfGlucoseData[i]))
|
assertThat(oapsPreppedGlucose.isfGlucoseData[i].equals(aapsPreppedGlucose.isfGlucoseData[i])).isTrue()
|
||||||
oapsPreppedGlucose.basalGlucoseData = oapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
|
oapsPreppedGlucose.basalGlucoseData = oapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
|
||||||
aapsPreppedGlucose.basalGlucoseData = aapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
|
aapsPreppedGlucose.basalGlucoseData = aapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
|
||||||
for (i in aapsPreppedGlucose.basalGlucoseData.indices)
|
for (i in aapsPreppedGlucose.basalGlucoseData.indices)
|
||||||
Assertions.assertTrue(oapsPreppedGlucose.basalGlucoseData[i].equals(aapsPreppedGlucose.basalGlucoseData[i]))
|
assertThat(oapsPreppedGlucose.basalGlucoseData[i].equals(aapsPreppedGlucose.basalGlucoseData[i])).isTrue()
|
||||||
}
|
|
||||||
?: Assertions.fail()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Assertions.fail()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -102,26 +96,20 @@ class AutotunePrepTest : TestBaseWithProfile() {
|
||||||
autotuneIob.boluses = buildBoluses(oapsPreppedGlucose) //Values from oapsPrepData because linked to iob calculation method for TBR
|
autotuneIob.boluses = buildBoluses(oapsPreppedGlucose) //Values from oapsPrepData because linked to iob calculation method for TBR
|
||||||
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact, 3.0)).thenReturn(min5mCarbImpact)
|
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact, 3.0)).thenReturn(min5mCarbImpact)
|
||||||
`when`(sp.getBoolean(info.nightscout.core.utils.R.string.key_autotune_categorize_uam_as_basal, false)).thenReturn(false) // CategorizeUAM as Basal = False
|
`when`(sp.getBoolean(info.nightscout.core.utils.R.string.key_autotune_categorize_uam_as_basal, false)).thenReturn(false) // CategorizeUAM as Basal = False
|
||||||
val aapsPreppedGlucose = autotunePrep.categorizeBGDatums(inputProfile, inputProfile.localInsulin, false)
|
val aapsPreppedGlucose = autotunePrep.categorizeBGDatums(inputProfile, inputProfile.localInsulin, false)!!
|
||||||
try {
|
// compare all categorization calculated by aaps plugin (aapsPreppedGlucose) with categorization calculated by OpenAPS (oapsPreppedGlucose)
|
||||||
aapsPreppedGlucose?.let { // compare all categorization calculated by aaps plugin (aapsPreppedGlucose) with categorization calculated by OpenAPS (oapsPreppedGlucose)
|
|
||||||
for (i in aapsPreppedGlucose.crData.indices)
|
for (i in aapsPreppedGlucose.crData.indices)
|
||||||
Assertions.assertTrue(oapsPreppedGlucose.crData[i].equals(aapsPreppedGlucose.crData[i]))
|
assertThat(oapsPreppedGlucose.crData[i].equals(aapsPreppedGlucose.crData[i])).isTrue()
|
||||||
for (i in aapsPreppedGlucose.csfGlucoseData.indices)
|
for (i in aapsPreppedGlucose.csfGlucoseData.indices)
|
||||||
Assertions.assertTrue(oapsPreppedGlucose.csfGlucoseData[i].equals(aapsPreppedGlucose.csfGlucoseData[i]))
|
assertThat(oapsPreppedGlucose.csfGlucoseData[i].equals(aapsPreppedGlucose.csfGlucoseData[i])).isTrue()
|
||||||
oapsPreppedGlucose.isfGlucoseData = oapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
|
oapsPreppedGlucose.isfGlucoseData = oapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
|
||||||
aapsPreppedGlucose.isfGlucoseData = aapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
|
aapsPreppedGlucose.isfGlucoseData = aapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
|
||||||
for (i in aapsPreppedGlucose.isfGlucoseData.indices)
|
for (i in aapsPreppedGlucose.isfGlucoseData.indices)
|
||||||
Assertions.assertTrue(oapsPreppedGlucose.isfGlucoseData[i].equals(aapsPreppedGlucose.isfGlucoseData[i]))
|
assertThat(oapsPreppedGlucose.isfGlucoseData[i].equals(aapsPreppedGlucose.isfGlucoseData[i])).isTrue()
|
||||||
oapsPreppedGlucose.basalGlucoseData = oapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
|
oapsPreppedGlucose.basalGlucoseData = oapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
|
||||||
aapsPreppedGlucose.basalGlucoseData = aapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
|
aapsPreppedGlucose.basalGlucoseData = aapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
|
||||||
for (i in aapsPreppedGlucose.basalGlucoseData.indices)
|
for (i in aapsPreppedGlucose.basalGlucoseData.indices)
|
||||||
Assertions.assertTrue(oapsPreppedGlucose.basalGlucoseData[i].equals(aapsPreppedGlucose.basalGlucoseData[i]))
|
assertThat(oapsPreppedGlucose.basalGlucoseData[i].equals(aapsPreppedGlucose.basalGlucoseData[i])).isTrue()
|
||||||
}
|
|
||||||
?: Assertions.fail()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Assertions.fail()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -141,26 +129,20 @@ class AutotunePrepTest : TestBaseWithProfile() {
|
||||||
autotuneIob.boluses = buildBoluses(oapsPreppedGlucose) //Values from oapsPrepData because linked to iob calculation method for TBR
|
autotuneIob.boluses = buildBoluses(oapsPreppedGlucose) //Values from oapsPrepData because linked to iob calculation method for TBR
|
||||||
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact, 3.0)).thenReturn(min5mCarbImpact)
|
`when`(sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact, 3.0)).thenReturn(min5mCarbImpact)
|
||||||
`when`(sp.getBoolean(info.nightscout.core.utils.R.string.key_autotune_categorize_uam_as_basal, false)).thenReturn(true) // CategorizeUAM as Basal = True
|
`when`(sp.getBoolean(info.nightscout.core.utils.R.string.key_autotune_categorize_uam_as_basal, false)).thenReturn(true) // CategorizeUAM as Basal = True
|
||||||
val aapsPreppedGlucose = autotunePrep.categorizeBGDatums(inputProfile, inputProfile.localInsulin, false)
|
val aapsPreppedGlucose = autotunePrep.categorizeBGDatums(inputProfile, inputProfile.localInsulin, false)!!
|
||||||
try {
|
// compare all categorization calculated by aaps plugin (aapsPreppedGlucose) with categorization calculated by OpenAPS (oapsPreppedGlucose)
|
||||||
aapsPreppedGlucose?.let { // compare all categorization calculated by aaps plugin (aapsPreppedGlucose) with categorization calculated by OpenAPS (oapsPreppedGlucose)
|
|
||||||
for (i in aapsPreppedGlucose.crData.indices)
|
for (i in aapsPreppedGlucose.crData.indices)
|
||||||
Assertions.assertTrue(oapsPreppedGlucose.crData[i].equals(aapsPreppedGlucose.crData[i]))
|
assertThat(oapsPreppedGlucose.crData[i].equals(aapsPreppedGlucose.crData[i])).isTrue()
|
||||||
for (i in aapsPreppedGlucose.csfGlucoseData.indices)
|
for (i in aapsPreppedGlucose.csfGlucoseData.indices)
|
||||||
Assertions.assertTrue(oapsPreppedGlucose.csfGlucoseData[i].equals(aapsPreppedGlucose.csfGlucoseData[i]))
|
assertThat(oapsPreppedGlucose.csfGlucoseData[i].equals(aapsPreppedGlucose.csfGlucoseData[i])).isTrue()
|
||||||
oapsPreppedGlucose.isfGlucoseData = oapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
|
oapsPreppedGlucose.isfGlucoseData = oapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
|
||||||
aapsPreppedGlucose.isfGlucoseData = aapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
|
aapsPreppedGlucose.isfGlucoseData = aapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
|
||||||
for (i in aapsPreppedGlucose.isfGlucoseData.indices)
|
for (i in aapsPreppedGlucose.isfGlucoseData.indices)
|
||||||
Assertions.assertTrue(oapsPreppedGlucose.isfGlucoseData[i].equals(aapsPreppedGlucose.isfGlucoseData[i]))
|
assertThat(oapsPreppedGlucose.isfGlucoseData[i].equals(aapsPreppedGlucose.isfGlucoseData[i])).isTrue()
|
||||||
oapsPreppedGlucose.basalGlucoseData = oapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
|
oapsPreppedGlucose.basalGlucoseData = oapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
|
||||||
aapsPreppedGlucose.basalGlucoseData = aapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
|
aapsPreppedGlucose.basalGlucoseData = aapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
|
||||||
for (i in aapsPreppedGlucose.basalGlucoseData.indices)
|
for (i in aapsPreppedGlucose.basalGlucoseData.indices)
|
||||||
Assertions.assertTrue(oapsPreppedGlucose.basalGlucoseData[i].equals(aapsPreppedGlucose.basalGlucoseData[i]))
|
assertThat(oapsPreppedGlucose.basalGlucoseData[i].equals(aapsPreppedGlucose.basalGlucoseData[i])).isTrue()
|
||||||
}
|
|
||||||
?: Assertions.fail()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Assertions.fail()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************************************************************************************************************************
|
/*************************************************************************************************************************************************************************************
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package info.nightscout.plugins.general.autotune
|
package info.nightscout.plugins.general.autotune
|
||||||
|
|
||||||
import app.aaps.shared.tests.TestBaseWithProfile
|
import app.aaps.shared.tests.TestBaseWithProfile
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import info.nightscout.plugins.general.autotune.data.BGDatum
|
import info.nightscout.plugins.general.autotune.data.BGDatum
|
||||||
import info.nightscout.plugins.general.autotune.data.CRDatum
|
import info.nightscout.plugins.general.autotune.data.CRDatum
|
||||||
import info.nightscout.plugins.general.autotune.data.PreppedGlucose
|
import info.nightscout.plugins.general.autotune.data.PreppedGlucose
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
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 java.io.File
|
import java.io.File
|
||||||
|
@ -43,10 +43,10 @@ class PreppedGlucoseTest : TestBaseWithProfile() {
|
||||||
JSONObject("{\"device\":\"AndroidAPS-DexcomG6\",\"date\":1653180549000,\"dateString\":\"2022-05-22T00:49:09.000Z\",\"isValid\":true,\"sgv\":121,\"direction\":\"FortyFiveDown\",\"type\":\"sgv\",\"_id\":\"628988a3da46aa0004d1e0f5\",\"glucose\":121,\"avgDelta\":\"-5.25\",\"BGI\":-3.32,\"deviation\":\"-1.93\"}"),
|
JSONObject("{\"device\":\"AndroidAPS-DexcomG6\",\"date\":1653180549000,\"dateString\":\"2022-05-22T00:49:09.000Z\",\"isValid\":true,\"sgv\":121,\"direction\":\"FortyFiveDown\",\"type\":\"sgv\",\"_id\":\"628988a3da46aa0004d1e0f5\",\"glucose\":121,\"avgDelta\":\"-5.25\",\"BGI\":-3.32,\"deviation\":\"-1.93\"}"),
|
||||||
dateUtil
|
dateUtil
|
||||||
)
|
)
|
||||||
Assertions.assertEquals(3, prep1.crData.size)
|
assertThat(prep1.crData).hasSize(3)
|
||||||
Assertions.assertTrue(crData0.equals(prep1.crData[0]))
|
assertThat(crData0.equals(prep1.crData[0])).isTrue()
|
||||||
Assertions.assertTrue(csfDataEnd.equals(prep1.csfGlucoseData[prep1.csfGlucoseData.size - 1]))
|
assertThat(csfDataEnd.equals(prep1.csfGlucoseData[prep1.csfGlucoseData.size - 1])).isTrue()
|
||||||
Assertions.assertTrue(isfData0.equals(prep1.isfGlucoseData[0]))
|
assertThat(isfData0.equals(prep1.isfGlucoseData[0])).isTrue()
|
||||||
Assertions.assertTrue(basalDataEnd.equals(prep1.basalGlucoseData[prep1.basalGlucoseData.size - 1]))
|
assertThat(basalDataEnd.equals(prep1.basalGlucoseData[prep1.basalGlucoseData.size - 1])).isTrue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue