NSEffectiveProfileSwitch unit tests

This commit is contained in:
Milos Kozak 2022-12-24 11:41:09 +01:00
parent 9048a84006
commit 295e1ad18f
2 changed files with 48 additions and 2 deletions

View file

@ -49,12 +49,12 @@ data class EffectiveProfileSwitch(
var originalTimeshift: Long, // [milliseconds]
var originalPercentage: Int, // 1 ~ XXX [%]
var originalDuration: Long, // [milliseconds]
var originalEnd: Long,
var originalEnd: Long, // not used (calculated from duration)
@Embedded
var insulinConfiguration: InsulinConfiguration
) : TraceableDBEntry, DBEntryWithTime {
private fun contentEqualsTo(other: EffectiveProfileSwitch): Boolean =
fun contentEqualsTo(other: EffectiveProfileSwitch): Boolean =
isValid == other.isValid &&
timestamp == other.timestamp &&
utcOffset == other.utcOffset &&

View file

@ -0,0 +1,46 @@
package info.nightscout.plugins.sync.nsclientV3.extensions
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.database.entities.EffectiveProfileSwitch
import info.nightscout.database.entities.embedments.InterfaceIDs
import info.nightscout.plugins.sync.nsclient.extensions.fromConstant
import info.nightscout.sdk.localmodel.treatment.NSEffectiveProfileSwitch
import info.nightscout.sdk.mapper.convertToRemoteAndBack
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
@Suppress("SpellCheckingInspection")
internal class EffectiveProfileSwitchExtensionKtTest : TestBaseWithProfile() {
@Test
fun toEffectiveProfileSwitch() {
val profileSwitch = EffectiveProfileSwitch(
timestamp = 10000,
isValid = true,
basalBlocks = validProfile.basalBlocks,
isfBlocks = validProfile.isfBlocks,
icBlocks = validProfile.icBlocks,
targetBlocks = validProfile.targetBlocks,
glucoseUnit = EffectiveProfileSwitch.GlucoseUnit.fromConstant(validProfile.units),
originalProfileName = "SomeProfile",
originalCustomizedName = "SomeProfile (150%, 1h)",
originalTimeshift = 3600000,
originalPercentage = 150,
originalDuration = 3600000,
originalEnd = 0,
insulinConfiguration = activePlugin.activeInsulin.insulinConfiguration.also {
it.insulinEndTime = (validProfile.dia * 3600 * 1000).toLong()
},
interfaceIDs_backing = InterfaceIDs(
nightscoutId = "nightscoutId",
pumpId = 11000,
pumpType = InterfaceIDs.PumpType.DANA_I,
pumpSerial = "bbbb"
)
)
val profileSwitch2 = (profileSwitch.toNSEffectiveProfileSwitch(dateUtil).convertToRemoteAndBack() as NSEffectiveProfileSwitch).toEffectiveProfileSwitch(dateUtil)!!
Assertions.assertTrue(profileSwitch.contentEqualsTo(profileSwitch2))
Assertions.assertTrue(profileSwitch.interfaceIdsEqualsTo(profileSwitch2))
}
}