Merge pull request #2828 from ryanhaining/assertthat_plugins_main

Rewrites plugins/main tests with matchers
This commit is contained in:
Milos Kozak 2023-09-24 10:34:25 +02:00 committed by GitHub
commit 15e7a7fee5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 220 additions and 231 deletions

View file

@ -1,13 +1,13 @@
package info.nightscout.core.extensions package info.nightscout.core.extensions
import app.aaps.shared.tests.TestBaseWithProfile import app.aaps.shared.tests.TestBaseWithProfile
import com.google.common.truth.Truth.assertThat
import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.Bolus
import info.nightscout.insulin.InsulinLyumjevPlugin import info.nightscout.insulin.InsulinLyumjevPlugin
import info.nightscout.interfaces.insulin.Insulin import info.nightscout.interfaces.insulin.Insulin
import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.ui.UiInteraction
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.Mock import org.mockito.Mock
@ -22,26 +22,26 @@ class BolusExtensionKtTest : TestBaseWithProfile() {
private val dia = 7.0 private val dia = 7.0
@BeforeEach @BeforeEach fun setup() {
fun setup() {
insulin = InsulinLyumjevPlugin(profileInjector, rh, profileFunctions, rxBus, aapsLogger, config, hardLimits, uiInteraction) insulin = InsulinLyumjevPlugin(profileInjector, rh, profileFunctions, rxBus, aapsLogger, config, hardLimits, uiInteraction)
Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin) Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin)
} }
@Test @Test fun iobCalc() {
fun iobCalc() {
val bolus = Bolus(timestamp = now - 1, amount = 1.0, type = Bolus.Type.NORMAL) val bolus = Bolus(timestamp = now - 1, amount = 1.0, type = Bolus.Type.NORMAL)
// there should be almost full IOB after now // there should be almost full IOB after now
Assertions.assertEquals(1.0, bolus.iobCalc(activePlugin, now, dia).iobContrib, 0.01) assertThat(bolus.iobCalc(activePlugin, now, dia).iobContrib).isWithin(0.01).of(1.0)
// there should be less than 5% after DIA -1 // there should be less than 5% after DIA -1
Assertions.assertTrue(0.05 > bolus.iobCalc(activePlugin, now + T.hours(dia.toLong() - 1).msecs(), dia).iobContrib) assertThat(
bolus.iobCalc(activePlugin, now + T.hours(dia.toLong() - 1).msecs(), dia).iobContrib
).isLessThan(0.05)
// there should be zero after DIA // there should be zero after DIA
Assertions.assertEquals(0.0, bolus.iobCalc(activePlugin, now + T.hours(dia.toLong() + 1).msecs(), dia).iobContrib) assertThat(bolus.iobCalc(activePlugin, now + T.hours(dia.toLong() + 1).msecs(), dia).iobContrib).isEqualTo(0.0)
// no IOB for invalid record // no IOB for invalid record
bolus.isValid = false bolus.isValid = false
Assertions.assertEquals(0.0, bolus.iobCalc(activePlugin, now + T.hours(1).msecs(), dia).iobContrib) assertThat(bolus.iobCalc(activePlugin, now + T.hours(1).msecs(), dia).iobContrib).isEqualTo(0.0)
bolus.isValid = true bolus.isValid = true
bolus.type = Bolus.Type.PRIMING bolus.type = Bolus.Type.PRIMING
Assertions.assertEquals(0.0, bolus.iobCalc(activePlugin, now + T.hours(1).msecs(), dia).iobContrib) assertThat(bolus.iobCalc(activePlugin, now + T.hours(1).msecs(), dia).iobContrib).isEqualTo(0.0)
} }
} }

View file

@ -1,6 +1,7 @@
package info.nightscout.core.extensions package info.nightscout.core.extensions
import app.aaps.shared.tests.TestBaseWithProfile import app.aaps.shared.tests.TestBaseWithProfile
import com.google.common.truth.Truth.assertThat
import info.nightscout.database.entities.ExtendedBolus import info.nightscout.database.entities.ExtendedBolus
import info.nightscout.database.entities.TemporaryBasal import info.nightscout.database.entities.TemporaryBasal
import info.nightscout.insulin.InsulinLyumjevPlugin import info.nightscout.insulin.InsulinLyumjevPlugin
@ -10,7 +11,6 @@ import info.nightscout.interfaces.insulin.Insulin
import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.ui.UiInteraction
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.Mock import org.mockito.Mock
@ -25,72 +25,61 @@ class ExtendedBolusExtensionKtTest : TestBaseWithProfile() {
private val dia = 7.0 private val dia = 7.0
@BeforeEach @BeforeEach fun setup() {
fun setup() {
insulin = InsulinLyumjevPlugin(profileInjector, rh, profileFunctions, rxBus, aapsLogger, config, hardLimits, uiInteraction) insulin = InsulinLyumjevPlugin(profileInjector, rh, profileFunctions, rxBus, aapsLogger, config, hardLimits, uiInteraction)
Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin) Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin)
Mockito.`when`(dateUtil.now()).thenReturn(now) Mockito.`when`(dateUtil.now()).thenReturn(now)
} }
@Test @Test fun iobCalc() {
fun iobCalc() {
val bolus = ExtendedBolus(timestamp = now - 1, amount = 1.0, duration = T.hours(1).msecs()) val bolus = ExtendedBolus(timestamp = now - 1, amount = 1.0, duration = T.hours(1).msecs())
// there should zero IOB after now // there should zero IOB after now
Assertions.assertEquals(0.0, bolus.iobCalc(now, validProfile, insulin).iob, 0.01) assertThat(bolus.iobCalc(now, validProfile, insulin).iob).isWithin(0.01).of(0.0)
// there should be significant IOB at EB finish // there should be significant IOB at EB finish
Assertions.assertTrue(0.8 < bolus.iobCalc(now + T.hours(1).msecs(), validProfile, insulin).iob) assertThat(bolus.iobCalc(now + T.hours(1).msecs(), validProfile, insulin).iob).isGreaterThan(0.8)
// there should be less that 5% after DIA -1 // there should be less that 5% after DIA -1
Assertions.assertTrue(0.05 > bolus.iobCalc(now + T.hours(dia.toLong() - 1).msecs(), validProfile, insulin).iob) assertThat(bolus.iobCalc(now + T.hours(dia.toLong() - 1).msecs(), validProfile, insulin).iob).isLessThan(0.05)
// there should be zero after DIA // there should be zero after DIA
Assertions.assertEquals(0.0, bolus.iobCalc(now + T.hours(dia.toLong() + 1).msecs(), validProfile, insulin).iob) assertThat(bolus.iobCalc(now + T.hours(dia.toLong() + 1).msecs(), validProfile, insulin).iob).isEqualTo(0.0)
// no IOB for invalid record // no IOB for invalid record
bolus.isValid = false bolus.isValid = false
Assertions.assertEquals(0.0, bolus.iobCalc(now + T.hours(1).msecs(), validProfile, insulin).iob) assertThat(bolus.iobCalc(now + T.hours(1).msecs(), validProfile, insulin).iob).isEqualTo(0.0)
bolus.isValid = true bolus.isValid = true
val asResult = AutosensResult() val asResult = AutosensResult()
// there should zero IOB after now // there should zero IOB after now
Assertions.assertEquals(0.0, bolus.iobCalc(now, validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).iob, 0.01) assertThat(bolus.iobCalc(now, validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).iob).isWithin(0.01).of(0.0)
// there should be significant IOB at EB finish // there should be significant IOB at EB finish
Assertions.assertTrue(0.8 < bolus.iobCalc(now + T.hours(1).msecs(), validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).iob) assertThat(bolus.iobCalc(now + T.hours(1).msecs(), validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).iob).isGreaterThan(0.8)
// there should be less that 5% after DIA -1 // there should be less that 5% after DIA -1
Assertions.assertTrue( assertThat(
0.05 > bolus.iobCalc( bolus.iobCalc(
now + T.hours(dia.toLong() - 1).msecs(), now + T.hours(dia.toLong() - 1).msecs(), validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin
validProfile,
asResult,
SMBDefaults.exercise_mode,
SMBDefaults.half_basal_exercise_target,
true,
insulin
).iob ).iob
) ).isLessThan(0.05)
// there should be zero after DIA // there should be zero after DIA
Assertions.assertEquals( assertThat(
0.0,
bolus.iobCalc(now + T.hours(dia.toLong() + 1).msecs(), validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).iob bolus.iobCalc(now + T.hours(dia.toLong() + 1).msecs(), validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).iob
) ).isEqualTo(0.0)
// no IOB for invalid record // no IOB for invalid record
bolus.isValid = false bolus.isValid = false
Assertions.assertEquals(0.0, bolus.iobCalc(now + T.hours(1).msecs(), validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).iob) assertThat(bolus.iobCalc(now + T.hours(1).msecs(), validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).iob).isEqualTo(0.0)
} }
@Test @Test fun isInProgress() {
fun isInProgress() {
val bolus = ExtendedBolus(timestamp = now - 1, amount = 1.0, duration = T.hours(1).msecs()) val bolus = ExtendedBolus(timestamp = now - 1, amount = 1.0, duration = T.hours(1).msecs())
Mockito.`when`(dateUtil.now()).thenReturn(now) Mockito.`when`(dateUtil.now()).thenReturn(now)
Assertions.assertTrue(bolus.isInProgress(dateUtil)) assertThat(bolus.isInProgress(dateUtil)).isTrue()
Mockito.`when`(dateUtil.now()).thenReturn(now + T.hours(2).msecs()) Mockito.`when`(dateUtil.now()).thenReturn(now + T.hours(2).msecs())
Assertions.assertFalse(bolus.isInProgress(dateUtil)) assertThat(bolus.isInProgress(dateUtil)).isFalse()
} }
@Test @Test fun toTemporaryBasal() {
fun toTemporaryBasal() {
val bolus = ExtendedBolus(timestamp = now - 1, amount = 1.0, duration = T.hours(1).msecs()) val bolus = ExtendedBolus(timestamp = now - 1, amount = 1.0, duration = T.hours(1).msecs())
val tbr = bolus.toTemporaryBasal(validProfile) val tbr = bolus.toTemporaryBasal(validProfile)
Assertions.assertEquals(bolus.timestamp, tbr.timestamp) assertThat(tbr.timestamp).isEqualTo(bolus.timestamp)
Assertions.assertEquals(bolus.duration, tbr.duration) assertThat(tbr.duration).isEqualTo(bolus.duration)
Assertions.assertEquals(bolus.rate + validProfile.getBasal(now), tbr.rate) assertThat(tbr.rate).isEqualTo(bolus.rate + validProfile.getBasal(now))
Assertions.assertEquals(TemporaryBasal.Type.FAKE_EXTENDED, tbr.type) assertThat(tbr.type).isEqualTo(TemporaryBasal.Type.FAKE_EXTENDED)
} }
} }

View file

@ -1,11 +1,11 @@
package info.nightscout.core.extensions package info.nightscout.core.extensions
import app.aaps.shared.tests.TestBaseWithProfile import app.aaps.shared.tests.TestBaseWithProfile
import com.google.common.truth.Truth.assertThat
import info.nightscout.core.main.R import info.nightscout.core.main.R
import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.GlucoseValue
import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.iob.InMemoryGlucoseValue import info.nightscout.interfaces.iob.InMemoryGlucoseValue
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class GlucoseValueExtensionKtTest : TestBaseWithProfile() { class GlucoseValueExtensionKtTest : TestBaseWithProfile() {
@ -20,30 +20,30 @@ class GlucoseValueExtensionKtTest : TestBaseWithProfile() {
@Test @Test
fun inMemoryValueToUnits() { fun inMemoryValueToUnits() {
Assertions.assertEquals(100.0, inMemoryGlucoseValue.valueToUnits(GlucoseUnit.MGDL)) assertThat(inMemoryGlucoseValue.valueToUnits(GlucoseUnit.MGDL)).isEqualTo(100.0)
Assertions.assertEquals(5.55, inMemoryGlucoseValue.valueToUnits(GlucoseUnit.MMOL), 0.01) assertThat(inMemoryGlucoseValue.valueToUnits(GlucoseUnit.MMOL)).isWithin(0.01).of(5.55)
} }
@Test @Test
fun directionToIcon() { fun directionToIcon() {
Assertions.assertEquals(R.drawable.ic_flat, glucoseValue.trendArrow.directionToIcon()) assertThat(glucoseValue.trendArrow.directionToIcon()).isEqualTo(R.drawable.ic_flat)
glucoseValue.trendArrow = GlucoseValue.TrendArrow.NONE glucoseValue.trendArrow = GlucoseValue.TrendArrow.NONE
Assertions.assertEquals(R.drawable.ic_invalid, glucoseValue.trendArrow.directionToIcon()) assertThat(glucoseValue.trendArrow.directionToIcon()).isEqualTo(R.drawable.ic_invalid)
glucoseValue.trendArrow = GlucoseValue.TrendArrow.TRIPLE_DOWN glucoseValue.trendArrow = GlucoseValue.TrendArrow.TRIPLE_DOWN
Assertions.assertEquals(R.drawable.ic_invalid, glucoseValue.trendArrow.directionToIcon()) assertThat(glucoseValue.trendArrow.directionToIcon()).isEqualTo(R.drawable.ic_invalid)
glucoseValue.trendArrow = GlucoseValue.TrendArrow.TRIPLE_UP glucoseValue.trendArrow = GlucoseValue.TrendArrow.TRIPLE_UP
Assertions.assertEquals(R.drawable.ic_invalid, glucoseValue.trendArrow.directionToIcon()) assertThat(glucoseValue.trendArrow.directionToIcon()).isEqualTo(R.drawable.ic_invalid)
glucoseValue.trendArrow = GlucoseValue.TrendArrow.DOUBLE_DOWN glucoseValue.trendArrow = GlucoseValue.TrendArrow.DOUBLE_DOWN
Assertions.assertEquals(R.drawable.ic_doubledown, glucoseValue.trendArrow.directionToIcon()) assertThat(glucoseValue.trendArrow.directionToIcon()).isEqualTo(R.drawable.ic_doubledown)
glucoseValue.trendArrow = GlucoseValue.TrendArrow.SINGLE_DOWN glucoseValue.trendArrow = GlucoseValue.TrendArrow.SINGLE_DOWN
Assertions.assertEquals(R.drawable.ic_singledown, glucoseValue.trendArrow.directionToIcon()) assertThat(glucoseValue.trendArrow.directionToIcon()).isEqualTo(R.drawable.ic_singledown)
glucoseValue.trendArrow = GlucoseValue.TrendArrow.FORTY_FIVE_DOWN glucoseValue.trendArrow = GlucoseValue.TrendArrow.FORTY_FIVE_DOWN
Assertions.assertEquals(R.drawable.ic_fortyfivedown, glucoseValue.trendArrow.directionToIcon()) assertThat(glucoseValue.trendArrow.directionToIcon()).isEqualTo(R.drawable.ic_fortyfivedown)
glucoseValue.trendArrow = GlucoseValue.TrendArrow.FORTY_FIVE_UP glucoseValue.trendArrow = GlucoseValue.TrendArrow.FORTY_FIVE_UP
Assertions.assertEquals(R.drawable.ic_fortyfiveup, glucoseValue.trendArrow.directionToIcon()) assertThat(glucoseValue.trendArrow.directionToIcon()).isEqualTo(R.drawable.ic_fortyfiveup)
glucoseValue.trendArrow = GlucoseValue.TrendArrow.SINGLE_UP glucoseValue.trendArrow = GlucoseValue.TrendArrow.SINGLE_UP
Assertions.assertEquals(R.drawable.ic_singleup, glucoseValue.trendArrow.directionToIcon()) assertThat(glucoseValue.trendArrow.directionToIcon()).isEqualTo(R.drawable.ic_singleup)
glucoseValue.trendArrow = GlucoseValue.TrendArrow.DOUBLE_UP glucoseValue.trendArrow = GlucoseValue.TrendArrow.DOUBLE_UP
Assertions.assertEquals(R.drawable.ic_doubleup, glucoseValue.trendArrow.directionToIcon()) assertThat(glucoseValue.trendArrow.directionToIcon()).isEqualTo(R.drawable.ic_doubleup)
} }
} }

View file

@ -1,6 +1,7 @@
package info.nightscout.core.extensions package info.nightscout.core.extensions
import app.aaps.shared.tests.TestBaseWithProfile import app.aaps.shared.tests.TestBaseWithProfile
import com.google.common.truth.Truth.assertThat
import info.nightscout.database.entities.TemporaryBasal import info.nightscout.database.entities.TemporaryBasal
import info.nightscout.insulin.InsulinLyumjevPlugin import info.nightscout.insulin.InsulinLyumjevPlugin
import info.nightscout.interfaces.aps.AutosensResult import info.nightscout.interfaces.aps.AutosensResult
@ -9,7 +10,6 @@ import info.nightscout.interfaces.insulin.Insulin
import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.ui.UiInteraction
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.Mock import org.mockito.Mock
@ -35,26 +35,28 @@ class TemporaryBasalExtensionKtTest : TestBaseWithProfile() {
fun iobCalc() { fun iobCalc() {
val temporaryBasal = TemporaryBasal(timestamp = now - 1, rate = 200.0, isAbsolute = false, duration = T.hours(1).msecs(), type = TemporaryBasal.Type.NORMAL) val temporaryBasal = TemporaryBasal(timestamp = now - 1, rate = 200.0, isAbsolute = false, duration = T.hours(1).msecs(), type = TemporaryBasal.Type.NORMAL)
// there should zero IOB after now // there should zero IOB after now
Assertions.assertEquals(0.0, temporaryBasal.iobCalc(now, validProfile, insulin).basaliob, 0.01) assertThat(temporaryBasal.iobCalc(now, validProfile, insulin).basaliob).isWithin(0.01).of(0.0)
// there should be significant IOB at EB finish // there should be significant IOB at EB finish
Assertions.assertTrue(0.8 < temporaryBasal.iobCalc(now + T.hours(1).msecs(), validProfile, insulin).basaliob) assertThat(temporaryBasal.iobCalc(now + T.hours(1).msecs(), validProfile, insulin).basaliob).isGreaterThan(0.8)
// there should be less that 5% after DIA -1 // there should be less that 5% after DIA -1
Assertions.assertTrue(0.05 > temporaryBasal.iobCalc(now + T.hours(dia.toLong() - 1).msecs(), validProfile, insulin).basaliob) assertThat(temporaryBasal.iobCalc(now + T.hours(dia.toLong() - 1).msecs(), validProfile, insulin).basaliob).isLessThan(0.05)
// there should be zero after DIA // there should be zero after DIA
Assertions.assertEquals(0.0, temporaryBasal.iobCalc(now + T.hours(dia.toLong() + 1).msecs(), validProfile, insulin).basaliob) assertThat(temporaryBasal.iobCalc(now + T.hours(dia.toLong() + 1).msecs(), validProfile, insulin).basaliob).isEqualTo(0.0)
// no IOB for invalid record // no IOB for invalid record
temporaryBasal.isValid = false temporaryBasal.isValid = false
Assertions.assertEquals(0.0, temporaryBasal.iobCalc(now + T.hours(1).msecs(), validProfile, insulin).basaliob) assertThat(temporaryBasal.iobCalc(now + T.hours(1).msecs(), validProfile, insulin).basaliob).isEqualTo(0.0)
temporaryBasal.isValid = true temporaryBasal.isValid = true
val asResult = AutosensResult() val asResult = AutosensResult()
// there should zero IOB after now // there should zero IOB after now
Assertions.assertEquals(0.0, temporaryBasal.iobCalc(now, validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).basaliob, 0.01) assertThat(temporaryBasal.iobCalc(now, validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).basaliob).isWithin(0.01).of(0.0)
// there should be significant IOB at EB finish // there should be significant IOB at EB finish
Assertions.assertTrue(0.8 < temporaryBasal.iobCalc(now + T.hours(1).msecs(), validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).basaliob) assertThat(temporaryBasal.iobCalc(now + T.hours(1).msecs(), validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).basaliob).isGreaterThan(
0.8
)
// there should be less that 5% after DIA -1 // there should be less that 5% after DIA -1
Assertions.assertTrue( assertThat(
0.05 > temporaryBasal.iobCalc( temporaryBasal.iobCalc(
now + T.hours(dia.toLong() - 1).msecs(), now + T.hours(dia.toLong() - 1).msecs(),
validProfile, validProfile,
asResult, asResult,
@ -63,10 +65,9 @@ class TemporaryBasalExtensionKtTest : TestBaseWithProfile() {
true, true,
insulin insulin
).basaliob ).basaliob
) ).isLessThan(0.05)
// there should be zero after DIA // there should be zero after DIA
Assertions.assertEquals( assertThat(
0.0,
temporaryBasal.iobCalc( temporaryBasal.iobCalc(
now + T.hours(dia.toLong() + 1).msecs(), now + T.hours(dia.toLong() + 1).msecs(),
validProfile, validProfile,
@ -76,12 +77,11 @@ class TemporaryBasalExtensionKtTest : TestBaseWithProfile() {
true, true,
insulin insulin
).basaliob ).basaliob
) ).isEqualTo(0.0)
// no IOB for invalid record // no IOB for invalid record
temporaryBasal.isValid = false temporaryBasal.isValid = false
Assertions.assertEquals( assertThat(
0.0,
temporaryBasal.iobCalc(now + T.hours(1).msecs(), validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).basaliob temporaryBasal.iobCalc(now + T.hours(1).msecs(), validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin).basaliob
) ).isEqualTo(0.0)
} }
} }

View file

@ -1,9 +1,9 @@
package info.nightscout.core.extensions package info.nightscout.core.extensions
import app.aaps.shared.tests.TestBaseWithProfile import app.aaps.shared.tests.TestBaseWithProfile
import com.google.common.truth.Truth.assertThat
import info.nightscout.database.entities.TemporaryTarget import info.nightscout.database.entities.TemporaryTarget
import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.GlucoseUnit
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class TemporaryTargetExtensionKtTest : TestBaseWithProfile() { class TemporaryTargetExtensionKtTest : TestBaseWithProfile() {
@ -25,18 +25,18 @@ class TemporaryTargetExtensionKtTest : TestBaseWithProfile() {
@Test @Test
fun lowValueToUnitsToString() { fun lowValueToUnitsToString() {
Assertions.assertEquals("110", temporaryTarget.lowValueToUnitsToString(GlucoseUnit.MGDL, decimalFormatter)) assertThat(temporaryTarget.lowValueToUnitsToString(GlucoseUnit.MGDL, decimalFormatter)).isEqualTo("110")
Assertions.assertEquals("6.1", temporaryTarget.lowValueToUnitsToString(GlucoseUnit.MMOL, decimalFormatter)) assertThat(temporaryTarget.lowValueToUnitsToString(GlucoseUnit.MMOL, decimalFormatter)).isEqualTo("6.1")
} }
@Test @Test
fun highValueToUnitsToString() { fun highValueToUnitsToString() {
Assertions.assertEquals("120", temporaryTarget.highValueToUnitsToString(GlucoseUnit.MGDL, decimalFormatter)) assertThat(temporaryTarget.highValueToUnitsToString(GlucoseUnit.MGDL, decimalFormatter)).isEqualTo("120")
Assertions.assertEquals("6.7", temporaryTarget.highValueToUnitsToString(GlucoseUnit.MMOL, decimalFormatter)) assertThat(temporaryTarget.highValueToUnitsToString(GlucoseUnit.MMOL, decimalFormatter)).isEqualTo("6.7")
} }
@Test @Test
fun target() { fun target() {
Assertions.assertEquals(115.0, temporaryTarget.target()) assertThat(temporaryTarget.target()).isEqualTo(115.0)
} }
} }

View file

@ -1,10 +1,10 @@
package info.nightscout.core.extensions package info.nightscout.core.extensions
import app.aaps.shared.tests.TestBaseWithProfile import app.aaps.shared.tests.TestBaseWithProfile
import com.google.common.truth.Truth.assertThat
import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.entities.TherapyEvent
import info.nightscout.database.entities.embedments.InterfaceIDs import info.nightscout.database.entities.embedments.InterfaceIDs
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito import org.mockito.Mockito
@ -30,8 +30,8 @@ class TherapyEventExtensionKtTest : TestBaseWithProfile() {
) )
) )
Mockito.`when`(dateUtil.now()).thenReturn(now + T.mins(30).msecs()) Mockito.`when`(dateUtil.now()).thenReturn(now + T.mins(30).msecs())
Assertions.assertFalse(therapyEvent.isOlderThan(1.0, dateUtil)) assertThat(therapyEvent.isOlderThan(1.0, dateUtil)).isFalse()
Mockito.`when`(dateUtil.now()).thenReturn(now + T.hours(2).msecs()) Mockito.`when`(dateUtil.now()).thenReturn(now + T.hours(2).msecs())
Assertions.assertTrue(therapyEvent.isOlderThan(1.0, dateUtil)) assertThat(therapyEvent.isOlderThan(1.0, dateUtil)).isTrue()
} }
} }

View file

@ -1,6 +1,7 @@
package info.nightscout.plugins.general.smsCommunicator package info.nightscout.plugins.general.smsCommunicator
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.interfaces.Constants import info.nightscout.interfaces.Constants
@ -12,7 +13,6 @@ import info.nightscout.plugins.general.smsCommunicator.otp.OneTimePasswordValida
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.Mock import org.mockito.Mock
@ -61,26 +61,26 @@ class AuthRequestTest : TestBase() {
// Check if SMS requesting code is sent // Check if SMS requesting code is sent
var authRequest = AuthRequest(injector, requester, "Request text", "ABC", action) var authRequest = AuthRequest(injector, requester, "Request text", "ABC", action)
Assertions.assertEquals(sentSms!!.phoneNumber, "aNumber") assertThat(sentSms!!.phoneNumber).isEqualTo("aNumber")
Assertions.assertEquals(sentSms!!.text, "Request text") assertThat(sentSms!!.text).isEqualTo("Request text")
// wrong reply // wrong reply
actionCalled = false actionCalled = false
authRequest.action("EFG") authRequest.action("EFG")
Assertions.assertEquals(sentSms!!.phoneNumber, "aNumber") assertThat(sentSms!!.phoneNumber).isEqualTo("aNumber")
Assertions.assertEquals(sentSms!!.text, "Wrong code. Command cancelled.") assertThat(sentSms!!.text).isEqualTo("Wrong code. Command cancelled.")
Assertions.assertFalse(actionCalled) assertThat(actionCalled).isFalse()
// correct reply // correct reply
authRequest = AuthRequest(injector, requester, "Request text", "ABC", action) authRequest = AuthRequest(injector, requester, "Request text", "ABC", action)
actionCalled = false actionCalled = false
`when`(otp.checkOTP(anyObject())).thenReturn(OneTimePasswordValidationResult.OK) `when`(otp.checkOTP(anyObject())).thenReturn(OneTimePasswordValidationResult.OK)
authRequest.action("ABC") authRequest.action("ABC")
Assertions.assertTrue(actionCalled) assertThat(actionCalled).isTrue()
// second time action should not be called // second time action should not be called
actionCalled = false actionCalled = false
authRequest.action("ABC") authRequest.action("ABC")
Assertions.assertFalse(actionCalled) assertThat(actionCalled).isFalse()
// test timed out message // test timed out message
val now: Long = 10000 val now: Long = 10000
@ -89,6 +89,6 @@ class AuthRequestTest : TestBase() {
actionCalled = false actionCalled = false
`when`(dateUtil.now()).thenReturn(now + T.mins(Constants.SMS_CONFIRM_TIMEOUT).msecs() + 1) `when`(dateUtil.now()).thenReturn(now + T.mins(Constants.SMS_CONFIRM_TIMEOUT).msecs() + 1)
authRequest.action("ABC") authRequest.action("ABC")
Assertions.assertFalse(actionCalled) assertThat(actionCalled).isFalse()
} }
} }

View file

@ -1,6 +1,6 @@
package info.nightscout.plugins.general.smsCommunicator package info.nightscout.plugins.general.smsCommunicator
import org.junit.jupiter.api.Assertions import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class SmsActionTest { class SmsActionTest {
@ -13,49 +13,49 @@ class SmsActionTest {
} }
} }
smsAction.run() smsAction.run()
Assertions.assertEquals(result, "A") assertThat(result).isEqualTo("A")
smsAction = object : SmsAction(false, 1.0) { smsAction = object : SmsAction(false, 1.0) {
override fun run() { override fun run() {
result = "B" result = "B"
} }
} }
smsAction.run() smsAction.run()
Assertions.assertEquals(result, "B") assertThat(result).isEqualTo("B")
Assertions.assertEquals(smsAction.aDouble(), 1.0, 0.000001) assertThat(smsAction.aDouble()).isWithin(0.000001).of(1.0)
smsAction = object : SmsAction(false, 1.0, 2) { smsAction = object : SmsAction(false, 1.0, 2) {
override fun run() { override fun run() {
result = "C" result = "C"
} }
} }
smsAction.run() smsAction.run()
Assertions.assertEquals(result, "C") assertThat(result).isEqualTo("C")
Assertions.assertEquals(smsAction.aDouble(), 1.0, 0.000001) assertThat(smsAction.aDouble()).isWithin(0.000001).of(1.0)
Assertions.assertEquals(smsAction.secondInteger().toLong(), 2) assertThat(smsAction.secondInteger().toLong()).isEqualTo(2)
smsAction = object : SmsAction(false, "aString", 3) { smsAction = object : SmsAction(false, "aString", 3) {
override fun run() { override fun run() {
result = "D" result = "D"
} }
} }
smsAction.run() smsAction.run()
Assertions.assertEquals(result, "D") assertThat(result).isEqualTo("D")
Assertions.assertEquals(smsAction.aString(), "aString") assertThat(smsAction.aString()).isEqualTo("aString")
Assertions.assertEquals(smsAction.secondInteger().toLong(), 3) assertThat(smsAction.secondInteger().toLong()).isEqualTo(3)
smsAction = object : SmsAction(false, 4) { smsAction = object : SmsAction(false, 4) {
override fun run() { override fun run() {
result = "E" result = "E"
} }
} }
smsAction.run() smsAction.run()
Assertions.assertEquals(result, "E") assertThat(result).isEqualTo("E")
Assertions.assertEquals(smsAction.anInteger().toLong(), 4) assertThat(smsAction.anInteger().toLong()).isEqualTo(4)
smsAction = object : SmsAction(false, 5, 6) { smsAction = object : SmsAction(false, 5, 6) {
override fun run() { override fun run() {
result = "F" result = "F"
} }
} }
smsAction.run() smsAction.run()
Assertions.assertEquals(result, "F") assertThat(result).isEqualTo("F")
Assertions.assertEquals(smsAction.anInteger().toLong(), 5) assertThat(smsAction.anInteger().toLong()).isEqualTo(5)
Assertions.assertEquals(smsAction.secondInteger().toLong(), 6) assertThat(smsAction.secondInteger().toLong()).isEqualTo(6)
} }
} }

View file

@ -2,8 +2,8 @@ package info.nightscout.plugins.general.smsCommunicator
import android.telephony.SmsMessage import android.telephony.SmsMessage
import app.aaps.shared.tests.TestBase import app.aaps.shared.tests.TestBase
import com.google.common.truth.Truth.assertThat
import info.nightscout.interfaces.smsCommunicator.Sms import info.nightscout.interfaces.smsCommunicator.Sms
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -15,32 +15,32 @@ class SmsTest : TestBase() {
`when`(smsMessage.originatingAddress).thenReturn("aNumber") `when`(smsMessage.originatingAddress).thenReturn("aNumber")
`when`(smsMessage.messageBody).thenReturn("aBody") `when`(smsMessage.messageBody).thenReturn("aBody")
var sms = Sms(smsMessage) var sms = Sms(smsMessage)
Assertions.assertEquals(sms.phoneNumber, "aNumber") assertThat(sms.phoneNumber).isEqualTo("aNumber")
Assertions.assertEquals(sms.text, "aBody") assertThat(sms.text).isEqualTo("aBody")
Assertions.assertTrue(sms.received) assertThat(sms.received).isTrue()
sms = Sms("aNumber", "aBody") sms = Sms("aNumber", "aBody")
Assertions.assertEquals(sms.phoneNumber, "aNumber") assertThat(sms.phoneNumber).isEqualTo("aNumber")
Assertions.assertEquals(sms.text, "aBody") assertThat(sms.text).isEqualTo("aBody")
Assertions.assertTrue(sms.sent) assertThat(sms.sent).isTrue()
sms = Sms("aNumber", "U") sms = Sms("aNumber", "U")
Assertions.assertEquals(sms.phoneNumber, "aNumber") assertThat(sms.phoneNumber).isEqualTo("aNumber")
Assertions.assertEquals(sms.text, "U") assertThat(sms.text).isEqualTo("U")
Assertions.assertTrue(sms.sent) assertThat(sms.sent).isTrue()
Assertions.assertEquals(sms.toString(), "SMS from aNumber: U") assertThat(sms.toString()).isEqualTo("SMS from aNumber: U")
// copy constructor #1 // copy constructor #1
val sms2 = Sms(sms) val sms2 = Sms(sms)
Assertions.assertEquals(sms2.phoneNumber, "aNumber") assertThat(sms2.phoneNumber).isEqualTo("aNumber")
Assertions.assertEquals(sms2.text, "U") assertThat(sms2.text).isEqualTo("U")
Assertions.assertTrue(sms2.sent) assertThat(sms2.sent).isTrue()
Assertions.assertEquals(sms2.toString(), "SMS from aNumber: U") assertThat(sms2.toString()).isEqualTo("SMS from aNumber: U")
// copy constructor #2 // copy constructor #2
val sms3 = Sms(sms, "different") val sms3 = Sms(sms, "different")
Assertions.assertEquals(sms3.phoneNumber, "different") assertThat(sms3.phoneNumber).isEqualTo("different")
Assertions.assertEquals(sms3.text, "U") assertThat(sms3.text).isEqualTo("U")
Assertions.assertTrue(sms3.sent) assertThat(sms3.sent).isTrue()
Assertions.assertEquals(sms3.toString(), "SMS from different: U") assertThat(sms3.toString()).isEqualTo("SMS from different: U")
} }
} }

View file

@ -4,6 +4,7 @@ import android.content.Context
import androidx.collection.LongSparseArray import androidx.collection.LongSparseArray
import app.aaps.shared.impl.utils.DateUtilImpl import app.aaps.shared.impl.utils.DateUtilImpl
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.database.entities.GlucoseValue import info.nightscout.database.entities.GlucoseValue
@ -15,7 +16,6 @@ import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
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.Mock import org.mockito.Mock
@ -97,7 +97,7 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(true, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isTrue()
// too much shifted data should return false // too much shifted data should return false
bgReadingList.clear() bgReadingList.clear()
@ -142,7 +142,7 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(false, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isFalse()
// too much shifted and missing data should return false // too much shifted and missing data should return false
bgReadingList.clear() bgReadingList.clear()
@ -177,7 +177,7 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(false, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isFalse()
// too much shifted and missing data should return false // too much shifted and missing data should return false
bgReadingList.clear() bgReadingList.clear()
@ -322,7 +322,7 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(false, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isFalse()
// slightly shifted data should return true // slightly shifted data should return true
bgReadingList.clear() bgReadingList.clear()
@ -367,7 +367,7 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(true, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isTrue()
// slightly shifted and missing data should return true // slightly shifted and missing data should return true
bgReadingList.clear() bgReadingList.clear()
@ -402,7 +402,7 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(true, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isTrue()
} }
@Test @Test
@ -452,11 +452,11 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(true, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isTrue()
autosensDataStore.createBucketedData(aapsLogger, dateUtil) autosensDataStore.createBucketedData(aapsLogger, dateUtil)
Assertions.assertEquals(bgReadingList[0].timestamp, autosensDataStore.bucketedData!![0].timestamp) assertThat(autosensDataStore.bucketedData!![0].timestamp).isEqualTo(bgReadingList[0].timestamp)
Assertions.assertEquals(bgReadingList[3].timestamp, autosensDataStore.bucketedData!![3].timestamp) assertThat(autosensDataStore.bucketedData!![3].timestamp).isEqualTo(bgReadingList[3].timestamp)
Assertions.assertEquals(bgReadingList.size.toLong(), autosensDataStore.bucketedData!!.size.toLong()) assertThat(autosensDataStore.bucketedData!!).hasSize(bgReadingList.size)
// Missing value should be replaced // Missing value should be replaced
bgReadingList.clear() bgReadingList.clear()
@ -491,11 +491,11 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(true, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isTrue()
autosensDataStore.createBucketedData(aapsLogger, dateUtil) autosensDataStore.createBucketedData(aapsLogger, dateUtil)
Assertions.assertEquals(bgReadingList[0].timestamp, autosensDataStore.bucketedData!![0].timestamp) assertThat(autosensDataStore.bucketedData!![0].timestamp).isEqualTo(bgReadingList[0].timestamp)
Assertions.assertEquals(bgReadingList[2].timestamp, autosensDataStore.bucketedData!![3].timestamp) assertThat(autosensDataStore.bucketedData!![3].timestamp).isEqualTo(bgReadingList[2].timestamp)
Assertions.assertEquals(bgReadingList.size + 1.toLong(), autosensDataStore.bucketedData!!.size.toLong()) assertThat(autosensDataStore.bucketedData!!).hasSize(bgReadingList.size + 1)
// drift should be cleared // drift should be cleared
bgReadingList.clear() bgReadingList.clear()
@ -550,13 +550,13 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(true, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isTrue()
autosensDataStore.createBucketedData(aapsLogger, dateUtil) autosensDataStore.createBucketedData(aapsLogger, dateUtil)
Assertions.assertEquals(T.mins(20).msecs(), autosensDataStore.bucketedData!![0].timestamp) assertThat(autosensDataStore.bucketedData!![0].timestamp).isEqualTo(T.mins(20).msecs())
Assertions.assertEquals(T.mins(15).msecs(), autosensDataStore.bucketedData!![1].timestamp) assertThat(autosensDataStore.bucketedData!![1].timestamp).isEqualTo(T.mins(15).msecs())
Assertions.assertEquals(T.mins(10).msecs(), autosensDataStore.bucketedData!![2].timestamp) assertThat(autosensDataStore.bucketedData!![2].timestamp).isEqualTo(T.mins(10).msecs())
Assertions.assertEquals(T.mins(5).msecs(), autosensDataStore.bucketedData!![3].timestamp) assertThat(autosensDataStore.bucketedData!![3].timestamp).isEqualTo(T.mins(5).msecs())
Assertions.assertEquals(bgReadingList.size.toLong(), autosensDataStore.bucketedData!!.size.toLong()) assertThat(autosensDataStore.bucketedData!!).hasSize(bgReadingList.size)
// bucketed data should return null if not enough bg data // bucketed data should return null if not enough bg data
bgReadingList.clear() bgReadingList.clear()
@ -581,9 +581,9 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(true, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isTrue()
autosensDataStore.createBucketedData(aapsLogger, dateUtil) autosensDataStore.createBucketedData(aapsLogger, dateUtil)
Assertions.assertEquals(null, autosensDataStore.bucketedData) assertThat(autosensDataStore.bucketedData).isNull()
// data should be reconstructed // data should be reconstructed
bgReadingList.clear() bgReadingList.clear()
@ -618,15 +618,15 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(true, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isTrue()
autosensDataStore.createBucketedData(aapsLogger, dateUtil) autosensDataStore.createBucketedData(aapsLogger, dateUtil)
Assertions.assertEquals(T.mins(50).msecs(), autosensDataStore.bucketedData!![0].timestamp) assertThat(autosensDataStore.bucketedData!![0].timestamp).isEqualTo(T.mins(50).msecs())
Assertions.assertEquals(T.mins(20).msecs(), autosensDataStore.bucketedData!![6].timestamp) assertThat(autosensDataStore.bucketedData!![6].timestamp).isEqualTo(T.mins(20).msecs())
Assertions.assertEquals(7, autosensDataStore.bucketedData!!.size.toLong()) assertThat(autosensDataStore.bucketedData!!).hasSize(7)
Assertions.assertEquals(100.0, autosensDataStore.bucketedData!![0].value, 1.0) assertThat(autosensDataStore.bucketedData!![0].value).isWithin(1.0).of(100.0)
Assertions.assertEquals(90.0, autosensDataStore.bucketedData!![1].value, 1.0) assertThat(autosensDataStore.bucketedData!![1].value).isWithin(1.0).of(90.0)
Assertions.assertEquals(50.0, autosensDataStore.bucketedData!![5].value, 1.0) assertThat(autosensDataStore.bucketedData!![5].value).isWithin(1.0).of(50.0)
Assertions.assertEquals(40.0, autosensDataStore.bucketedData!![6].value, 1.0) assertThat(autosensDataStore.bucketedData!![6].value).isWithin(1.0).of(40.0)
// non 5min data should be reconstructed // non 5min data should be reconstructed
bgReadingList.clear() bgReadingList.clear()
@ -661,15 +661,15 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(false, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isFalse()
autosensDataStore.createBucketedData(aapsLogger, dateUtil) autosensDataStore.createBucketedData(aapsLogger, dateUtil)
Assertions.assertEquals(T.mins(50).msecs(), autosensDataStore.bucketedData!![0].timestamp) assertThat(autosensDataStore.bucketedData!![0].timestamp).isEqualTo(T.mins(50).msecs())
Assertions.assertEquals(T.mins(20).msecs(), autosensDataStore.bucketedData!![6].timestamp) assertThat(autosensDataStore.bucketedData!![6].timestamp).isEqualTo(T.mins(20).msecs())
Assertions.assertEquals(7, autosensDataStore.bucketedData!!.size.toLong()) assertThat(autosensDataStore.bucketedData!!).hasSize(7)
Assertions.assertEquals(100.0, autosensDataStore.bucketedData!![0].value, 1.0) assertThat(autosensDataStore.bucketedData!![0].value).isWithin(1.0).of(100.0)
Assertions.assertEquals(90.0, autosensDataStore.bucketedData!![1].value, 1.0) assertThat(autosensDataStore.bucketedData!![1].value).isWithin(1.0).of(90.0)
Assertions.assertEquals(50.0, autosensDataStore.bucketedData!![5].value, 1.0) assertThat(autosensDataStore.bucketedData!![5].value).isWithin(1.0).of(50.0)
Assertions.assertEquals(40.0, autosensDataStore.bucketedData!![6].value, 1.0) assertThat(autosensDataStore.bucketedData!![6].value).isWithin(1.0).of(40.0)
} }
@Test @Test
@ -679,7 +679,7 @@ class AutosensDataStoreTest : TestBase() {
//bucketed data should be null if no bg data available //bucketed data should be null if no bg data available
autosensDataStore.bgReadings = ArrayList() autosensDataStore.bgReadings = ArrayList()
autosensDataStore.createBucketedData(aapsLogger, dateUtil) autosensDataStore.createBucketedData(aapsLogger, dateUtil)
Assertions.assertEquals(null, autosensDataStore.bucketedData) assertThat(autosensDataStore.bucketedData).isNull()
// real data gap test // real data gap test
bgReadingList.clear() bgReadingList.clear()
@ -956,10 +956,10 @@ class AutosensDataStoreTest : TestBase() {
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
autosensDataStore.referenceTime = -1 autosensDataStore.referenceTime = -1
Assertions.assertEquals(true, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isTrue()
autosensDataStore.createBucketedData(aapsLogger, dateUtil) autosensDataStore.createBucketedData(aapsLogger, dateUtil)
Assertions.assertEquals(dateUtil.fromISODateString("2018-09-05T13:34:57Z"), autosensDataStore.bucketedData!![0].timestamp) assertThat(autosensDataStore.bucketedData!![0].timestamp).isEqualTo(dateUtil.fromISODateString("2018-09-05T13:34:57Z"))
Assertions.assertEquals(dateUtil.fromISODateString("2018-09-05T03:44:57Z"), autosensDataStore.bucketedData!![autosensDataStore.bucketedData!!.size - 1].timestamp) assertThat(autosensDataStore.bucketedData!!.last().timestamp).isEqualTo(dateUtil.fromISODateString("2018-09-05T03:44:57Z"))
// 5min 4sec data // 5min 4sec data
bgReadingList.clear() bgReadingList.clear()
@ -1174,7 +1174,7 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(false, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isFalse()
} }
@Test @Test
@ -1225,16 +1225,16 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(false, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isFalse()
autosensDataStore.createBucketedData(aapsLogger, dateUtil) autosensDataStore.createBucketedData(aapsLogger, dateUtil)
Assertions.assertEquals(T.mins(45).msecs(), autosensDataStore.bucketedData!![0].timestamp) assertThat(autosensDataStore.bucketedData!![0].timestamp).isEqualTo(T.mins(45).msecs())
Assertions.assertEquals(T.mins(35).msecs(), autosensDataStore.bucketedData!![2].timestamp) assertThat(autosensDataStore.bucketedData!![2].timestamp).isEqualTo(T.mins(35).msecs())
Assertions.assertEquals(T.mins(20).msecs(), autosensDataStore.bucketedData!![5].timestamp) assertThat(autosensDataStore.bucketedData!![5].timestamp).isEqualTo(T.mins(20).msecs())
Assertions.assertEquals(6, autosensDataStore.bucketedData!!.size.toLong()) assertThat(autosensDataStore.bucketedData!!).hasSize(6)
Assertions.assertEquals(99.0, autosensDataStore.bucketedData!![0].value, 1.0) // Recalculated data to 45min assertThat(autosensDataStore.bucketedData!![0].value).isWithin(1.0).of(99.0) // Recalculated data to 45min
Assertions.assertEquals(90.0, autosensDataStore.bucketedData!![1].value, 1.0) // Recalculated data to 40min assertThat(autosensDataStore.bucketedData!![1].value).isWithin(1.0).of(90.0) // Recalculated data to 40min
Assertions.assertEquals(67.0, autosensDataStore.bucketedData!![3].value, 1.0) // Recalculated data to 30min assertThat(autosensDataStore.bucketedData!![3].value).isWithin(1.0).of(67.0) // Recalculated data to 30min
Assertions.assertEquals(45.0, autosensDataStore.bucketedData!![5].value, 1.0) // Recalculated data to 20min assertThat(autosensDataStore.bucketedData!![5].value).isWithin(1.0).of(45.0) // Recalculated data to 20min
// non 5min data not aligned to referenceTime should be recalculated to referenceTime // non 5min data not aligned to referenceTime should be recalculated to referenceTime
autosensDataStore.referenceTime = T.mins(5).msecs() autosensDataStore.referenceTime = T.mins(5).msecs()
@ -1280,16 +1280,16 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(false, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isFalse()
autosensDataStore.createBucketedData(aapsLogger, dateUtil) autosensDataStore.createBucketedData(aapsLogger, dateUtil)
Assertions.assertEquals(T.mins(45).msecs(), autosensDataStore.bucketedData!![0].timestamp) assertThat(autosensDataStore.bucketedData!![0].timestamp).isEqualTo(T.mins(45).msecs())
Assertions.assertEquals(T.mins(35).msecs(), autosensDataStore.bucketedData!![2].timestamp) assertThat(autosensDataStore.bucketedData!![2].timestamp).isEqualTo(T.mins(35).msecs())
Assertions.assertEquals(T.mins(20).msecs(), autosensDataStore.bucketedData!![5].timestamp) assertThat(autosensDataStore.bucketedData!![5].timestamp).isEqualTo(T.mins(20).msecs())
Assertions.assertEquals(6, autosensDataStore.bucketedData!!.size.toLong()) assertThat(autosensDataStore.bucketedData!!).hasSize(6)
Assertions.assertEquals(99.0, autosensDataStore.bucketedData!![0].value, 1.0) // Recalculated data to 45min assertThat(autosensDataStore.bucketedData!![0].value).isWithin(1.0).of(99.0) // Recalculated data to 45min
Assertions.assertEquals(90.0, autosensDataStore.bucketedData!![1].value, 1.0) // Recalculated data to 40min assertThat(autosensDataStore.bucketedData!![1].value).isWithin(1.0).of(90.0) // Recalculated data to 40min
Assertions.assertEquals(67.0, autosensDataStore.bucketedData!![3].value, 1.0) // Recalculated data to 30min assertThat(autosensDataStore.bucketedData!![3].value).isWithin(1.0).of(67.0) // Recalculated data to 30min
Assertions.assertEquals(45.0, autosensDataStore.bucketedData!![5].value, 1.0) // Recalculated data to 20min assertThat(autosensDataStore.bucketedData!![5].value).isWithin(1.0).of(45.0) // Recalculated data to 20min
// non 5min data without referenceTime set, should align the data to the time of the last reading // non 5min data without referenceTime set, should align the data to the time of the last reading
autosensDataStore.referenceTime = -1 autosensDataStore.referenceTime = -1
@ -1335,29 +1335,29 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(false, autosensDataStore.isAbout5minData(aapsLogger)) assertThat(autosensDataStore.isAbout5minData(aapsLogger)).isFalse()
autosensDataStore.createBucketedData(aapsLogger, dateUtil) autosensDataStore.createBucketedData(aapsLogger, dateUtil)
Assertions.assertEquals(T.mins(48).msecs(), autosensDataStore.bucketedData!![0].timestamp) assertThat(autosensDataStore.bucketedData!![0].timestamp).isEqualTo(T.mins(48).msecs())
Assertions.assertEquals(T.mins(43).msecs(), autosensDataStore.bucketedData!![1].timestamp) assertThat(autosensDataStore.bucketedData!![1].timestamp).isEqualTo(T.mins(43).msecs())
Assertions.assertEquals(T.mins(33).msecs(), autosensDataStore.bucketedData!![3].timestamp) assertThat(autosensDataStore.bucketedData!![3].timestamp).isEqualTo(T.mins(33).msecs())
Assertions.assertEquals(T.mins(18).msecs(), autosensDataStore.bucketedData!![6].timestamp) assertThat(autosensDataStore.bucketedData!![6].timestamp).isEqualTo(T.mins(18).msecs())
Assertions.assertEquals(7, autosensDataStore.bucketedData!!.size.toLong()) assertThat(autosensDataStore.bucketedData!!).hasSize(7)
Assertions.assertEquals(100.0, autosensDataStore.bucketedData!![0].value, 1.0) // Recalculated data to 48min assertThat(autosensDataStore.bucketedData!![0].value).isWithin(1.0).of(100.0) // Recalculated data to 48min
Assertions.assertEquals(98.0, autosensDataStore.bucketedData!![1].value, 1.0) // Recalculated data to 43min assertThat(autosensDataStore.bucketedData!![1].value).isWithin(1.0).of(98.0) // Recalculated data to 43min
Assertions.assertEquals(74.0, autosensDataStore.bucketedData!![3].value, 1.0) // Recalculated data to 33min assertThat(autosensDataStore.bucketedData!![3].value).isWithin(1.0).of(74.0) // Recalculated data to 33min
Assertions.assertEquals(40.0, autosensDataStore.bucketedData!![6].value, 1.0) // Recalculated data to 18min assertThat(autosensDataStore.bucketedData!![6].value).isWithin(1.0).of(40.0) // Recalculated data to 18min
} }
@Test @Test
fun bgReadingsTest() { fun bgReadingsTest() {
val bgReadingList: List<GlucoseValue> = ArrayList() val bgReadingList: List<GlucoseValue> = ArrayList()
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(bgReadingList, autosensDataStore.bgReadings) assertThat(autosensDataStore.bgReadings).isEmpty()
} }
@Test @Test
fun roundUpTimeTest() { fun roundUpTimeTest() {
Assertions.assertEquals(T.mins(3).msecs(), autosensDataStore.roundUpTime(T.secs(155).msecs())) assertThat(autosensDataStore.roundUpTime(T.secs(155).msecs())).isEqualTo(T.mins(3).msecs())
} }
@Test @Test
@ -1404,11 +1404,11 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(T.mins(10).msecs(), autosensDataStore.findNewer(T.mins(8).msecs())!!.timestamp) assertThat(autosensDataStore.findNewer(T.mins(8).msecs())!!.timestamp).isEqualTo(T.mins(10).msecs())
Assertions.assertEquals(T.mins(5).msecs(), autosensDataStore.findNewer(T.mins(5).msecs())!!.timestamp) assertThat(autosensDataStore.findNewer(T.mins(5).msecs())!!.timestamp).isEqualTo(T.mins(5).msecs())
Assertions.assertEquals(T.mins(10).msecs(), autosensDataStore.findNewer(T.mins(10).msecs())!!.timestamp) assertThat(autosensDataStore.findNewer(T.mins(10).msecs())!!.timestamp).isEqualTo(T.mins(10).msecs())
Assertions.assertEquals(T.mins(20).msecs(), autosensDataStore.findNewer(T.mins(20).msecs())!!.timestamp) assertThat(autosensDataStore.findNewer(T.mins(20).msecs())!!.timestamp).isEqualTo(T.mins(20).msecs())
Assertions.assertEquals(null, autosensDataStore.findNewer(T.mins(22).msecs())) assertThat(autosensDataStore.findNewer(T.mins(22).msecs())).isNull()
} }
@Test @Test
@ -1455,11 +1455,11 @@ class AutosensDataStoreTest : TestBase() {
) )
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
Assertions.assertEquals(T.mins(5).msecs(), autosensDataStore.findOlder(T.mins(8).msecs())!!.timestamp) assertThat(autosensDataStore.findOlder(T.mins(8).msecs())!!.timestamp).isEqualTo(T.mins(5).msecs())
Assertions.assertEquals(T.mins(5).msecs(), autosensDataStore.findOlder(T.mins(5).msecs())!!.timestamp) assertThat(autosensDataStore.findOlder(T.mins(5).msecs())!!.timestamp).isEqualTo(T.mins(5).msecs())
Assertions.assertEquals(T.mins(10).msecs(), autosensDataStore.findOlder(T.mins(10).msecs())!!.timestamp) assertThat(autosensDataStore.findOlder(T.mins(10).msecs())!!.timestamp).isEqualTo(T.mins(10).msecs())
Assertions.assertEquals(T.mins(20).msecs(), autosensDataStore.findOlder(T.mins(20).msecs())!!.timestamp) assertThat(autosensDataStore.findOlder(T.mins(20).msecs())!!.timestamp).isEqualTo(T.mins(20).msecs())
Assertions.assertEquals(null, autosensDataStore.findOlder(T.mins(4).msecs())) assertThat(autosensDataStore.findOlder(T.mins(4).msecs())).isNull()
} }
@Test @Test
@ -1467,7 +1467,7 @@ class AutosensDataStoreTest : TestBase() {
val bgReadingList: MutableList<GlucoseValue> = ArrayList() val bgReadingList: MutableList<GlucoseValue> = ArrayList()
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
autosensDataStore.createBucketedData(aapsLogger, dateUtil) autosensDataStore.createBucketedData(aapsLogger, dateUtil)
Assertions.assertEquals(null, autosensDataStore.findPreviousTimeFromBucketedData(1000)) assertThat(autosensDataStore.findPreviousTimeFromBucketedData(1000)).isNull()
// Super data should not be touched // Super data should not be touched
bgReadingList.clear() bgReadingList.clear()
@ -1513,10 +1513,10 @@ class AutosensDataStoreTest : TestBase() {
) )
autosensDataStore.bgReadings = bgReadingList autosensDataStore.bgReadings = bgReadingList
autosensDataStore.createBucketedData(aapsLogger, dateUtil) autosensDataStore.createBucketedData(aapsLogger, dateUtil)
Assertions.assertEquals(null, autosensDataStore.findPreviousTimeFromBucketedData(T.mins(4).msecs())) assertThat(autosensDataStore.findPreviousTimeFromBucketedData(T.mins(4).msecs())).isNull()
Assertions.assertEquals(T.mins(5).msecs(), autosensDataStore.findPreviousTimeFromBucketedData(T.mins(6).msecs())) assertThat(autosensDataStore.findPreviousTimeFromBucketedData(T.mins(6).msecs())).isEqualTo(T.mins(5).msecs())
Assertions.assertEquals(T.mins(20).msecs(), autosensDataStore.findPreviousTimeFromBucketedData(T.mins(20).msecs())) assertThat(autosensDataStore.findPreviousTimeFromBucketedData(T.mins(20).msecs())).isEqualTo(T.mins(20).msecs())
Assertions.assertEquals(T.mins(20).msecs(), autosensDataStore.findPreviousTimeFromBucketedData(T.mins(25).msecs())) assertThat(autosensDataStore.findPreviousTimeFromBucketedData(T.mins(25).msecs())).isEqualTo(T.mins(20).msecs())
} }
@Test @Test
@ -1527,18 +1527,18 @@ class AutosensDataStoreTest : TestBase() {
ads.storedLastAutosensResult = AutosensDataObject(injector).apply { time = now - 10 } ads.storedLastAutosensResult = AutosensDataObject(injector).apply { time = now - 10 }
// empty array, return last stored // empty array, return last stored
ads.autosensDataTable = LongSparseArray<AutosensData>() ads.autosensDataTable = LongSparseArray<AutosensData>()
Assertions.assertEquals(now - 10, ads.getLastAutosensData("test", aapsLogger, dateUtilMocked)?.time) assertThat(ads.getLastAutosensData("test", aapsLogger, dateUtilMocked)?.time).isEqualTo(now - 10)
// data is there, return it // data is there, return it
ads.autosensDataTable.append(now - 1, AutosensDataObject(injector).apply { time = now - 1 }) ads.autosensDataTable.append(now - 1, AutosensDataObject(injector).apply { time = now - 1 })
Assertions.assertEquals(now - 1, ads.getLastAutosensData("test", aapsLogger, dateUtilMocked)?.time) assertThat(ads.getLastAutosensData("test", aapsLogger, dateUtilMocked)?.time).isEqualTo(now - 1)
// and latest value should be saved // and latest value should be saved
Assertions.assertEquals(now - 1, ads.storedLastAutosensResult?.time) assertThat(ads.storedLastAutosensResult?.time).isEqualTo(now - 1)
// data is old, return last stored // data is old, return last stored
ads.storedLastAutosensResult = AutosensDataObject(injector).apply { time = now - 1 } ads.storedLastAutosensResult = AutosensDataObject(injector).apply { time = now - 1 }
ads.autosensDataTable = LongSparseArray<AutosensData>() ads.autosensDataTable = LongSparseArray<AutosensData>()
ads.autosensDataTable.append(now - T.mins(20).msecs(), AutosensDataObject(injector).apply { time = now - T.mins(20).msecs() }) ads.autosensDataTable.append(now - T.mins(20).msecs(), AutosensDataObject(injector).apply { time = now - T.mins(20).msecs() })
Assertions.assertEquals(now - 1, ads.getLastAutosensData("test", aapsLogger, dateUtilMocked)?.time) assertThat(ads.getLastAutosensData("test", aapsLogger, dateUtilMocked)?.time).isEqualTo(now - 1)
} }
} }