From 54735af1ece2838b85c1b0c7d4ef20b3cda9f71b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 3 Sep 2023 11:48:56 +0200 Subject: [PATCH] GlucoseValueExtensionKtTest --- .../core/extensions/GlucoseValueExtension.kt | 14 +++++ .../core/extensions/TrendArrowIcon.kt | 18 ------- .../extensions/GlucoseValueExtensionKtTest.kt | 52 +++++++++++++++++++ 3 files changed, 66 insertions(+), 18 deletions(-) delete mode 100644 core/main/src/main/java/info/nightscout/core/extensions/TrendArrowIcon.kt create mode 100644 plugins/insulin/src/test/java/info/nightscout/core/extensions/GlucoseValueExtensionKtTest.kt diff --git a/core/main/src/main/java/info/nightscout/core/extensions/GlucoseValueExtension.kt b/core/main/src/main/java/info/nightscout/core/extensions/GlucoseValueExtension.kt index 80884eb25e..bbff5637dc 100644 --- a/core/main/src/main/java/info/nightscout/core/extensions/GlucoseValueExtension.kt +++ b/core/main/src/main/java/info/nightscout/core/extensions/GlucoseValueExtension.kt @@ -1,5 +1,6 @@ package info.nightscout.core.extensions +import info.nightscout.core.main.R import info.nightscout.database.entities.GlucoseValue import info.nightscout.interfaces.Constants import info.nightscout.interfaces.GlucoseUnit @@ -31,3 +32,16 @@ fun InMemoryGlucoseValue.valueToUnitsString(units: GlucoseUnit): String = if (units == GlucoseUnit.MGDL) DecimalFormatter.to0Decimal(recalculated) else DecimalFormatter.to1Decimal(recalculated * Constants.MGDL_TO_MMOLL) +fun GlucoseValue.TrendArrow.directionToIcon(): Int = + when (this) { + GlucoseValue.TrendArrow.TRIPLE_DOWN -> R.drawable.ic_invalid + GlucoseValue.TrendArrow.DOUBLE_DOWN -> R.drawable.ic_doubledown + GlucoseValue.TrendArrow.SINGLE_DOWN -> R.drawable.ic_singledown + GlucoseValue.TrendArrow.FORTY_FIVE_DOWN -> R.drawable.ic_fortyfivedown + GlucoseValue.TrendArrow.FLAT -> R.drawable.ic_flat + GlucoseValue.TrendArrow.FORTY_FIVE_UP -> R.drawable.ic_fortyfiveup + GlucoseValue.TrendArrow.SINGLE_UP -> R.drawable.ic_singleup + GlucoseValue.TrendArrow.DOUBLE_UP -> R.drawable.ic_doubleup + GlucoseValue.TrendArrow.TRIPLE_UP -> R.drawable.ic_invalid + GlucoseValue.TrendArrow.NONE -> R.drawable.ic_invalid + } \ No newline at end of file diff --git a/core/main/src/main/java/info/nightscout/core/extensions/TrendArrowIcon.kt b/core/main/src/main/java/info/nightscout/core/extensions/TrendArrowIcon.kt deleted file mode 100644 index 02c33ed49b..0000000000 --- a/core/main/src/main/java/info/nightscout/core/extensions/TrendArrowIcon.kt +++ /dev/null @@ -1,18 +0,0 @@ -package info.nightscout.core.extensions - -import info.nightscout.core.main.R -import info.nightscout.database.entities.GlucoseValue - -fun GlucoseValue.TrendArrow.directionToIcon(): Int { - return when { - this == GlucoseValue.TrendArrow.DOUBLE_DOWN -> R.drawable.ic_doubledown - this == GlucoseValue.TrendArrow.SINGLE_DOWN -> R.drawable.ic_singledown - this == GlucoseValue.TrendArrow.FORTY_FIVE_DOWN -> R.drawable.ic_fortyfivedown - this == GlucoseValue.TrendArrow.FLAT -> R.drawable.ic_flat - this == GlucoseValue.TrendArrow.FORTY_FIVE_UP -> R.drawable.ic_fortyfiveup - this == GlucoseValue.TrendArrow.SINGLE_UP -> R.drawable.ic_singleup - this == GlucoseValue.TrendArrow.DOUBLE_UP -> R.drawable.ic_doubleup - this == GlucoseValue.TrendArrow.NONE -> R.drawable.ic_invalid - else -> R.drawable.ic_invalid - } -} diff --git a/plugins/insulin/src/test/java/info/nightscout/core/extensions/GlucoseValueExtensionKtTest.kt b/plugins/insulin/src/test/java/info/nightscout/core/extensions/GlucoseValueExtensionKtTest.kt new file mode 100644 index 0000000000..f70484c71a --- /dev/null +++ b/plugins/insulin/src/test/java/info/nightscout/core/extensions/GlucoseValueExtensionKtTest.kt @@ -0,0 +1,52 @@ +package info.nightscout.core.extensions + +import info.nightscout.androidaps.TestBaseWithProfile +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() { + + private val glucoseValue = GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = 1514766900000, sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT) + private val inMemoryGlucoseValue = InMemoryGlucoseValue(1000, 100.0, sourceSensor = GlucoseValue.SourceSensor.UNKNOWN) + @Test + fun valueToUnitsString() { + Assertions.assertEquals("100", glucoseValue.valueToUnitsString(GlucoseUnit.MGDL)) + Assertions.assertEquals("5.6", glucoseValue.valueToUnitsString(GlucoseUnit.MMOL)) + } + @Test + fun inMemoryValueToUnitsString() { + Assertions.assertEquals("100", inMemoryGlucoseValue.valueToUnitsString(GlucoseUnit.MGDL)) + Assertions.assertEquals("5.6", inMemoryGlucoseValue.valueToUnitsString(GlucoseUnit.MMOL)) + } + @Test + fun inMemoryValueToUnits() { + Assertions.assertEquals(100.0, inMemoryGlucoseValue.valueToUnits(GlucoseUnit.MGDL)) + Assertions.assertEquals(5.55, inMemoryGlucoseValue.valueToUnits(GlucoseUnit.MMOL), 0.01) + } + @Test + fun directionToIcon() { + Assertions.assertEquals(R.drawable.ic_flat, glucoseValue.trendArrow.directionToIcon()) + glucoseValue.trendArrow = GlucoseValue.TrendArrow.NONE + Assertions.assertEquals(R.drawable.ic_invalid, glucoseValue.trendArrow.directionToIcon()) + glucoseValue.trendArrow = GlucoseValue.TrendArrow.TRIPLE_DOWN + Assertions.assertEquals(R.drawable.ic_invalid, glucoseValue.trendArrow.directionToIcon()) + glucoseValue.trendArrow = GlucoseValue.TrendArrow.TRIPLE_UP + Assertions.assertEquals(R.drawable.ic_invalid, glucoseValue.trendArrow.directionToIcon()) + glucoseValue.trendArrow = GlucoseValue.TrendArrow.DOUBLE_DOWN + Assertions.assertEquals(R.drawable.ic_doubledown, glucoseValue.trendArrow.directionToIcon()) + glucoseValue.trendArrow = GlucoseValue.TrendArrow.SINGLE_DOWN + Assertions.assertEquals(R.drawable.ic_singledown, glucoseValue.trendArrow.directionToIcon()) + glucoseValue.trendArrow = GlucoseValue.TrendArrow.FORTY_FIVE_DOWN + Assertions.assertEquals(R.drawable.ic_fortyfivedown, glucoseValue.trendArrow.directionToIcon()) + glucoseValue.trendArrow = GlucoseValue.TrendArrow.FORTY_FIVE_UP + Assertions.assertEquals(R.drawable.ic_fortyfiveup, glucoseValue.trendArrow.directionToIcon()) + glucoseValue.trendArrow = GlucoseValue.TrendArrow.SINGLE_UP + Assertions.assertEquals(R.drawable.ic_singleup, glucoseValue.trendArrow.directionToIcon()) + glucoseValue.trendArrow = GlucoseValue.TrendArrow.DOUBLE_UP + Assertions.assertEquals(R.drawable.ic_doubleup, glucoseValue.trendArrow.directionToIcon()) + } +} \ No newline at end of file