Merge pull request #2811 from ryanhaining/assertthat_core

Rewrites core/ tests with matchers
This commit is contained in:
Milos Kozak 2023-09-21 11:24:26 +02:00 committed by GitHub
commit 647d66eca0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 331 additions and 343 deletions

View file

@ -1,8 +1,8 @@
package info.nightscout.core.data package info.nightscout.core.data
import com.google.common.truth.Truth.assertThat
import info.nightscout.core.constraints.ConstraintObject import info.nightscout.core.constraints.ConstraintObject
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
@ -13,43 +13,39 @@ class ConstraintTest : TestBase() {
@Test fun doTests() { @Test fun doTests() {
val b = ConstraintObject(true, aapsLogger) val b = ConstraintObject(true, aapsLogger)
Assertions.assertEquals(true, b.value()) assertThat(b.value()).isTrue()
Assertions.assertEquals("", b.getReasons()) assertThat(b.getReasons()).isEmpty()
Assertions.assertEquals("", b.getMostLimitedReasons()) assertThat(b.getMostLimitedReasons()).isEmpty()
b.set(false) b.set(false)
Assertions.assertEquals(false, b.value()) assertThat(b.value()).isFalse()
Assertions.assertEquals("", b.getReasons()) assertThat(b.getReasons()).isEmpty()
Assertions.assertEquals("", b.getMostLimitedReasons()) assertThat(b.getMostLimitedReasons()).isEmpty()
b.set(true, "Set true", this) b.set(true, "Set true", this)
Assertions.assertEquals(true, b.value()) assertThat(b.value()).isTrue()
Assertions.assertEquals("ConstraintTest: Set true", b.getReasons()) assertThat(b.getReasons()).isEqualTo("ConstraintTest: Set true")
Assertions.assertEquals("ConstraintTest: Set true", b.getMostLimitedReasons()) assertThat(b.getMostLimitedReasons()).isEqualTo("ConstraintTest: Set true")
b.set(false, "Set false", this) b.set(false, "Set false", this)
Assertions.assertEquals(false, b.value()) assertThat(b.value()).isFalse()
Assertions.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getReasons()) assertThat(b.getReasons()).isEqualTo("ConstraintTest: Set true\nConstraintTest: Set false")
Assertions.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getMostLimitedReasons()) assertThat(b.getMostLimitedReasons()).isEqualTo("ConstraintTest: Set true\nConstraintTest: Set false")
val d = ConstraintObject(10.0, aapsLogger) val d = ConstraintObject(10.0, aapsLogger)
d.set(5.0, "Set 5d", this) d.set(5.0, "Set 5d", this)
Assertions.assertEquals(5.0, d.value(), 0.01) assertThat(d.value()).isWithin(0.01).of(5.0)
Assertions.assertEquals("ConstraintTest: Set 5d", d.getReasons()) assertThat(d.getReasons()).isEqualTo("ConstraintTest: Set 5d")
Assertions.assertEquals("ConstraintTest: Set 5d", d.getMostLimitedReasons()) assertThat(d.getMostLimitedReasons()).isEqualTo("ConstraintTest: Set 5d")
d.setIfSmaller(6.0, "Set 6d", this) d.setIfSmaller(6.0, "Set 6d", this)
Assertions.assertEquals(5.0, d.value(), 0.01) assertThat(d.value()).isWithin(0.01).of(5.0)
Assertions.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d", d.getReasons()) assertThat(d.getReasons()).isEqualTo("ConstraintTest: Set 5d\nConstraintTest: Set 6d")
Assertions.assertEquals("ConstraintTest: Set 5d", d.getMostLimitedReasons()) assertThat(d.getMostLimitedReasons()).isEqualTo("ConstraintTest: Set 5d")
d.setIfSmaller(4.0, "Set 4d", this) d.setIfSmaller(4.0, "Set 4d", this)
Assertions.assertEquals(4.0, d.value(), 0.01) assertThat(d.value()).isWithin(0.01).of(4.0)
Assertions.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d", d.getReasons()) assertThat(d.getReasons()).isEqualTo("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d")
Assertions.assertEquals("ConstraintTest: Set 4d", d.getMostLimitedReasons()) assertThat(d.getMostLimitedReasons()).isEqualTo("ConstraintTest: Set 4d")
Assertions.assertEquals(10.0, d.originalValue(), 0.01) assertThat(d.originalValue()).isWithin(0.01).of(10.0)
d.setIfDifferent(7.0, "Set 7d", this) d.setIfDifferent(7.0, "Set 7d", this)
Assertions.assertEquals(7.0, d.value(), 0.01) assertThat(d.value()).isWithin(0.01).of(7.0)
Assertions.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d\nConstraintTest: Set 7d", d.getReasons()) assertThat(d.getReasons()).isEqualTo("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d\nConstraintTest: Set 7d")
Assertions.assertEquals("ConstraintTest: Set 4d\nConstraintTest: Set 7d", d.getMostLimitedReasons()) assertThat(d.getMostLimitedReasons()).isEqualTo("ConstraintTest: Set 4d\nConstraintTest: Set 7d")
Assertions.assertEquals(10.0, d.originalValue(), 0.01) assertThat(d.originalValue()).isWithin(0.01).of(10.0)
}
@BeforeEach
fun prepareMock() {
} }
} }

View file

@ -1,5 +1,6 @@
package info.nightscout.core.data package info.nightscout.core.data
import com.google.common.truth.Truth.assertThat
import android.content.Context import android.content.Context
import com.google.gson.Gson import com.google.gson.Gson
import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.Bolus
@ -8,7 +9,6 @@ import info.nightscout.database.entities.TherapyEvent
import info.nightscout.interfaces.pump.DetailedBolusInfo import info.nightscout.interfaces.pump.DetailedBolusInfo
import info.nightscout.sharedtests.TestBase import info.nightscout.sharedtests.TestBase
import org.apache.commons.lang3.builder.EqualsBuilder import org.apache.commons.lang3.builder.EqualsBuilder
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
@ -18,14 +18,14 @@ class DetailedBolusInfoTest : TestBase() {
@Test fun toStringShouldBeOverloaded() { @Test fun toStringShouldBeOverloaded() {
val detailedBolusInfo = DetailedBolusInfo() val detailedBolusInfo = DetailedBolusInfo()
Assertions.assertEquals(true, detailedBolusInfo.toJsonString().contains("insulin")) assertThat(detailedBolusInfo.toJsonString()).contains("insulin")
} }
@Test fun copyShouldCopyAllProperties() { @Test fun copyShouldCopyAllProperties() {
val d1 = DetailedBolusInfo() val d1 = DetailedBolusInfo()
d1.deliverAtTheLatest = 123 d1.deliverAtTheLatest = 123
val d2 = d1.copy() val d2 = d1.copy()
Assertions.assertTrue(EqualsBuilder.reflectionEquals(d2, d1, arrayListOf("id"))) assertThat(EqualsBuilder.reflectionEquals(d2, d1, arrayListOf("id"))).isTrue()
} }
private fun fromJsonString(json: String): DetailedBolusInfo = private fun fromJsonString(json: String): DetailedBolusInfo =
@ -41,10 +41,10 @@ class DetailedBolusInfoTest : TestBase() {
detailedBolusInfo.eventType = DetailedBolusInfo.EventType.BOLUS_WIZARD detailedBolusInfo.eventType = DetailedBolusInfo.EventType.BOLUS_WIZARD
val serialized = detailedBolusInfo.toJsonString() val serialized = detailedBolusInfo.toJsonString()
val deserialized = fromJsonString(serialized) val deserialized = fromJsonString(serialized)
Assertions.assertEquals(1L, deserialized.bolusCalculatorResult?.timestamp) assertThat(deserialized.bolusCalculatorResult?.timestamp).isEqualTo(1L)
Assertions.assertEquals(DetailedBolusInfo.EventType.BOLUS_WIZARD, deserialized.eventType) assertThat(deserialized.eventType).isEqualTo(DetailedBolusInfo.EventType.BOLUS_WIZARD)
// Context should be excluded // Context should be excluded
Assertions.assertNull(deserialized.context) assertThat(deserialized.context).isNull()
} }
@Test @Test
@ -56,12 +56,12 @@ class DetailedBolusInfoTest : TestBase() {
detailedBolusInfo.glucoseType = DetailedBolusInfo.MeterType.FINGER detailedBolusInfo.glucoseType = DetailedBolusInfo.MeterType.FINGER
val therapyEvent = detailedBolusInfo.createTherapyEvent() val therapyEvent = detailedBolusInfo.createTherapyEvent()
Assertions.assertEquals(1000L, therapyEvent.timestamp) assertThat(therapyEvent.timestamp).isEqualTo(1000L)
Assertions.assertEquals(TherapyEvent.Type.MEAL_BOLUS, therapyEvent.type) assertThat(therapyEvent.type).isEqualTo(TherapyEvent.Type.MEAL_BOLUS)
Assertions.assertEquals(TherapyEvent.GlucoseUnit.MGDL, therapyEvent.glucoseUnit) assertThat(therapyEvent.glucoseUnit).isEqualTo(TherapyEvent.GlucoseUnit.MGDL)
Assertions.assertEquals("note", therapyEvent.note) assertThat(therapyEvent.note).isEqualTo("note")
Assertions.assertEquals(180.0, therapyEvent.glucose) assertThat(therapyEvent.glucose).isEqualTo(180.0)
Assertions.assertEquals(TherapyEvent.MeterType.FINGER, therapyEvent.glucoseType) assertThat(therapyEvent.glucoseType).isEqualTo(TherapyEvent.MeterType.FINGER)
} }
@Test @Test
@ -72,9 +72,9 @@ class DetailedBolusInfoTest : TestBase() {
detailedBolusInfo.insulin = 7.0 detailedBolusInfo.insulin = 7.0
val bolus = detailedBolusInfo.createBolus() val bolus = detailedBolusInfo.createBolus()
Assertions.assertEquals(1000L, bolus.timestamp) assertThat(bolus.timestamp).isEqualTo(1000L)
Assertions.assertEquals(Bolus.Type.SMB, bolus.type) assertThat(bolus.type).isEqualTo(Bolus.Type.SMB)
Assertions.assertEquals(7.0, bolus.amount, 0.01) assertThat(bolus.amount).isWithin(0.01).of(7.0)
} }
@Test @Test
@ -84,8 +84,8 @@ class DetailedBolusInfoTest : TestBase() {
detailedBolusInfo.carbs = 6.0 detailedBolusInfo.carbs = 6.0
val carbs = detailedBolusInfo.createCarbs() val carbs = detailedBolusInfo.createCarbs()
Assertions.assertEquals(1000L, carbs.timestamp) assertThat(carbs.timestamp).isEqualTo(1000L)
Assertions.assertEquals(6.0, carbs.amount, 0.01) assertThat(carbs.amount).isWithin(0.01).of(6.0)
} }
private fun createBolusCalculatorResult(): BolusCalculatorResult = private fun createBolusCalculatorResult(): BolusCalculatorResult =

View file

@ -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)
}
} }
} }

View file

@ -1,13 +1,13 @@
package info.nightscout.core.data package info.nightscout.core.data
import com.google.common.truth.Truth.assertThat
import info.nightscout.interfaces.iob.MealData import info.nightscout.interfaces.iob.MealData
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class MealDataTest { class MealDataTest {
@Test fun canCreateObject() { @Test fun canCreateObject() {
val md = MealData() val md = MealData()
Assertions.assertEquals(0.0, md.carbs, 0.01) assertThat(md.carbs).isWithin(0.01).of(0.0)
} }
} }

View file

@ -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 dagger.android.AndroidInjector import dagger.android.AndroidInjector
import info.nightscout.core.extensions.pureProfileFromJson import info.nightscout.core.extensions.pureProfileFromJson
import info.nightscout.core.profile.ProfileSealed import info.nightscout.core.profile.ProfileSealed
@ -15,7 +16,6 @@ import info.nightscout.sharedtests.HardLimitsMock
import info.nightscout.sharedtests.TestBase import info.nightscout.sharedtests.TestBase
import info.nightscout.sharedtests.TestPumpPlugin import info.nightscout.sharedtests.TestPumpPlugin
import org.json.JSONObject import org.json.JSONObject
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
@ -71,77 +71,77 @@ class ProfileTest : TestBase() {
// Test valid profile // Test valid profile
var p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(okProfile), dateUtil)!!) var p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(okProfile), dateUtil)!!)
Assertions.assertEquals(true, p.isValid("Test", testPumpPlugin, config, rh, rxBus, hardLimits, false).isValid) assertThat(p.isValid("Test", testPumpPlugin, config, rh, rxBus, hardLimits, false).isValid).isTrue()
// Assertions.assertEquals(true, p.log().contains("NS units: mmol")) // assertThat(p.log()).contains("NS units: mmol")
// JSONAssertions.assertEquals(JSONObject(okProfile), p.toPureNsJson(dateUtil), false) // JSONAssertions.assertEquals(JSONObject(okProfile), p.toPureNsJson(dateUtil), false)
Assertions.assertEquals(5.0, p.dia, 0.01) assertThat(p.dia).isWithin(0.01).of(5.0)
// Assertions.assertEquals(TimeZone.getTimeZone("UTC"), p.timeZone) // assertThat(p.timeZone).isEqualTo(TimeZone.getTimeZone("UTC"))
Assertions.assertEquals("00:30", dateUtil.formatHHMM(30 * 60)) assertThat(dateUtil.formatHHMM(30 * 60)).isEqualTo("00:30")
val c = Calendar.getInstance() val c = Calendar.getInstance()
c[Calendar.HOUR_OF_DAY] = 1 c[Calendar.HOUR_OF_DAY] = 1
c[Calendar.MINUTE] = 0 c[Calendar.MINUTE] = 0
c[Calendar.SECOND] = 0 c[Calendar.SECOND] = 0
c[Calendar.MILLISECOND] = 0 c[Calendar.MILLISECOND] = 0
Assertions.assertEquals(108.0, p.getIsfMgdl(c.timeInMillis), 0.01) assertThat(p.getIsfMgdl(c.timeInMillis)).isWithin(0.01).of(108.0)
c[Calendar.HOUR_OF_DAY] = 2 c[Calendar.HOUR_OF_DAY] = 2
Assertions.assertEquals(111.6, p.getIsfMgdl(c.timeInMillis), 0.01) assertThat(p.getIsfMgdl(c.timeInMillis)).isWithin(0.01).of(111.6)
// Assertions.assertEquals(110.0, p.getIsfTimeFromMidnight(2 * 60 * 60), 0.01) // assertThat(p.getIsfTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(110.0)
Assertions.assertEquals( assertThat(p.getIsfList(rh, dateUtil).replace(".", ",")).isEqualTo(
""" """
00:00 6,0 mmol/U 00:00 6,0 mmol/U
02:00 6,2 mmol/U 02:00 6,2 mmol/U
""".trimIndent(), p.getIsfList(rh, dateUtil).replace(".", ",") """.trimIndent()
) )
Assertions.assertEquals(30.0, p.getIc(c.timeInMillis), 0.01) assertThat(p.getIc(c.timeInMillis)).isWithin(0.01).of(30.0)
Assertions.assertEquals(30.0, p.getIcTimeFromMidnight(2 * 60 * 60), 0.01) assertThat(p.getIcTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(30.0)
Assertions.assertEquals("00:00 30,0 g/U", p.getIcList(rh, dateUtil).replace(".", ",")) assertThat(p.getIcList(rh, dateUtil).replace(".", ",")).isEqualTo("00:00 30,0 g/U")
Assertions.assertEquals(0.1, p.getBasal(c.timeInMillis), 0.01) assertThat(p.getBasal(c.timeInMillis)).isWithin(0.01).of(0.1)
Assertions.assertEquals(0.1, p.getBasalTimeFromMidnight(2 * 60 * 60), 0.01) assertThat(p.getBasalTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(0.1)
Assertions.assertEquals("00:00 0,10 U/h", p.getBasalList(rh, dateUtil).replace(".", ",")) assertThat(p.getBasalList(rh, dateUtil).replace(".", ",")).isEqualTo("00:00 0,10 U/h")
Assertions.assertEquals(0.1, p.getBasalValues()[0].value, 0.01) assertThat(p.getBasalValues()[0].value).isWithin(0.01).of(0.1)
Assertions.assertEquals(0.1, p.getMaxDailyBasal(), 0.01) assertThat(p.getMaxDailyBasal()).isWithin(0.01).of(0.1)
Assertions.assertEquals(2.4, p.percentageBasalSum(), 0.01) assertThat(p.percentageBasalSum()).isWithin(0.01).of(2.4)
Assertions.assertEquals(2.4, p.baseBasalSum(), 0.01) assertThat(p.baseBasalSum()).isWithin(0.01).of(2.4)
// Assertions.assertEquals(81.0, p.getTargetMgdl(2 * 60 * 60), 0.01) // assertThat( p.getTargetMgdl(2 * 60 * 60)).isWithin(0.01).of(81.0)
Assertions.assertEquals(90.0, p.getTargetLowMgdl(c.timeInMillis), 0.01) assertThat( p.getTargetLowMgdl(c.timeInMillis)).isWithin(0.01).of(90.0)
// Assertions.assertEquals(4.0, p.getTargetLowTimeFromMidnight(2 * 60 * 60), 0.01) // assertThat( p.getTargetLowTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(4.0)
Assertions.assertEquals(90.0, p.getTargetHighMgdl(c.timeInMillis), 0.01) assertThat( p.getTargetHighMgdl(c.timeInMillis)).isWithin(0.01).of(90.0)
// Assertions.assertEquals(5.0, p.getTargetHighTimeFromMidnight(2 * 60 * 60), 0.01) // assertThat( p.getTargetHighTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(5.0)
Assertions.assertEquals("00:00 5,0 - 5,0 mmol", p.getTargetList(rh, dateUtil).replace(".", ",")) assertThat(p.getTargetList(rh, dateUtil).replace(".", ",")).isEqualTo("00:00 5,0 - 5,0 mmol")
Assertions.assertEquals(100, p.percentage) assertThat(p.percentage).isEqualTo(100)
Assertions.assertEquals(0, p.timeshift) assertThat(p.timeshift).isEqualTo(0)
//Test basal profile below limit //Test basal profile below limit
p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(belowLimitValidProfile), dateUtil)!!) p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(belowLimitValidProfile), dateUtil)!!)
p.isValid("Test", testPumpPlugin, config, rh, rxBus, hardLimits, false) p.isValid("Test", testPumpPlugin, config, rh, rxBus, hardLimits, false)
// Test profile w/o units // Test profile w/o units
Assertions.assertNull(pureProfileFromJson(JSONObject(noUnitsValidProfile), dateUtil)) assertThat(pureProfileFromJson(JSONObject(noUnitsValidProfile), dateUtil)).isNull()
//Test profile not starting at midnight //Test profile not starting at midnight
p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(notStartingAtZeroValidProfile), dateUtil)!!) p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(notStartingAtZeroValidProfile), dateUtil)!!)
Assertions.assertEquals(30.0, p.getIc(0), 0.01) assertThat(p.getIc(0)).isWithin(0.01).of(30.0)
// Test wrong profile // Test wrong profile
Assertions.assertNull(pureProfileFromJson(JSONObject(wrongProfile), dateUtil)) assertThat(pureProfileFromJson(JSONObject(wrongProfile), dateUtil)).isNull()
// Test percentage functionality // Test percentage functionality
p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(okProfile), dateUtil)!!) p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(okProfile), dateUtil)!!)
p.pct = 50 p.pct = 50
Assertions.assertEquals(0.05, p.getBasal(c.timeInMillis), 0.01) assertThat(p.getBasal(c.timeInMillis)).isWithin(0.01).of(0.05)
Assertions.assertEquals(1.2, p.percentageBasalSum(), 0.01) assertThat(p.percentageBasalSum()).isWithin(0.01).of(1.2)
Assertions.assertEquals(60.0, p.getIc(c.timeInMillis), 0.01) assertThat(p.getIc(c.timeInMillis)).isWithin(0.01).of(60.0)
Assertions.assertEquals(223.2, p.getIsfMgdl(c.timeInMillis), 0.01) assertThat(p.getIsfMgdl(c.timeInMillis)).isWithin(0.01).of(223.2)
// Test timeshift functionality // Test timeshift functionality
p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(okProfile), dateUtil)!!) p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(okProfile), dateUtil)!!)
p.ts = 1 p.ts = 1
Assertions.assertEquals( assertThat(p.getIsfList(rh, dateUtil).replace(',', '.')).isEqualTo(
""" """
00:00 6.2 mmol/U 00:00 6.2 mmol/U
01:00 6.0 mmol/U 01:00 6.0 mmol/U
03:00 6.2 mmol/U 03:00 6.2 mmol/U
""".trimIndent(), p.getIsfList(rh, dateUtil).replace(',', '.') """.trimIndent()
) )
// Test hour alignment // Test hour alignment

View file

@ -1,10 +1,10 @@
package info.nightscout.core.extensions package info.nightscout.core.extensions
import com.google.common.truth.Truth.assertThat
import info.nightscout.database.entities.data.Block import info.nightscout.database.entities.data.Block
import info.nightscout.database.entities.data.TargetBlock import info.nightscout.database.entities.data.TargetBlock
import info.nightscout.database.entities.data.checkSanity import info.nightscout.database.entities.data.checkSanity
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class BlockExtensionKtTest { class BlockExtensionKtTest {
@ -17,36 +17,36 @@ class BlockExtensionKtTest {
b.add(Block(T.hours(10).msecs(), 3.0)) b.add(Block(T.hours(10).msecs(), 3.0))
b.add(Block(T.hours(12).msecs(), 4.0)) b.add(Block(T.hours(12).msecs(), 4.0))
Assertions.assertTrue(b.checkSanity()) assertThat(b.checkSanity()).isTrue()
Assertions.assertEquals(1.0, b.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0), 0.01) assertThat(b.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0)).isWithin(0.01).of(1.0)
Assertions.assertEquals(2.0, b.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0), 0.01) assertThat(b.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0)).isWithin(0.01).of(2.0)
Assertions.assertEquals(3.0, b.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0), 0.01) assertThat(b.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0)).isWithin(0.01).of(3.0)
Assertions.assertEquals(3.0, b.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0), 0.01) assertThat(b.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0)).isWithin(0.01).of(3.0)
Assertions.assertEquals(4.0, b.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0), 0.01) assertThat(b.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0)).isWithin(0.01).of(4.0)
Assertions.assertEquals(4.0, b.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0), 0.01) assertThat(b.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0)).isWithin(0.01).of(4.0)
val s1 = b.shiftBlock(1.0, -1) val s1 = b.shiftBlock(1.0, -1)
Assertions.assertTrue(s1.checkSanity()) assertThat(s1.checkSanity()).isTrue()
Assertions.assertEquals(1.0, s1.blockValueBySeconds(T.hours(23).secs().toInt(), 1.0, 0), 0.01) assertThat(s1.blockValueBySeconds(T.hours(23).secs().toInt(), 1.0, 0)).isWithin(0.01).of(1.0)
Assertions.assertEquals(2.0, s1.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0), 0.01) assertThat(s1.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0)).isWithin(0.01).of(2.0)
Assertions.assertEquals(3.0, s1.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0), 0.01) assertThat(s1.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0)).isWithin(0.01).of(3.0)
Assertions.assertEquals(3.0, s1.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0), 0.01) assertThat(s1.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0)).isWithin(0.01).of(3.0)
Assertions.assertEquals(4.0, s1.blockValueBySeconds(T.hours(11).secs().toInt(), 1.0, 0), 0.01) assertThat(s1.blockValueBySeconds(T.hours(11).secs().toInt(), 1.0, 0)).isWithin(0.01).of(4.0)
Assertions.assertEquals(4.0, s1.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0), 0.01) assertThat(s1.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0)).isWithin(0.01).of(4.0)
val s2 = b.shiftBlock(2.0, 1) val s2 = b.shiftBlock(2.0, 1)
Assertions.assertTrue(s2.checkSanity()) assertThat(s2.checkSanity()).isTrue()
Assertions.assertEquals(2.0, s2.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0), 0.01) assertThat(s2.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0)).isWithin(0.01).of(2.0)
Assertions.assertEquals(4.0, s2.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0), 0.01) assertThat(s2.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0)).isWithin(0.01).of(4.0)
Assertions.assertEquals(6.0, s2.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0), 0.01) assertThat(s2.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0)).isWithin(0.01).of(6.0)
Assertions.assertEquals(6.0, s2.blockValueBySeconds(T.hours(4).secs().toInt(), 1.0, 0), 0.01) assertThat(s2.blockValueBySeconds(T.hours(4).secs().toInt(), 1.0, 0)).isWithin(0.01).of(6.0)
Assertions.assertEquals(8.0, s2.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0), 0.01) assertThat(s2.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0)).isWithin(0.01).of(8.0)
Assertions.assertEquals(8.0, s2.blockValueBySeconds(T.hours(14).secs().toInt(), 1.0, 0), 0.01) assertThat(s2.blockValueBySeconds(T.hours(14).secs().toInt(), 1.0, 0)).isWithin(0.01).of(8.0)
} }
@Test @Test
@ -57,36 +57,36 @@ class BlockExtensionKtTest {
b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0)) b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0))
b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0)) b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0))
Assertions.assertTrue(b.checkSanity()) assertThat(b.checkSanity()).isTrue()
Assertions.assertEquals(1.5, b.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01) assertThat(b.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0)).isWithin(0.01).of(1.5)
Assertions.assertEquals(2.5, b.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01) assertThat(b.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0)).isWithin(0.01).of(2.5)
Assertions.assertEquals(3.5, b.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01) assertThat(b.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0)).isWithin(0.01).of(3.5)
Assertions.assertEquals(3.5, b.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01) assertThat(b.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0)).isWithin(0.01).of(3.5)
Assertions.assertEquals(4.5, b.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01) assertThat(b.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0)).isWithin(0.01).of(4.5)
Assertions.assertEquals(4.5, b.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01) assertThat(b.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0)).isWithin(0.01).of(4.5)
val s1 = b.shiftTargetBlock(-1) val s1 = b.shiftTargetBlock(-1)
Assertions.assertTrue(s1.checkSanity()) assertThat(s1.checkSanity()).isTrue()
Assertions.assertEquals(1.5, s1.targetBlockValueBySeconds(T.hours(23).secs().toInt(), 0), 0.01) assertThat(s1.targetBlockValueBySeconds(T.hours(23).secs().toInt(), 0)).isWithin(0.01).of(1.5)
Assertions.assertEquals(2.5, s1.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01) assertThat(s1.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0)).isWithin(0.01).of(2.5)
Assertions.assertEquals(3.5, s1.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01) assertThat(s1.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0)).isWithin(0.01).of(3.5)
Assertions.assertEquals(3.5, s1.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01) assertThat(s1.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0)).isWithin(0.01).of(3.5)
Assertions.assertEquals(4.5, s1.targetBlockValueBySeconds(T.hours(11).secs().toInt(), 0), 0.01) assertThat(s1.targetBlockValueBySeconds(T.hours(11).secs().toInt(), 0)).isWithin(0.01).of(4.5)
Assertions.assertEquals(4.5, s1.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01) assertThat(s1.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0)).isWithin(0.01).of(4.5)
val s2 = b.shiftTargetBlock(1) val s2 = b.shiftTargetBlock(1)
Assertions.assertTrue(s2.checkSanity()) assertThat(s2.checkSanity()).isTrue()
Assertions.assertEquals(1.5, s2.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01) assertThat(s2.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0)).isWithin(0.01).of(1.5)
Assertions.assertEquals(2.5, s2.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01) assertThat(s2.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0)).isWithin(0.01).of(2.5)
Assertions.assertEquals(3.5, s2.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01) assertThat(s2.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0)).isWithin(0.01).of(3.5)
Assertions.assertEquals(3.5, s2.targetBlockValueBySeconds(T.hours(4).secs().toInt(), 0), 0.01) assertThat(s2.targetBlockValueBySeconds(T.hours(4).secs().toInt(), 0)).isWithin(0.01).of(3.5)
Assertions.assertEquals(4.5, s2.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01) assertThat(s2.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0)).isWithin(0.01).of(4.5)
Assertions.assertEquals(4.5, s2.targetBlockValueBySeconds(T.hours(14).secs().toInt(), 0), 0.01) assertThat(s2.targetBlockValueBySeconds(T.hours(14).secs().toInt(), 0)).isWithin(0.01).of(4.5)
} }
@Test @Test
@ -97,14 +97,14 @@ class BlockExtensionKtTest {
b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0)) b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0))
b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0)) b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0))
Assertions.assertTrue(b.checkSanity()) assertThat(b.checkSanity()).isTrue()
Assertions.assertEquals(1.0, b.lowTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01) assertThat(b.lowTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0)).isWithin(0.01).of(1.0)
Assertions.assertEquals(2.0, b.lowTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01) assertThat(b.lowTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0)).isWithin(0.01).of(2.0)
Assertions.assertEquals(3.0, b.lowTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01) assertThat(b.lowTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0)).isWithin(0.01).of(3.0)
Assertions.assertEquals(3.0, b.lowTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01) assertThat(b.lowTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0)).isWithin(0.01).of(3.0)
Assertions.assertEquals(4.0, b.lowTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01) assertThat(b.lowTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0)).isWithin(0.01).of(4.0)
Assertions.assertEquals(4.0, b.lowTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01) assertThat(b.lowTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0)).isWithin(0.01).of(4.0)
} }
@Test @Test
@ -115,13 +115,13 @@ class BlockExtensionKtTest {
b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0)) b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0))
b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0)) b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0))
Assertions.assertTrue(b.checkSanity()) assertThat(b.checkSanity()).isTrue()
Assertions.assertEquals(2.0, b.highTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01) assertThat(b.highTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0)).isWithin(0.01).of(2.0)
Assertions.assertEquals(3.0, b.highTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01) assertThat(b.highTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0)).isWithin(0.01).of(3.0)
Assertions.assertEquals(4.0, b.highTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01) assertThat(b.highTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0)).isWithin(0.01).of(4.0)
Assertions.assertEquals(4.0, b.highTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01) assertThat(b.highTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0)).isWithin(0.01).of(4.0)
Assertions.assertEquals(5.0, b.highTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01) assertThat(b.highTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0)).isWithin(0.01).of(5.0)
Assertions.assertEquals(5.0, b.highTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01) assertThat(b.highTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0)).isWithin(0.01).of(5.0)
} }
} }

View file

@ -2,13 +2,13 @@ package info.nightscout.core.graph.data
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import com.google.common.truth.Truth.assertThat
import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.GlucoseValue
import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.iob.InMemoryGlucoseValue import info.nightscout.interfaces.iob.InMemoryGlucoseValue
import info.nightscout.interfaces.profile.DefaultValueHelper import info.nightscout.interfaces.profile.DefaultValueHelper
import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
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
@ -34,15 +34,16 @@ internal class InMemoryGlucoseValueDataPointTest {
Mockito.`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL) Mockito.`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
Mockito.`when`(rh.gac(any(), any())).thenReturn(Color.GREEN) Mockito.`when`(rh.gac(any(), any())).thenReturn(Color.GREEN)
} }
@Test @Test
fun alphaShouldBeAddedForFilledGaps() { fun alphaShouldBeAddedForFilledGaps() {
val gv = InMemoryGlucoseValue(1000, 100.0, sourceSensor = GlucoseValue.SourceSensor.UNKNOWN) val gv = InMemoryGlucoseValue(1000, 100.0, sourceSensor = GlucoseValue.SourceSensor.UNKNOWN)
val sut = InMemoryGlucoseValueDataPoint(gv, defaultValueHelper, profileFunction, rh) val sut = InMemoryGlucoseValueDataPoint(gv, defaultValueHelper, profileFunction, rh)
var alpha = sut.color(context).ushr(24) var alpha = sut.color(context).ushr(24)
Assertions.assertEquals(255, alpha) assertThat(alpha).isEqualTo(255)
gv.filledGap = true gv.filledGap = true
alpha = sut.color(context).ushr(24) alpha = sut.color(context).ushr(24)
Assertions.assertEquals(128, alpha) assertThat(alpha).isEqualTo(128)
} }
} }

View file

@ -1,70 +1,70 @@
package info.nightscout.core.interfaces package info.nightscout.core.interfaces
import com.google.common.truth.Truth.assertThat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.plugin.PluginType
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class PluginDescriptionTest { class PluginDescriptionTest {
@Test fun mainTypeTest() { @Test fun mainTypeTest() {
val pluginDescription = PluginDescription().mainType(PluginType.PUMP) val pluginDescription = PluginDescription().mainType(PluginType.PUMP)
Assertions.assertEquals(PluginType.PUMP, pluginDescription.mainType) assertThat(pluginDescription.mainType).isEqualTo(PluginType.PUMP)
} }
@Test fun fragmentClassTest() { @Test fun fragmentClassTest() {
val pluginDescription = PluginDescription().fragmentClass(Fragment::class.java.name) val pluginDescription = PluginDescription().fragmentClass(Fragment::class.java.name)
Assertions.assertEquals(Fragment::class.java.name, pluginDescription.fragmentClass) assertThat(pluginDescription.fragmentClass).isEqualTo(Fragment::class.java.name)
} }
@Test fun alwaysEnabledTest() { @Test fun alwaysEnabledTest() {
val pluginDescription = PluginDescription().alwaysEnabled(true) val pluginDescription = PluginDescription().alwaysEnabled(true)
Assertions.assertEquals(true, pluginDescription.alwaysEnabled) assertThat(pluginDescription.alwaysEnabled).isTrue()
} }
@Test fun alwaysVisibleTest() { @Test fun alwaysVisibleTest() {
val pluginDescription = PluginDescription().alwaysVisible(true) val pluginDescription = PluginDescription().alwaysVisible(true)
Assertions.assertEquals(true, pluginDescription.alwaysVisible) assertThat(pluginDescription.alwaysVisible).isTrue()
} }
@Test fun neverVisibleTest() { @Test fun neverVisibleTest() {
val pluginDescription = PluginDescription().neverVisible(true) val pluginDescription = PluginDescription().neverVisible(true)
Assertions.assertEquals(true, pluginDescription.neverVisible) assertThat(pluginDescription.neverVisible).isTrue()
} }
@Test fun showInListTest() { @Test fun showInListTest() {
val pluginDescription = PluginDescription().showInList(false) val pluginDescription = PluginDescription().showInList(false)
Assertions.assertEquals(false, pluginDescription.showInList) assertThat(pluginDescription.showInList).isFalse()
} }
@Test fun pluginIcon() { @Test fun pluginIcon() {
val pluginDescription = PluginDescription().pluginIcon(10) val pluginDescription = PluginDescription().pluginIcon(10)
Assertions.assertEquals(10, pluginDescription.pluginIcon.toLong()) assertThat(pluginDescription.pluginIcon.toLong()).isEqualTo(10)
} }
@Test fun pluginName() { @Test fun pluginName() {
val pluginDescription = PluginDescription().pluginName(10) val pluginDescription = PluginDescription().pluginName(10)
Assertions.assertEquals(10, pluginDescription.pluginName.toLong()) assertThat(pluginDescription.pluginName.toLong()).isEqualTo(10)
} }
@Test fun shortNameTest() { @Test fun shortNameTest() {
val pluginDescription = PluginDescription().shortName(10) val pluginDescription = PluginDescription().shortName(10)
Assertions.assertEquals(10, pluginDescription.shortName.toLong()) assertThat(pluginDescription.shortName.toLong()).isEqualTo(10)
} }
@Test fun preferencesIdTest() { @Test fun preferencesIdTest() {
val pluginDescription = PluginDescription().preferencesId(10) val pluginDescription = PluginDescription().preferencesId(10)
Assertions.assertEquals(10, pluginDescription.preferencesId.toLong()) assertThat(pluginDescription.preferencesId.toLong()).isEqualTo(10)
} }
@Test fun enableByDefault() { @Test fun enableByDefault() {
val pluginDescription = PluginDescription().enableByDefault(true) val pluginDescription = PluginDescription().enableByDefault(true)
Assertions.assertEquals(true, pluginDescription.enableByDefault) assertThat(pluginDescription.enableByDefault).isTrue()
} }
@Test fun visibleByDefault() { @Test fun visibleByDefault() {
val pluginDescription = PluginDescription().visibleByDefault(true) val pluginDescription = PluginDescription().visibleByDefault(true)
Assertions.assertEquals(true, pluginDescription.visibleByDefault) assertThat(pluginDescription.visibleByDefault).isTrue()
} }
} }

View file

@ -1,10 +1,10 @@
package info.nightscout.core.interfaces package info.nightscout.core.interfaces
import com.google.common.truth.Truth.assertThat
import info.nightscout.interfaces.pump.defs.PumpCapability import info.nightscout.interfaces.pump.defs.PumpCapability
import info.nightscout.interfaces.pump.defs.PumpDescription import info.nightscout.interfaces.pump.defs.PumpDescription
import info.nightscout.interfaces.pump.defs.PumpTempBasalType import info.nightscout.interfaces.pump.defs.PumpTempBasalType
import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.interfaces.pump.defs.PumpType
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class PumpDescriptionTest { class PumpDescriptionTest {
@ -12,22 +12,22 @@ class PumpDescriptionTest {
@Test fun setPumpDescription() { @Test fun setPumpDescription() {
val pumpDescription = PumpDescription() val pumpDescription = PumpDescription()
pumpDescription.fillFor(PumpType.ACCU_CHEK_COMBO) pumpDescription.fillFor(PumpType.ACCU_CHEK_COMBO)
Assertions.assertEquals(pumpDescription.bolusStep, PumpType.ACCU_CHEK_COMBO.bolusSize, 0.1) assertThat(pumpDescription.bolusStep).isWithin(0.1).of(PumpType.ACCU_CHEK_COMBO.bolusSize)
Assertions.assertEquals(pumpDescription.basalMinimumRate, PumpType.ACCU_CHEK_COMBO.baseBasalStep, 0.1) assertThat(pumpDescription.basalMinimumRate).isWithin(0.1).of(PumpType.ACCU_CHEK_COMBO.baseBasalStep)
Assertions.assertEquals(pumpDescription.basalStep, PumpType.ACCU_CHEK_COMBO.baseBasalStep, 0.1) assertThat(pumpDescription.basalStep).isWithin(0.1).of(PumpType.ACCU_CHEK_COMBO.baseBasalStep)
Assertions.assertEquals(pumpDescription.extendedBolusDurationStep, PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.durationStep?.toDouble()) assertThat(pumpDescription.extendedBolusDurationStep).isEqualTo(PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.durationStep?.toDouble())
Assertions.assertEquals(pumpDescription.extendedBolusMaxDuration, PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.maxDuration?.toDouble()) assertThat(pumpDescription.extendedBolusMaxDuration).isEqualTo(PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.maxDuration?.toDouble())
Assertions.assertEquals(pumpDescription.extendedBolusStep, PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.step) assertThat(pumpDescription.extendedBolusStep).isEqualTo(PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.step)
Assertions.assertEquals(pumpDescription.isExtendedBolusCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.ExtendedBolus)) assertThat(pumpDescription.isExtendedBolusCapable).isEqualTo(PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.ExtendedBolus))
Assertions.assertEquals(pumpDescription.isBolusCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.Bolus)) assertThat(pumpDescription.isBolusCapable).isEqualTo(PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.Bolus))
Assertions.assertEquals(pumpDescription.isRefillingCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.Refill)) assertThat(pumpDescription.isRefillingCapable).isEqualTo(PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.Refill))
Assertions.assertEquals(pumpDescription.isSetBasalProfileCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.BasalProfileSet)) assertThat(pumpDescription.isSetBasalProfileCapable).isEqualTo(PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.BasalProfileSet))
Assertions.assertEquals(pumpDescription.isTempBasalCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.TempBasal)) assertThat(pumpDescription.isTempBasalCapable).isEqualTo(PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.TempBasal))
Assertions.assertEquals(pumpDescription.maxTempPercent.toDouble(), PumpType.ACCU_CHEK_COMBO.tbrSettings?.maxDose) assertThat(pumpDescription.maxTempPercent.toDouble()).isEqualTo(PumpType.ACCU_CHEK_COMBO.tbrSettings?.maxDose)
Assertions.assertEquals(pumpDescription.tempPercentStep.toDouble(), PumpType.ACCU_CHEK_COMBO.tbrSettings?.step) assertThat(pumpDescription.tempPercentStep.toDouble()).isEqualTo(PumpType.ACCU_CHEK_COMBO.tbrSettings?.step)
Assertions.assertEquals(pumpDescription.tempBasalStyle, if (PumpType.ACCU_CHEK_COMBO.pumpTempBasalType == PumpTempBasalType.Percent) PumpDescription.PERCENT else PumpDescription.ABSOLUTE) assertThat(pumpDescription.tempBasalStyle).isEqualTo(if (PumpType.ACCU_CHEK_COMBO.pumpTempBasalType == PumpTempBasalType.Percent) PumpDescription.PERCENT else PumpDescription.ABSOLUTE)
Assertions.assertEquals(pumpDescription.tempDurationStep.toLong(), PumpType.ACCU_CHEK_COMBO.tbrSettings?.durationStep?.toLong()) assertThat(pumpDescription.tempDurationStep.toLong()).isEqualTo(PumpType.ACCU_CHEK_COMBO.tbrSettings?.durationStep?.toLong())
Assertions.assertEquals(pumpDescription.tempDurationStep15mAllowed, PumpType.ACCU_CHEK_COMBO.specialBasalDurations?.hasCapability(PumpCapability.BasalRate_Duration15minAllowed)) assertThat(pumpDescription.tempDurationStep15mAllowed).isEqualTo(PumpType.ACCU_CHEK_COMBO.specialBasalDurations?.hasCapability(PumpCapability.BasalRate_Duration15minAllowed))
Assertions.assertEquals(pumpDescription.tempDurationStep30mAllowed, PumpType.ACCU_CHEK_COMBO.specialBasalDurations?.hasCapability(PumpCapability.BasalRate_Duration30minAllowed)) assertThat(pumpDescription.tempDurationStep30mAllowed).isEqualTo(PumpType.ACCU_CHEK_COMBO.specialBasalDurations?.hasCapability(PumpCapability.BasalRate_Duration30minAllowed))
} }
} }

View file

@ -1,7 +1,7 @@
package info.nightscout.core.pump.common.utils package info.nightscout.core.pump.common.utils
import com.google.common.truth.Truth.assertThat
import info.nightscout.core.utils.DateTimeUtil import info.nightscout.core.utils.DateTimeUtil
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
internal class DateTimeUtilUTest { internal class DateTimeUtilUTest {
@ -10,6 +10,6 @@ internal class DateTimeUtilUTest {
val dt1 = 20191001182301L val dt1 = 20191001182301L
val dt2 = 20191001192805L val dt2 = 20191001192805L
val aTechDateDifferenceAsMinutes = DateTimeUtil.getATechDateDifferenceAsMinutes(dt1, dt2) val aTechDateDifferenceAsMinutes = DateTimeUtil.getATechDateDifferenceAsMinutes(dt1, dt2)
Assertions.assertEquals(65, aTechDateDifferenceAsMinutes) assertThat(aTechDateDifferenceAsMinutes).isEqualTo(65)
} }
} }

View file

@ -1,8 +1,8 @@
package info.nightscout.core.utils package info.nightscout.core.utils
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.TruthJUnit.assume import com.google.common.truth.TruthJUnit.assume
import info.nightscout.sharedtests.TestBase import info.nightscout.sharedtests.TestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
// https://stackoverflow.com/questions/52344522/joseexception-couldnt-create-aes-gcm-nopadding-cipher-illegal-key-size // https://stackoverflow.com/questions/52344522/joseexception-couldnt-create-aes-gcm-nopadding-cipher-illegal-key-size
@ -33,11 +33,11 @@ class CryptoUtilTest : TestBase() {
val encrypted = cryptoUtil.encrypt(password, salt, payload) val encrypted = cryptoUtil.encrypt(password, salt, payload)
assumeAES256isSupported(cryptoUtil) assumeAES256isSupported(cryptoUtil)
Assertions.assertNotNull(encrypted) assertThat(encrypted).isNotNull()
val decrypted = cryptoUtil.decrypt(password, salt, encrypted!!) val decrypted = cryptoUtil.decrypt(password, salt, encrypted!!)
assumeAES256isSupported(cryptoUtil) assumeAES256isSupported(cryptoUtil)
Assertions.assertEquals(decrypted, payload) assertThat(decrypted).isEqualTo(payload)
} }
@Test @Test
@ -49,18 +49,18 @@ class CryptoUtilTest : TestBase() {
val encrypted = cryptoUtil.encrypt(password, salt, payload) val encrypted = cryptoUtil.encrypt(password, salt, payload)
assumeAES256isSupported(cryptoUtil) assumeAES256isSupported(cryptoUtil)
Assertions.assertNotNull(encrypted) assertThat(encrypted).isNotNull()
val decrypted = cryptoUtil.decrypt(password, salt, encrypted!!) val decrypted = cryptoUtil.decrypt(password, salt, encrypted!!)
assumeAES256isSupported(cryptoUtil) assumeAES256isSupported(cryptoUtil)
Assertions.assertEquals(decrypted, payload) assertThat(decrypted).isEqualTo(payload)
} }
@Test @Test
fun testHashVector() { fun testHashVector() {
val payload = "{what:payloadYouWantToProtect}" val payload = "{what:payloadYouWantToProtect}"
val hash = cryptoUtil.sha256(payload) val hash = cryptoUtil.sha256(payload)
Assertions.assertEquals(hash, "a1aafe3ed6cc127e6d102ddbc40a205147230e9cfd178daf108c83543bbdcd13") assertThat(hash).isEqualTo("a1aafe3ed6cc127e6d102ddbc40a205147230e9cfd178daf108c83543bbdcd13")
} }
@Test @Test
@ -69,44 +69,44 @@ class CryptoUtilTest : TestBase() {
val password = "topSikret" val password = "topSikret"
val expectedHmac = "ea2213953d0f2e55047cae2d23fb4f0de1b805d55e6271efa70d6b85fb692bea" // generated using other HMAC tool val expectedHmac = "ea2213953d0f2e55047cae2d23fb4f0de1b805d55e6271efa70d6b85fb692bea" // generated using other HMAC tool
val hash = cryptoUtil.hmac256(payload, password) val hash = cryptoUtil.hmac256(payload, password)
Assertions.assertEquals(hash, expectedHmac) assertThat(hash).isEqualTo(expectedHmac)
} }
@Test @Test
fun testPlainPasswordCheck() { fun testPlainPasswordCheck() {
Assertions.assertTrue(cryptoUtil.checkPassword("same", "same")) assertThat(cryptoUtil.checkPassword("same", "same")).isTrue()
Assertions.assertFalse(cryptoUtil.checkPassword("same", "other")) assertThat(cryptoUtil.checkPassword("same", "other")).isFalse()
} }
@Test @Test
fun testHashedPasswordCheck() { fun testHashedPasswordCheck() {
Assertions.assertTrue(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("givenSecret"))) assertThat(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("givenSecret"))).isTrue()
Assertions.assertFalse(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("otherSecret"))) assertThat(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("otherSecret"))).isFalse()
Assertions.assertTrue( assertThat(
cryptoUtil.checkPassword( cryptoUtil.checkPassword(
"givenHashToCheck", "givenHashToCheck",
"hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1" "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1"
) )
) ).isTrue()
Assertions.assertFalse( assertThat(
cryptoUtil.checkPassword( cryptoUtil.checkPassword(
"givenMashToCheck", "givenMashToCheck",
"hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1" "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1"
) )
) ).isFalse()
Assertions.assertFalse( assertThat(
cryptoUtil.checkPassword( cryptoUtil.checkPassword(
"givenHashToCheck", "givenHashToCheck",
"hmac:0fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1" "hmac:0fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1"
) )
) ).isFalse()
Assertions.assertFalse( assertThat(
cryptoUtil.checkPassword( cryptoUtil.checkPassword(
"givenHashToCheck", "givenHashToCheck",
"hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:b0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1" "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:b0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1"
) )
) ).isFalse()
} }
} }

View file

