NSCarbs unit tests
This commit is contained in:
parent
fb265f959e
commit
8ceaaa4119
|
@ -58,16 +58,6 @@ data class Bolus(
|
|||
notes == other.notes &&
|
||||
isBasalInsulin == other.isBasalInsulin
|
||||
|
||||
fun interfaceIdsEqualsTo(other: Bolus): Boolean =
|
||||
interfaceIDs.nightscoutId == interfaceIDs.nightscoutId &&
|
||||
interfaceIDs.nightscoutSystemId == interfaceIDs.nightscoutSystemId &&
|
||||
interfaceIDs.pumpType == interfaceIDs.pumpType &&
|
||||
interfaceIDs.pumpSerial == interfaceIDs.pumpSerial &&
|
||||
interfaceIDs.temporaryId == interfaceIDs.temporaryId &&
|
||||
interfaceIDs.pumpId == interfaceIDs.pumpId &&
|
||||
interfaceIDs.startId == interfaceIDs.startId &&
|
||||
interfaceIDs.endId == interfaceIDs.endId
|
||||
|
||||
fun onlyNsIdAdded(previous: Bolus): Boolean =
|
||||
previous.id != id &&
|
||||
contentEqualsTo(previous) &&
|
||||
|
|
|
@ -38,7 +38,7 @@ data class Carbs(
|
|||
var notes: String? = null
|
||||
) : TraceableDBEntry, DBEntryWithTimeAndDuration {
|
||||
|
||||
private fun contentEqualsTo(other: Carbs): Boolean =
|
||||
fun contentEqualsTo(other: Carbs): Boolean =
|
||||
isValid == other.isValid &&
|
||||
timestamp == other.timestamp &&
|
||||
utcOffset == other.utcOffset &&
|
||||
|
|
|
@ -25,4 +25,15 @@ interface TraceableDBEntry: DBEntry {
|
|||
set(value) {
|
||||
interfaceIDs_backing = value
|
||||
}
|
||||
|
||||
fun interfaceIdsEqualsTo(other: TraceableDBEntry): Boolean =
|
||||
interfaceIDs.nightscoutId == interfaceIDs.nightscoutId &&
|
||||
interfaceIDs.nightscoutSystemId == interfaceIDs.nightscoutSystemId &&
|
||||
interfaceIDs.pumpType == interfaceIDs.pumpType &&
|
||||
interfaceIDs.pumpSerial == interfaceIDs.pumpSerial &&
|
||||
interfaceIDs.temporaryId == interfaceIDs.temporaryId &&
|
||||
interfaceIDs.pumpId == interfaceIDs.pumpId &&
|
||||
interfaceIDs.startId == interfaceIDs.startId &&
|
||||
interfaceIDs.endId == interfaceIDs.endId
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||
|
||||
import info.nightscout.database.entities.Carbs
|
||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||
import info.nightscout.sdk.localmodel.treatment.NSCarbs
|
||||
import info.nightscout.sdk.mapper.convertToRemoteAndBack
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
internal class CarbsExtensionKtTest {
|
||||
|
||||
@Test
|
||||
fun toCarbs() {
|
||||
var carbs = Carbs(
|
||||
timestamp = 10000,
|
||||
isValid = true,
|
||||
amount = 1.0,
|
||||
duration = 0,
|
||||
notes = "aaaa",
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId",
|
||||
pumpId = 11000,
|
||||
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||
pumpSerial = "bbbb"
|
||||
)
|
||||
)
|
||||
|
||||
var carbs2 = (carbs.toNSCarbs().convertToRemoteAndBack() as NSCarbs).toCarbs()
|
||||
Assertions.assertTrue(carbs.contentEqualsTo(carbs2))
|
||||
Assertions.assertTrue(carbs.interfaceIdsEqualsTo(carbs2))
|
||||
|
||||
carbs = Carbs(
|
||||
timestamp = 10000,
|
||||
isValid = false,
|
||||
amount = 1.0,
|
||||
duration = 60000,
|
||||
notes = null,
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId",
|
||||
pumpId = 11000,
|
||||
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||
pumpSerial = "bbbb"
|
||||
)
|
||||
)
|
||||
|
||||
carbs2 = (carbs.toNSCarbs().convertToRemoteAndBack() as NSCarbs).toCarbs()
|
||||
Assertions.assertTrue(carbs.contentEqualsTo(carbs2))
|
||||
Assertions.assertTrue(carbs.interfaceIdsEqualsTo(carbs2))
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue