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
import app.aaps.shared.tests.TestBaseWithProfile
import com.google.common.truth.Truth.assertThat
import info.nightscout.database.entities.Bolus
import info.nightscout.insulin.InsulinLyumjevPlugin
import info.nightscout.interfaces.insulin.Insulin
import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.shared.utils.T
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mock
@ -22,26 +22,26 @@ class BolusExtensionKtTest : TestBaseWithProfile() {
private val dia = 7.0
@BeforeEach
fun setup() {
@BeforeEach fun setup() {
insulin = InsulinLyumjevPlugin(profileInjector, rh, profileFunctions, rxBus, aapsLogger, config, hardLimits, uiInteraction)
Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin)
}
@Test
fun iobCalc() {
@Test fun iobCalc() {
val bolus = Bolus(timestamp = now - 1, amount = 1.0, type = Bolus.Type.NORMAL)
// 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
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
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
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.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
import app.aaps.shared.tests.TestBaseWithProfile
import com.google.common.truth.Truth.assertThat
import info.nightscout.database.entities.ExtendedBolus
import info.nightscout.database.entities.TemporaryBasal
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.ui.UiInteraction
import info.nightscout.shared.utils.T
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mock
@ -25,72 +25,61 @@ class ExtendedBolusExtensionKtTest : TestBaseWithProfile() {
private val dia = 7.0
@BeforeEach
fun setup() {
@BeforeEach fun setup() {
insulin = InsulinLyumjevPlugin(profileInjector, rh, profileFunctions, rxBus, aapsLogger, config, hardLimits, uiInteraction)
Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin)
Mockito.`when`(dateUtil.now()).thenReturn(now)
}
@Test
fun iobCalc() {
@Test fun iobCalc() {
val bolus = ExtendedBolus(timestamp = now - 1, amount = 1.0, duration = T.hours(1).msecs())
// 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
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
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
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
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
val asResult = AutosensResult()
// 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
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
Assertions.assertTrue(
0.05 > bolus.iobCalc(
now + T.hours(dia.toLong() - 1).msecs(),
validProfile,
asResult,
SMBDefaults.exercise_mode,
SMBDefaults.half_basal_exercise_target,
true,
insulin
assertThat(
bolus.iobCalc(
now + T.hours(dia.toLong() - 1).msecs(), validProfile, asResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, true, insulin
).iob
)
).isLessThan(0.05)
// there should be zero after DIA
Assertions.assertEquals(
0.0,
assertThat(
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
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
fun isInProgress() {
@Test fun isInProgress() {
val bolus = ExtendedBolus(timestamp = now - 1, amount = 1.0, duration = T.hours(1).msecs())
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())
Assertions.assertFalse(bolus.isInProgress(dateUtil))
assertThat(bolus.isInProgress(dateUtil)).isFalse()
}
@Test
fun toTemporaryBasal() {
@Test fun toTemporaryBasal() {
val bolus = ExtendedBolus(timestamp = now - 1, amount = 1.0, duration = T.hours(1).msecs())
val tbr = bolus.toTemporaryBasal(validProfile)
Assertions.assertEquals(bolus.timestamp, tbr.timestamp)
Assertions.assertEquals(bolus.duration, tbr.duration)
Assertions.assertEquals(bolus.rate + validProfile.getBasal(now), tbr.rate)
Assertions.assertEquals(TemporaryBasal.Type.FAKE_EXTENDED, tbr.type)
assertThat(tbr.timestamp).isEqualTo(bolus.timestamp)
assertThat(tbr.duration).isEqualTo(bolus.duration)
assertThat(tbr.rate).isEqualTo(bolus.rate + validProfile.getBasal(now))
assertThat(tbr.type).isEqualTo(TemporaryBasal.Type.FAKE_EXTENDED)
}
}

View file

@ -1,11 +1,11 @@
package info.nightscout.core.extensions
import app.aaps.shared.tests.TestBaseWithProfile
import com.google.common.truth.Truth.assertThat
import info.nightscout.core.main.R
import info.nightscout.database.entities.GlucoseValue
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.iob.InMemoryGlucoseValue
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class GlucoseValueExtensionKtTest : TestBaseWithProfile() {
@ -20,30 +20,30 @@ class GlucoseValueExtensionKtTest : TestBaseWithProfile() {
@Test
fun inMemoryValueToUnits() {
Assertions.assertEquals(100.0, inMemoryGlucoseValue.valueToUnits(GlucoseUnit.MGDL))
Assertions.assertEquals(5.55, inMemoryGlucoseValue.valueToUnits(GlucoseUnit.MMOL), 0.01)
assertThat(inMemoryGlucoseValue.valueToUnits(GlucoseUnit.MGDL)).isEqualTo(100.0)
assertThat(inMemoryGlucoseValue.valueToUnits(GlucoseUnit.MMOL)).isWithin(0.01).of(5.55)
}
@Test
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
Assertions.assertEquals(R.drawable.ic_invalid, glucoseValue.trendArrow.directionToIcon())
assertThat(glucoseValue.trendArrow.directionToIcon()).isEqualTo(R.drawable.ic_invalid)
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
Assertions.assertEquals(R.drawable.ic_invalid, glucoseValue.trendArrow.directionToIcon())
assertThat(glucoseValue.trendArrow.directionToIcon()).isEqualTo(R.drawable.ic_invalid)
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
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
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
Assertions.assertEquals(R.drawable.ic_fortyfiveup, glucoseValue.trendArrow.directionToIcon())
assertThat(glucoseValue.trendArrow.directionToIcon()).isEqualTo(R.drawable.ic_fortyfiveup)
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
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
import app.aaps.shared.tests.TestBaseWithProfile
import com.google.common.truth.Truth.assertThat
import info.nightscout.database.entities.TemporaryBasal
import info.nightscout.insulin.InsulinLyumjevPlugin
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.ui.UiInteraction
import info.nightscout.shared.utils.T
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mock
@ -35,26 +35,28 @@ class TemporaryBasalExtensionKtTest : TestBaseWithProfile() {
fun iobCalc() {
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
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
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
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
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
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
val asResult = AutosensResult()
// 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
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
Assertions.assertTrue(
0.05 > temporaryBasal.iobCalc(
assertThat(
temporaryBasal.iobCalc(
now + T.hours(dia.toLong() - 1).msecs(),
validProfile,
asResult,
@ -63,10 +65,9 @@ class TemporaryBasalExtensionKtTest : TestBaseWithProfile() {
true,
insulin
).basaliob
)
).isLessThan(0.05)
// there should be zero after DIA
Assertions.assertEquals(
0.0,
assertThat(
temporaryBasal.iobCalc(
now + T.hours(dia.toLong() + 1).msecs(),
validProfile,
@ -76,12 +77,11 @@ class TemporaryBasalExtensionKtTest : TestBaseWithProfile() {
true,
insulin
).basaliob
)
).isEqualTo(0.0)
// no IOB for invalid record
temporaryBasal.isValid = false
Assertions.assertEquals(
0.0,
assertThat(
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
import app.aaps.shared.tests.TestBaseWithProfile
import com.google.common.truth.Truth.assertThat
import info.nightscout.database.entities.TemporaryTarget
import info.nightscout.interfaces.GlucoseUnit
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class TemporaryTargetExtensionKtTest : TestBaseWithProfile() {
@ -25,18 +25,18 @@ class TemporaryTargetExtensionKtTest : TestBaseWithProfile() {
@Test
fun lowValueToUnitsToString() {
Assertions.assertEquals("110", temporaryTarget.lowValueToUnitsToString(GlucoseUnit.MGDL, decimalFormatter))
Assertions.assertEquals("6.1", temporaryTarget.lowValueToUnitsToString(GlucoseUnit.MMOL, decimalFormatter))
assertThat(temporaryTarget.lowValueToUnitsToString(GlucoseUnit.MGDL, decimalFormatter)).isEqualTo("110")
assertThat(temporaryTarget.lowValueToUnitsToString(GlucoseUnit.MMOL, decimalFormatter)).isEqualTo("6.1")
}
@Test
fun highValueToUnitsToString() {
Assertions.assertEquals("120", temporaryTarget.highValueToUnitsToString(GlucoseUnit.MGDL, decimalFormatter))
Assertions.assertEquals("6.7", temporaryTarget.highValueToUnitsToString(GlucoseUnit.MMOL, decimalFormatter))
assertThat(temporaryTarget.highValueToUnitsToString(GlucoseUnit.MGDL, decimalFormatter)).isEqualTo("120")
assertThat(temporaryTarget.highValueToUnitsToString(GlucoseUnit.MMOL, decimalFormatter)).isEqualTo("6.7")
}
@Test
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
import app.aaps.shared.tests.TestBaseWithProfile
import com.google.common.truth.Truth.assertThat
import info.nightscout.database.entities.TherapyEvent
import info.nightscout.database.entities.embedments.InterfaceIDs
import info.nightscout.shared.utils.T
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito
@ -30,8 +30,8 @@ class TherapyEventExtensionKtTest : TestBaseWithProfile() {
)
)
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())
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
import app.aaps.shared.tests.TestBase
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
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.utils.DateUtil
import info.nightscout.shared.utils.T
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mock
@ -61,26 +61,26 @@ class AuthRequestTest : TestBase() {
// Check if SMS requesting code is sent
var authRequest = AuthRequest(injector, requester, "Request text", "ABC", action)
Assertions.assertEquals(sentSms!!.phoneNumber, "aNumber")
Assertions.assertEquals(sentSms!!.text, "Request text")
assertThat(sentSms!!.phoneNumber).isEqualTo("aNumber")
assertThat(sentSms!!.text).isEqualTo("Request text")
// wrong reply
actionCalled = false
authRequest.action("EFG")
Assertions.assertEquals(sentSms!!.phoneNumber, "aNumber")
Assertions.assertEquals(sentSms!!.text, "Wrong code. Command cancelled.")
Assertions.assertFalse(actionCalled)
assertThat(sentSms!!.phoneNumber).isEqualTo("aNumber")
assertThat(sentSms!!.text).isEqualTo("Wrong code. Command cancelled.")
assertThat(actionCalled).isFalse()
// correct reply
authRequest = AuthRequest(injector, requester, "Request text", "ABC", action)
actionCalled = false
`when`(otp.checkOTP(anyObject())).thenReturn(OneTimePasswordValidationResult.OK)
authRequest.action("ABC")
Assertions.assertTrue(actionCalled)
assertThat(actionCalled).isTrue()
// second time action should not be called
actionCalled = false
authRequest.action("ABC")
Assertions.assertFalse(actionCalled)
assertThat(actionCalled).isFalse()
// test timed out message
val now: Long = 10000
@ -89,6 +89,6 @@ class AuthRequestTest : TestBase() {
actionCalled = false
`when`(dateUtil.now()).thenReturn(now + T.mins(Constants.SMS_CONFIRM_TIMEOUT).msecs() + 1)
authRequest.action("ABC")
Assertions.assertFalse(actionCalled)
assertThat(actionCalled).isFalse()
}
}

View file

@ -1,6 +1,6 @@
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
class SmsActionTest {
@ -13,49 +13,49 @@ class SmsActionTest {
}
}
smsAction.run()
Assertions.assertEquals(result, "A")
assertThat(result).isEqualTo("A")
smsAction = object : SmsAction(false, 1.0) {
override fun run() {
result = "B"
}
}
smsAction.run()
Assertions.assertEquals(result, "B")
Assertions.assertEquals(smsAction.aDouble(), 1.0, 0.000001)
assertThat(result).isEqualTo("B")
assertThat(smsAction.aDouble()).isWithin(0.000001).of(1.0)
smsAction = object : SmsAction(false, 1.0, 2) {
override fun run() {
result = "C"
}
}
smsAction.run()
Assertions.assertEquals(result, "C")
Assertions.assertEquals(smsAction.aDouble(), 1.0, 0.000001)
Assertions.assertEquals(smsAction.secondInteger().toLong(), 2)
assertThat(result).isEqualTo("C")
assertThat(smsAction.aDouble()).isWithin(0.000001).of(1.0)
assertThat(smsAction.secondInteger().toLong()).isEqualTo(2)
smsAction = object : SmsAction(false, "aString", 3) {
override fun run() {
result = "D"
}
}
smsAction.run()
Assertions.assertEquals(result, "D")
Assertions.assertEquals(smsAction.aString(), "aString")
Assertions.assertEquals(smsAction.secondInteger().toLong(), 3)
assertThat(result).isEqualTo("D")
assertThat(smsAction.aString()).isEqualTo("aString")
assertThat(smsAction.secondInteger().toLong()).isEqualTo(3)
smsAction = object : SmsAction(false, 4) {
override fun run() {
result = "E"
}
}
smsAction.run()
Assertions.assertEquals(result, "E")
Assertions.assertEquals(smsAction.anInteger().toLong(), 4)
assertThat(result).isEqualTo("E")
assertThat(smsAction.anInteger().toLong()).isEqualTo(4)
smsAction = object : SmsAction(false, 5, 6) {
override fun run() {
result = "F"
}
}
smsAction.run()
Assertions.assertEquals(result, "F")
Assertions.assertEquals(smsAction.anInteger().toLong(), 5)
Assertions.assertEquals(smsAction.secondInteger().toLong(), 6)
assertThat(result).isEqualTo("F")
assertThat(smsAction.anInteger().toLong()).isEqualTo(5)
assertThat(smsAction.secondInteger().toLong()).isEqualTo(6)
}
}

View file

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

View file

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