@ -7,7 +7,6 @@ import info.nightscout.shared.utils.DateUtilImpl
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T
import info.nightscout.sharedtests.TestBase import info.nightscout.sharedtests.TestBase
import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
@ -41,25 +40,25 @@ class DateUtilTest : TestBase() {
@Test @Test
fun fromISODateStringTest() { fun fromISODateStringTest() {
Assertions.assertEquals(1511124634417L, DateUtilImpl(context).fromISODateString("2017-11-19T22:50:34.417+0200")) assertThat(DateUtilImpl(context).fromISODateString("2017-11-19T22:50:34.417+0200")).isEqualTo(1511124634417L)
Assertions.assertEquals(1511124634000L, DateUtilImpl(context).fromISODateString("2017-11-19T22:50:34+0200")) assertThat(DateUtilImpl(context).fromISODateString("2017-11-19T22:50:34+0200")).isEqualTo(1511124634000L)
Assertions.assertEquals(1512317365000L, DateUtilImpl(context).fromISODateString("2017-12-03T16:09:25.000Z")) assertThat(DateUtilImpl(context).fromISODateString("2017-12-03T16:09:25.000Z")).isEqualTo(1512317365000L)
Assertions.assertEquals(1513902750000L, DateUtilImpl(context).fromISODateString("2017-12-22T00:32:30Z")) assertThat(DateUtilImpl(context).fromISODateString("2017-12-22T00:32:30Z")).isEqualTo(1513902750000L)
} }
@Test @Test
fun toISOStringTest() { fun toISOStringTest() {
Assertions.assertEquals("2017-12-22T00:32:30.000Z", DateUtilImpl(context).toISOString(1513902750000L)) assertThat(DateUtilImpl(context).toISOString(1513902750000L)).isEqualTo("2017-12-22T00:32:30.000Z")
} }
@Test fun secondsOfTheDayToMillisecondsTest() { @Test fun secondsOfTheDayToMillisecondsTest() {
Assertions.assertTrue(Date(DateUtilImpl(context).secondsOfTheDayToMilliseconds((T.hours(1).secs() + T.mins(1).secs() + 1).toInt())).toString().contains("01:01:00")) assertThat(Date(DateUtilImpl(context).secondsOfTheDayToMilliseconds((T.hours(1).secs() + T.mins(1).secs() + 1).toInt())).toString()).contains("01:01:00")
} }
@Test fun toSecondsTest() { @Test fun toSecondsTest() {
Assertions.assertEquals(3600, DateUtilImpl(context).toSeconds("01:00").toLong()) assertThat(DateUtilImpl(context).toSeconds("01:00").toLong()).isEqualTo(3600)
Assertions.assertEquals(3600, DateUtilImpl(context).toSeconds("01:00 a.m.").toLong()) assertThat(DateUtilImpl(context).toSeconds("01:00 a.m.").toLong()).isEqualTo(3600)
Assertions.assertEquals(3600, DateUtilImpl(context).toSeconds("01:00 AM").toLong()) assertThat(DateUtilImpl(context).toSeconds("01:00 AM").toLong()).isEqualTo(3600)
} }
@Test fun dateStringTest() { @Test fun dateStringTest() {
@ -67,7 +66,7 @@ class DateUtilTest : TestBase() {
} }
@Test fun timeStringTest() { @Test fun timeStringTest() {
Assertions.assertTrue(DateUtilImpl(context).timeString(1513902750000L).contains("32")) assertThat(DateUtilImpl(context).timeString(1513902750000L)).contains("32")
} }
@Test fun dateAndTimeStringTest() { @Test fun dateAndTimeStringTest() {
@ -85,11 +84,11 @@ class DateUtilTest : TestBase() {
/* /*
@Test @Test
public void timeStringFromSecondsTest() { public void timeStringFromSecondsTest() {
Assertions.assertEquals("1:00 AM", DateUtil.timeStringFromSeconds((int) T.hours(1).secs())); assertThat(DateUtil.timeStringFromSeconds((int) T.hours(1).secs()));.isEqualTo("1:00 AM")
} }
*/ */
@Test fun timeFrameStringTest() { @Test fun timeFrameStringTest() {
`when`(rh.gs(info.nightscout.interfaces.R.string.shorthour)).thenReturn("h") `when`(rh.gs(info.nightscout.interfaces.R.string.shorthour)).thenReturn("h")
Assertions.assertEquals("(1h 1')", DateUtilImpl(context).timeFrameString(T.hours(1).msecs() + T.mins(1).msecs(), rh)) assertThat(DateUtilImpl(context).timeFrameString(T.hours(1).msecs() + T.mins(1).msecs(), rh)).isEqualTo("(1h 1')")
} }
} }

View file

@ -1,7 +1,7 @@
package info.nightscout.core.utils package info.nightscout.core.utils
import com.google.common.truth.Truth.assertThat
import org.json.JSONObject import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
@ -13,67 +13,67 @@ class JsonHelperTest {
fun safeGetObjectTest() { fun safeGetObjectTest() {
val json = JSONObject(jsonString) val json = JSONObject(jsonString)
val o = Any() val o = Any()
Assertions.assertEquals(o, JsonHelper.safeGetObject(null, "x", o)) assertThat(JsonHelper.safeGetObject(null, "x", o)).isEqualTo(o)
Assertions.assertEquals(o, JsonHelper.safeGetObject(json, "x", o)) assertThat(JsonHelper.safeGetObject(json, "x", o)).isEqualTo(o)
Assertions.assertNotEquals(o, JsonHelper.safeGetObject(json, "d", o)) assertThat(JsonHelper.safeGetObject(json, "d", o)).isNotEqualTo(o)
} }
@Test @Test
fun safeGetJSONObjectTest() { fun safeGetJSONObjectTest() {
val json = JSONObject(jsonString) val json = JSONObject(jsonString)
val o = JSONObject() val o = JSONObject()
Assertions.assertEquals(o, JsonHelper.safeGetJSONObject(null, "x", o)) assertThat(JsonHelper.safeGetJSONObject(null, "x", o)).isEqualTo(o)
Assertions.assertTrue(JsonHelper.safeGetJSONObject(json, "j", o)!!.has("a")) assertThat(JsonHelper.safeGetJSONObject(json, "j", o)!!.has("a")).isTrue()
Assertions.assertEquals(o, JsonHelper.safeGetJSONObject(json, "d", o)) assertThat(JsonHelper.safeGetJSONObject(json, "d", o)).isEqualTo(o)
} }
@Test @Test
fun safeGetStringTest() { fun safeGetStringTest() {
val json = JSONObject(jsonString) val json = JSONObject(jsonString)
Assertions.assertNull(JsonHelper.safeGetString(null, "s")) assertThat(JsonHelper.safeGetString(null, "s")).isNull()
Assertions.assertNull(JsonHelper.safeGetString(json, "notexisting")) assertThat(JsonHelper.safeGetString(json, "notexisting")).isNull()
Assertions.assertEquals("5", JsonHelper.safeGetString(json, "s")) assertThat(JsonHelper.safeGetString(json, "s")).isEqualTo("5")
Assertions.assertEquals("default", JsonHelper.safeGetString(null, "notexisting", "default")) assertThat(JsonHelper.safeGetString(null, "notexisting", "default")).isEqualTo("default")
Assertions.assertEquals("default", JsonHelper.safeGetString(json, "notexisting", "default")) assertThat(JsonHelper.safeGetString(json, "notexisting", "default")).isEqualTo("default")
Assertions.assertEquals("5", JsonHelper.safeGetString(json, "s", "default")) assertThat(JsonHelper.safeGetString(json, "s", "default")).isEqualTo("5")
Assertions.assertEquals("default", JsonHelper.safeGetStringAllowNull(null, "notexisting", "default")) assertThat(JsonHelper.safeGetStringAllowNull(null, "notexisting", "default")).isEqualTo("default")
Assertions.assertEquals("default", JsonHelper.safeGetStringAllowNull(json, "notexisting", "default")) assertThat(JsonHelper.safeGetStringAllowNull(json, "notexisting", "default")).isEqualTo("default")
Assertions.assertNull(JsonHelper.safeGetStringAllowNull(json, "notexisting", null)) assertThat(JsonHelper.safeGetStringAllowNull(json, "notexisting", null)).isNull()
Assertions.assertEquals("5", JsonHelper.safeGetStringAllowNull(json, "s", "default")) assertThat(JsonHelper.safeGetStringAllowNull(json, "s", "default")).isEqualTo("5")
} }
@Test @Test
fun safeGetDoubleTest() { fun safeGetDoubleTest() {
val json = JSONObject(jsonString) val json = JSONObject(jsonString)
Assertions.assertEquals(0.0, JsonHelper.safeGetDouble(json, "notexisting"), 0.0) assertThat(JsonHelper.safeGetDouble(json, "notexisting")).isWithin(0.0).of(0.0)
Assertions.assertEquals(0.0, JsonHelper.safeGetDouble(null, "notexisting"), 0.0) assertThat(JsonHelper.safeGetDouble(null, "notexisting")).isWithin(0.0).of(0.0)
Assertions.assertEquals(3.0, JsonHelper.safeGetDouble(json, "d"), 0.000001) assertThat(JsonHelper.safeGetDouble(json, "d")).isWithin(0.000001).of(3.0)
Assertions.assertEquals(6.0, JsonHelper.safeGetDouble(null, "notexisting", 6.0), 0.0) assertThat(JsonHelper.safeGetDouble(null, "notexisting", 6.0)).isWithin(0.0).of(6.0)
Assertions.assertEquals(6.0, JsonHelper.safeGetDouble(json, "notexisting", 6.0), 0.0) assertThat(JsonHelper.safeGetDouble(json, "notexisting", 6.0)).isWithin(0.0).of(6.0)
Assertions.assertEquals(3.0, JsonHelper.safeGetDouble(json, "d", 6.0), 0.0) assertThat(JsonHelper.safeGetDouble(json, "d", 6.0)).isWithin(0.0).of(3.0)
} }
@Test @Test
fun safeGetLntTest() { fun safeGetLntTest() {
val json = JSONObject(jsonString) val json = JSONObject(jsonString)
Assertions.assertEquals(0, JsonHelper.safeGetInt(null, "notexisting").toLong()) assertThat(JsonHelper.safeGetInt(null, "notexisting").toLong()).isEqualTo(0)
Assertions.assertEquals(0, JsonHelper.safeGetInt(json, "notexisting").toLong()) assertThat(JsonHelper.safeGetInt(json, "notexisting").toLong()).isEqualTo(0)
Assertions.assertEquals(4, JsonHelper.safeGetInt(json, "i").toLong()) assertThat(JsonHelper.safeGetInt(json, "i").toLong()).isEqualTo(4)
} }
@Test @Test
fun safeGetLongTest() { fun safeGetLongTest() {
val json = JSONObject(jsonString) val json = JSONObject(jsonString)
Assertions.assertEquals(0, JsonHelper.safeGetInt(null, "notexisting").toLong()) assertThat(JsonHelper.safeGetInt(null, "notexisting").toLong()).isEqualTo(0)
Assertions.assertEquals(0, JsonHelper.safeGetInt(json, "notexisting").toLong()) assertThat(JsonHelper.safeGetInt(json, "notexisting").toLong()).isEqualTo(0)
Assertions.assertEquals(4, JsonHelper.safeGetInt(json, "i").toLong()) assertThat(JsonHelper.safeGetInt(json, "i").toLong()).isEqualTo(4)
} }
@Test @Test
fun safeGetBooleanTest() { fun safeGetBooleanTest() {
val json = JSONObject(jsonString) val json = JSONObject(jsonString)
Assertions.assertFalse(JsonHelper.safeGetBoolean(null, "notexisting")) assertThat(JsonHelper.safeGetBoolean(null, "notexisting")).isFalse()
Assertions.assertFalse(JsonHelper.safeGetBoolean(json, "notexisting")) assertThat(JsonHelper.safeGetBoolean(json, "notexisting")).isFalse()
Assertions.assertTrue(JsonHelper.safeGetBoolean(json, "b")) assertThat(JsonHelper.safeGetBoolean(json, "b")).isTrue()
} }
} }

View file

@ -1,41 +1,41 @@
package info.nightscout.core.utils package info.nightscout.core.utils
import com.google.common.truth.Truth.assertThat
import info.nightscout.interfaces.utils.Round import info.nightscout.interfaces.utils.Round
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class RoundTest { class RoundTest {
@Test @Test
fun roundToTest() { fun roundToTest() {
Assertions.assertEquals(0.55, Round.roundTo(0.54, 0.05), 0.00000000000000000001) assertThat(Round.roundTo(0.54, 0.05)).isWithin(0.00000000000000000001).of(0.55)
Assertions.assertEquals(-3.26, Round.roundTo(-3.2553715764602713, 0.01), 0.00000000000000000001) assertThat(Round.roundTo(-3.2553715764602713, 0.01)).isWithin(0.00000000000000000001).of(-3.26)
Assertions.assertEquals(0.816, Round.roundTo(0.8156666666666667, 0.001), 0.00000000000000000001) assertThat(Round.roundTo(0.8156666666666667, 0.001)).isWithin(0.00000000000000000001).of(0.816)
Assertions.assertEquals(0.235, Round.roundTo(0.235, 0.001), 0.00000000000000000001) assertThat(Round.roundTo(0.235, 0.001)).isWithin(0.00000000000000000001).of(0.235)
Assertions.assertEquals(0.3, Round.roundTo(0.3, 0.1), 0.00000000000000001) assertThat(Round.roundTo(0.3, 0.1)).isWithin(0.00000000000000001).of(0.3)
Assertions.assertEquals(0.0017, Round.roundTo(0.0016960652144170627, 0.0001), 0.00000000000000000001) assertThat(Round.roundTo(0.0016960652144170627, 0.0001)).isWithin(0.00000000000000000001).of(0.0017)
Assertions.assertEquals(0.0078, Round.roundTo(0.007804436682291013, 0.0001), 0.00000000000000000001) assertThat(Round.roundTo(0.007804436682291013, 0.0001)).isWithin(0.00000000000000000001).of(0.0078)
Assertions.assertEquals(0.6, Round.roundTo(0.6, 0.05), 0.00000000000000000001) assertThat(Round.roundTo(0.6, 0.05)).isWithin(0.00000000000000000001).of(0.6)
Assertions.assertEquals(1.0, Round.roundTo(1.49, 1.0), 0.00000000000000000001) assertThat(Round.roundTo(1.49, 1.0)).isWithin(0.00000000000000000001).of(1.0)
Assertions.assertEquals(0.0, Round.roundTo(0.0, 1.0), 0.00000000000000000001) assertThat(Round.roundTo(0.0, 1.0)).isWithin(0.00000000000000000001).of(0.0)
} }
@Test @Test
fun floorToTest() { fun floorToTest() {
Assertions.assertEquals(0.5, Round.floorTo(0.54, 0.05), 0.00000001) assertThat(Round.floorTo(0.54, 0.05)).isWithin(0.00000001).of(0.5)
Assertions.assertEquals(1.0, Round.floorTo(1.59, 1.0), 0.00000001) assertThat(Round.floorTo(1.59, 1.0)).isWithin(0.00000001).of(1.0)
Assertions.assertEquals(0.0, Round.floorTo(0.0, 1.0), 0.00000001) assertThat(Round.floorTo(0.0, 1.0)).isWithin(0.00000001).of(0.0)
} }
@Test @Test
fun ceilToTest() { fun ceilToTest() {
Assertions.assertEquals(0.6, Round.ceilTo(0.54, 0.1), 0.00000001) assertThat(Round.ceilTo(0.54, 0.1)).isWithin(0.00000001).of(0.6)
Assertions.assertEquals(2.0, Round.ceilTo(1.49999, 1.0), 0.00000001) assertThat(Round.ceilTo(1.49999, 1.0)).isWithin(0.00000001).of(2.0)
Assertions.assertEquals(0.0, Round.ceilTo(0.0, 1.0), 0.00000001) assertThat(Round.ceilTo(0.0, 1.0)).isWithin(0.00000001).of(0.0)
} }
@Test @Test
fun isSameTest() { fun isSameTest() {
Assertions.assertTrue(Round.isSame(0.54, 0.54)) assertThat(Round.isSame(0.54, 0.54)).isTrue()
} }
} }

View file

@ -1,19 +1,19 @@
package info.nightscout.core.utils package info.nightscout.core.utils
import com.google.common.truth.Truth.assertThat
import info.nightscout.core.utils.receivers.StringUtils import info.nightscout.core.utils.receivers.StringUtils
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class StringUtilsTest { class StringUtilsTest {
@Test fun removeSurroundingQuotesTest() { @Test fun removeSurroundingQuotesTest() {
var compareString = "test" var compareString = "test"
Assertions.assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString)) assertThat(StringUtils.removeSurroundingQuotes(compareString)).isEqualTo(compareString)
Assertions.assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\"")) assertThat(StringUtils.removeSurroundingQuotes("\"" + compareString + "\"")).isEqualTo(compareString)
Assertions.assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString)) assertThat(StringUtils.removeSurroundingQuotes("\"" + compareString)).isEqualTo("\"" + compareString)
compareString = "te\"st" compareString = """te"st"""
Assertions.assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString)) assertThat(StringUtils.removeSurroundingQuotes(compareString)).isEqualTo(compareString)
Assertions.assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\"")) assertThat(StringUtils.removeSurroundingQuotes("\"" + compareString + "\"")).isEqualTo(compareString)
Assertions.assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString)) assertThat(StringUtils.removeSurroundingQuotes("\"" + compareString)).isEqualTo("\"" + compareString)
} }
} }

View file

@ -1,5 +1,6 @@
package info.nightscout.core.wizard package info.nightscout.core.wizard
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.aps.Loop
@ -7,7 +8,6 @@ import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.sharedtests.TestBase import info.nightscout.sharedtests.TestBase
import org.json.JSONArray import org.json.JSONArray
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
@ -55,46 +55,46 @@ class QuickWizardTest : TestBase() {
@Test @Test
fun setDataTest() { fun setDataTest() {
quickWizard.setData(array) quickWizard.setData(array)
Assertions.assertEquals(2, quickWizard.size()) assertThat(quickWizard.size()).isEqualTo(2)
} }
@Test @Test
fun test() { fun test() {
quickWizard.setData(array) quickWizard.setData(array)
Assertions.assertEquals("Lunch", quickWizard[1].buttonText()) assertThat(quickWizard[1].buttonText()).isEqualTo("Lunch")
} }
@Test @Test
fun active() { fun active() {
quickWizard.setData(array) quickWizard.setData(array)
val e: QuickWizardEntry = quickWizard.getActive()!! val e: QuickWizardEntry = quickWizard.getActive()!!
Assertions.assertEquals(36.0, e.carbs().toDouble(), 0.01) assertThat(e.carbs().toDouble()).isWithin(0.01).of(36.0)
quickWizard.remove(0) quickWizard.remove(0)
quickWizard.remove(0) quickWizard.remove(0)
Assertions.assertNull(quickWizard.getActive()) assertThat(quickWizard.getActive()).isNull()
} }
@Test @Test
fun newEmptyItemTest() { fun newEmptyItemTest() {
Assertions.assertNotNull(quickWizard.newEmptyItem()) assertThat(quickWizard.newEmptyItem()).isNotNull()
} }
@Test @Test
fun addOrUpdate() { fun addOrUpdate() {
quickWizard.setData(array) quickWizard.setData(array)
Assertions.assertEquals(2, quickWizard.size()) assertThat(quickWizard.size()).isEqualTo(2)
quickWizard.addOrUpdate(quickWizard.newEmptyItem()) quickWizard.addOrUpdate(quickWizard.newEmptyItem())
Assertions.assertEquals(3, quickWizard.size()) assertThat(quickWizard.size()).isEqualTo(3)
val q: QuickWizardEntry = quickWizard.newEmptyItem() val q: QuickWizardEntry = quickWizard.newEmptyItem()
q.position = 0 q.position = 0
quickWizard.addOrUpdate(q) quickWizard.addOrUpdate(q)
Assertions.assertEquals(3, quickWizard.size()) assertThat(quickWizard.size()).isEqualTo(3)
} }
@Test @Test
fun remove() { fun remove() {
quickWizard.setData(array) quickWizard.setData(array)
quickWizard.remove(0) quickWizard.remove(0)
Assertions.assertEquals(1, quickWizard.size()) assertThat(quickWizard.size()).isEqualTo(1)
} }
} }