parent
62c5c53304
commit
cfb003af01
1 changed files with 41 additions and 49 deletions
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.core.data
|
package info.nightscout.core.data
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import info.nightscout.core.iob.combine
|
import info.nightscout.core.iob.combine
|
||||||
import info.nightscout.core.iob.copy
|
import info.nightscout.core.iob.copy
|
||||||
import info.nightscout.core.iob.determineBasalJson
|
import info.nightscout.core.iob.determineBasalJson
|
||||||
|
@ -11,7 +12,6 @@ import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.DateUtilImpl
|
import info.nightscout.shared.utils.DateUtilImpl
|
||||||
import info.nightscout.sharedtests.TestBase
|
import info.nightscout.sharedtests.TestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
@ -34,7 +34,7 @@ class IobTotalTest : TestBase() {
|
||||||
val a = IobTotal(now)
|
val a = IobTotal(now)
|
||||||
a.iob = 10.0
|
a.iob = 10.0
|
||||||
val b = a.copy()
|
val b = a.copy()
|
||||||
Assertions.assertEquals(a.iob, b.iob, 0.01)
|
assertThat(b.iob).isWithin(0.01).of(a.iob)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun plusTest() {
|
@Test fun plusTest() {
|
||||||
|
@ -48,14 +48,14 @@ class IobTotalTest : TestBase() {
|
||||||
a.netInsulin = 10.0
|
a.netInsulin = 10.0
|
||||||
a.extendedBolusInsulin = 10.0
|
a.extendedBolusInsulin = 10.0
|
||||||
a.plus(a.copy())
|
a.plus(a.copy())
|
||||||
Assertions.assertEquals(20.0, a.iob, 0.01)
|
assertThat(a.iob).isWithin(0.01).of(20.0)
|
||||||
Assertions.assertEquals(20.0, a.activity, 0.01)
|
assertThat(a.activity).isWithin(0.01).of(20.0)
|
||||||
Assertions.assertEquals(20.0, a.bolussnooze, 0.01)
|
assertThat(a.bolussnooze).isWithin(0.01).of(20.0)
|
||||||
Assertions.assertEquals(20.0, a.basaliob, 0.01)
|
assertThat(a.basaliob).isWithin(0.01).of(20.0)
|
||||||
Assertions.assertEquals(20.0, a.netbasalinsulin, 0.01)
|
assertThat(a.netbasalinsulin).isWithin(0.01).of(20.0)
|
||||||
Assertions.assertEquals(20.0, a.hightempinsulin, 0.01)
|
assertThat(a.hightempinsulin).isWithin(0.01).of(20.0)
|
||||||
Assertions.assertEquals(20.0, a.netInsulin, 0.01)
|
assertThat(a.netInsulin).isWithin(0.01).of(20.0)
|
||||||
Assertions.assertEquals(20.0, a.extendedBolusInsulin, 0.01)
|
assertThat(a.extendedBolusInsulin).isWithin(0.01).of(20.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun combineTest() {
|
@Test fun combineTest() {
|
||||||
|
@ -70,15 +70,15 @@ class IobTotalTest : TestBase() {
|
||||||
a.extendedBolusInsulin = 17.0
|
a.extendedBolusInsulin = 17.0
|
||||||
val b = a.copy()
|
val b = a.copy()
|
||||||
val c = IobTotal.combine(a, b)
|
val c = IobTotal.combine(a, b)
|
||||||
Assertions.assertEquals(a.time.toDouble(), c.time.toDouble(), 0.01)
|
assertThat(c.time.toDouble()).isWithin(0.01).of(a.time.toDouble())
|
||||||
Assertions.assertEquals(23.0, c.iob, 0.01)
|
assertThat(c.iob).isWithin(0.01).of(23.0)
|
||||||
Assertions.assertEquals(22.0, c.activity, 0.01)
|
assertThat(c.activity).isWithin(0.01).of(22.0)
|
||||||
Assertions.assertEquals(12.0, c.bolussnooze, 0.01)
|
assertThat(c.bolussnooze).isWithin(0.01).of(12.0)
|
||||||
Assertions.assertEquals(26.0, c.basaliob, 0.01)
|
assertThat(c.basaliob).isWithin(0.01).of(26.0)
|
||||||
Assertions.assertEquals(28.0, c.netbasalinsulin, 0.01)
|
assertThat(c.netbasalinsulin).isWithin(0.01).of(28.0)
|
||||||
Assertions.assertEquals(30.0, c.hightempinsulin, 0.01)
|
assertThat(c.hightempinsulin).isWithin(0.01).of(30.0)
|
||||||
Assertions.assertEquals(32.0, c.netInsulin, 0.01)
|
assertThat(c.netInsulin).isWithin(0.01).of(32.0)
|
||||||
Assertions.assertEquals(34.0, c.extendedBolusInsulin, 0.01)
|
assertThat(c.extendedBolusInsulin).isWithin(0.01).of(34.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun roundTest() {
|
@Test fun roundTest() {
|
||||||
|
@ -92,14 +92,14 @@ class IobTotalTest : TestBase() {
|
||||||
a.netInsulin = 1.1111111111111
|
a.netInsulin = 1.1111111111111
|
||||||
a.extendedBolusInsulin = 1.1111111111111
|
a.extendedBolusInsulin = 1.1111111111111
|
||||||
a.round()
|
a.round()
|
||||||
Assertions.assertEquals(1.111, a.iob, 0.00001)
|
assertThat(a.iob).isWithin(0.00001).of(1.111)
|
||||||
Assertions.assertEquals(1.1111, a.activity, 0.00001)
|
assertThat(a.activity).isWithin(0.00001).of(1.1111)
|
||||||
Assertions.assertEquals(1.1111, a.bolussnooze, 0.00001)
|
assertThat(a.bolussnooze).isWithin(0.00001).of(1.1111)
|
||||||
Assertions.assertEquals(1.111, a.basaliob, 0.00001)
|
assertThat(a.basaliob).isWithin(0.00001).of(1.111)
|
||||||
Assertions.assertEquals(1.111, a.netbasalinsulin, 0.00001)
|
assertThat(a.netbasalinsulin).isWithin(0.00001).of(1.111)
|
||||||
Assertions.assertEquals(1.111, a.hightempinsulin, 0.00001)
|
assertThat(a.hightempinsulin).isWithin(0.00001).of(1.111)
|
||||||
Assertions.assertEquals(1.111, a.netInsulin, 0.00001)
|
assertThat(a.netInsulin).isWithin(0.00001).of(1.111)
|
||||||
Assertions.assertEquals(1.111, a.extendedBolusInsulin, 0.00001)
|
assertThat(a.extendedBolusInsulin).isWithin(0.00001).of(1.111)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun jsonTest() {
|
@Test fun jsonTest() {
|
||||||
|
@ -112,15 +112,11 @@ class IobTotalTest : TestBase() {
|
||||||
a.hightempinsulin = 15.0
|
a.hightempinsulin = 15.0
|
||||||
a.netInsulin = 16.0
|
a.netInsulin = 16.0
|
||||||
a.extendedBolusInsulin = 17.0
|
a.extendedBolusInsulin = 17.0
|
||||||
try {
|
|
||||||
val j = a.json(dateUtil)
|
val j = a.json(dateUtil)
|
||||||
Assertions.assertEquals(a.iob, j.getDouble("iob"), 0.0000001)
|
assertThat(j.getDouble("iob")).isWithin(0.0000001).of(a.iob)
|
||||||
Assertions.assertEquals(a.basaliob, j.getDouble("basaliob"), 0.0000001)
|
assertThat(j.getDouble("basaliob")).isWithin(0.0000001).of(a.basaliob)
|
||||||
Assertions.assertEquals(a.activity, j.getDouble("activity"), 0.0000001)
|
assertThat(j.getDouble("activity")).isWithin(0.0000001).of(a.activity)
|
||||||
Assertions.assertEquals(now, dateUtil.fromISODateString(j.getString("time")))
|
assertThat(dateUtil.fromISODateString(j.getString("time"))).isEqualTo(now)
|
||||||
} catch (e: Exception) {
|
|
||||||
Assertions.fail("Exception: " + e.message)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun determineBasalJsonTest() {
|
@Test fun determineBasalJsonTest() {
|
||||||
|
@ -134,17 +130,13 @@ class IobTotalTest : TestBase() {
|
||||||
a.netInsulin = 16.0
|
a.netInsulin = 16.0
|
||||||
a.extendedBolusInsulin = 17.0
|
a.extendedBolusInsulin = 17.0
|
||||||
a.iobWithZeroTemp = IobTotal(now)
|
a.iobWithZeroTemp = IobTotal(now)
|
||||||
try {
|
|
||||||
val j = a.determineBasalJson(dateUtil)
|
val j = a.determineBasalJson(dateUtil)
|
||||||
Assertions.assertEquals(a.iob, j.getDouble("iob"), 0.0000001)
|
assertThat(j.getDouble("iob")).isWithin(0.0000001).of(a.iob)
|
||||||
Assertions.assertEquals(a.basaliob, j.getDouble("basaliob"), 0.0000001)
|
assertThat(j.getDouble("basaliob")).isWithin(0.0000001).of(a.basaliob)
|
||||||
Assertions.assertEquals(a.bolussnooze, j.getDouble("bolussnooze"), 0.0000001)
|
assertThat(j.getDouble("bolussnooze")).isWithin(0.0000001).of(a.bolussnooze)
|
||||||
Assertions.assertEquals(a.activity, j.getDouble("activity"), 0.0000001)
|
assertThat(j.getDouble("activity")).isWithin(0.0000001).of(a.activity)
|
||||||
Assertions.assertEquals(0, j.getLong("lastBolusTime"))
|
assertThat(j.getLong("lastBolusTime")).isEqualTo(0)
|
||||||
Assertions.assertEquals(now, dateUtil.fromISODateString(j.getString("time")))
|
assertThat(dateUtil.fromISODateString(j.getString("time"))).isEqualTo(now)
|
||||||
Assertions.assertNotNull(j.getJSONObject("iobWithZeroTemp"))
|
assertThat(j.getJSONObject("iobWithZeroTemp")).isNotNull()
|
||||||
} catch (e: Exception) {
|
|
||||||
Assertions.fail("Exception: " + e.message)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue