From 295e1ad18fdf137089dd5dcdecadfc925e406fc8 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 24 Dec 2022 11:41:09 +0100 Subject: [PATCH] NSEffectiveProfileSwitch unit tests --- .../entities/EffectiveProfileSwitch.kt | 4 +- .../EffectiveProfileSwitchExtensionKtTest.kt | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/EffectiveProfileSwitchExtensionKtTest.kt diff --git a/database/entities/src/main/java/info/nightscout/database/entities/EffectiveProfileSwitch.kt b/database/entities/src/main/java/info/nightscout/database/entities/EffectiveProfileSwitch.kt index 6d0bd8b5d1..870497c1a9 100644 --- a/database/entities/src/main/java/info/nightscout/database/entities/EffectiveProfileSwitch.kt +++ b/database/entities/src/main/java/info/nightscout/database/entities/EffectiveProfileSwitch.kt @@ -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 && diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/EffectiveProfileSwitchExtensionKtTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/EffectiveProfileSwitchExtensionKtTest.kt new file mode 100644 index 0000000000..c8c5ec6660 --- /dev/null +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/EffectiveProfileSwitchExtensionKtTest.kt @@ -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)) + } +} \ No newline at end of file