shared-tests #15
This commit is contained in:
parent
593af85b57
commit
076fec1929
|
@ -25,4 +25,6 @@ dependencies {
|
|||
implementation project(':core:graph')
|
||||
implementation project(':core:ui')
|
||||
implementation project(':core:utils')
|
||||
|
||||
testImplementation project(':app-wear-shared:shared-tests')
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
package info.nightscout.implementation.profile
|
||||
|
||||
import androidx.collection.ArrayMap
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.core.extensions.pureProfileFromJson
|
||||
import info.nightscout.core.profile.ProfileSealed
|
||||
import info.nightscout.interfaces.Config
|
||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||
import info.nightscout.interfaces.profile.ProfileStore
|
||||
import info.nightscout.interfaces.profile.PureProfile
|
||||
import info.nightscout.interfaces.utils.HardLimits
|
||||
import info.nightscout.interfaces.utils.JsonHelper
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
import info.nightscout.rx.logging.AAPSLogger
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import javax.inject.Inject
|
||||
|
||||
class ProfileStoreObject(val injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore {
|
||||
|
||||
@Inject lateinit var aapsLogger: AAPSLogger
|
||||
@Inject lateinit var activePlugin: ActivePlugin
|
||||
@Inject lateinit var config: Config
|
||||
@Inject lateinit var rh: ResourceHelper
|
||||
@Inject lateinit var rxBus: RxBus
|
||||
@Inject lateinit var hardLimits: HardLimits
|
||||
|
||||
init {
|
||||
injector.androidInjector().inject(this)
|
||||
}
|
||||
|
||||
private val cachedObjects = ArrayMap<String, PureProfile>()
|
||||
|
||||
private fun storeUnits(): String? = JsonHelper.safeGetStringAllowNull(data, "units", null)
|
||||
|
||||
private fun getStore(): JSONObject? {
|
||||
try {
|
||||
if (data.has("store")) return data.getJSONObject("store")
|
||||
} catch (e: JSONException) {
|
||||
aapsLogger.error("Unhandled exception", e)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getStartDate(): Long {
|
||||
val iso = JsonHelper.safeGetString(data, "created_at") ?: JsonHelper.safeGetString(data, "startDate") ?: return 0
|
||||
return try {
|
||||
dateUtil.fromISODateString(iso)
|
||||
} catch (e: Exception) {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) }
|
||||
override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) }
|
||||
|
||||
override fun getDefaultProfileName(): String? {
|
||||
val defaultProfileName = data.optString("defaultProfile")
|
||||
return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null
|
||||
}
|
||||
|
||||
override fun getProfileList(): ArrayList<CharSequence> {
|
||||
val ret = ArrayList<CharSequence>()
|
||||
getStore()?.keys()?.let { keys ->
|
||||
while (keys.hasNext()) {
|
||||
val profileName = keys.next() as String
|
||||
ret.add(profileName)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun getSpecificProfile(profileName: String): PureProfile? {
|
||||
var profile: PureProfile? = null
|
||||
val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits())
|
||||
getStore()?.let { store ->
|
||||
if (store.has(profileName)) {
|
||||
profile = cachedObjects[profileName]
|
||||
if (profile == null) {
|
||||
JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject ->
|
||||
profile = pureProfileFromJson(profileObject, dateUtil, units)
|
||||
profile?.let { cachedObjects[profileName] = profile }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return profile
|
||||
}
|
||||
|
||||
private fun getSpecificProfileJson(profileName: String): JSONObject? {
|
||||
getStore()?.let { store ->
|
||||
if (store.has(profileName))
|
||||
return JsonHelper.safeGetJSONObject(store, profileName, null)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override val allProfilesValid: Boolean
|
||||
get() = getProfileList()
|
||||
.asSequence()
|
||||
.map { profileName -> getSpecificProfile(profileName.toString()) }
|
||||
.map { pureProfile -> pureProfile?.let { ProfileSealed.Pure(pureProfile).isValid("allProfilesValid", activePlugin.activePump, config, rh, rxBus, hardLimits, false) } }
|
||||
.all { it?.isValid == true }
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package info.nightscout.androidaps
|
||||
|
||||
import info.nightscout.rx.AapsSchedulers
|
||||
import info.nightscout.rx.TestAapsSchedulers
|
||||
import info.nightscout.rx.logging.AAPSLoggerTest
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.junit.jupiter.MockitoExtension
|
||||
import org.mockito.junit.jupiter.MockitoSettings
|
||||
import org.mockito.quality.Strictness
|
||||
import java.util.Locale
|
||||
|
||||
@ExtendWith(MockitoExtension::class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
open class TestBase {
|
||||
|
||||
val aapsLogger = AAPSLoggerTest()
|
||||
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
|
||||
|
||||
@BeforeEach
|
||||
fun setupLocale() {
|
||||
Locale.setDefault(Locale.ENGLISH)
|
||||
System.setProperty("disableFirebase", "true")
|
||||
}
|
||||
|
||||
// Workaround for Kotlin nullability.
|
||||
// https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
|
||||
// https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin
|
||||
fun <T> anyObject(): T {
|
||||
Mockito.any<T>()
|
||||
return uninitialized()
|
||||
}
|
||||
|
||||
@Suppress("Unchecked_Cast")
|
||||
fun <T> uninitialized(): T = null as T
|
||||
}
|
|
@ -1,178 +0,0 @@
|
|||
package info.nightscout.androidaps
|
||||
|
||||
import android.content.Context
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.core.extensions.pureProfileFromJson
|
||||
import info.nightscout.core.profile.ProfileSealed
|
||||
import info.nightscout.core.utils.fabric.FabricPrivacy
|
||||
import info.nightscout.database.entities.EffectiveProfileSwitch
|
||||
import info.nightscout.database.entities.embedments.InsulinConfiguration
|
||||
import info.nightscout.implementation.profile.ProfileStoreObject
|
||||
import info.nightscout.interfaces.Config
|
||||
import info.nightscout.interfaces.iob.IobCobCalculator
|
||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||
import info.nightscout.interfaces.profile.ProfileFunction
|
||||
import info.nightscout.interfaces.profile.ProfileStore
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import org.json.JSONObject
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.mockito.ArgumentMatchers.anyDouble
|
||||
import org.mockito.ArgumentMatchers.anyInt
|
||||
import org.mockito.ArgumentMatchers.anyString
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.invocation.InvocationOnMock
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
open class TestBaseWithProfile : TestBase() {
|
||||
|
||||
@Mock lateinit var activePluginProvider: ActivePlugin
|
||||
@Mock lateinit var rh: ResourceHelper
|
||||
@Mock lateinit var iobCobCalculator: IobCobCalculator
|
||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var config: Config
|
||||
@Mock lateinit var context: Context
|
||||
|
||||
lateinit var dateUtil: DateUtil
|
||||
val rxBus = RxBus(aapsSchedulers, aapsLogger)
|
||||
|
||||
val profileInjector = HasAndroidInjector { AndroidInjector { } }
|
||||
|
||||
private lateinit var validProfileJSON: String
|
||||
lateinit var validProfile: ProfileSealed.Pure
|
||||
lateinit var effectiveProfileSwitch: EffectiveProfileSwitch
|
||||
|
||||
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
|
||||
|
||||
@BeforeEach
|
||||
fun prepareMock() {
|
||||
validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
|
||||
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +
|
||||
"\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
||||
dateUtil = Mockito.spy(DateUtil(context))
|
||||
`when`(dateUtil.now()).thenReturn(1656358822000)
|
||||
validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!)
|
||||
effectiveProfileSwitch = EffectiveProfileSwitch(
|
||||
timestamp = dateUtil.now(),
|
||||
basalBlocks = validProfile.basalBlocks,
|
||||
isfBlocks = validProfile.isfBlocks,
|
||||
icBlocks = validProfile.icBlocks,
|
||||
targetBlocks = validProfile.targetBlocks,
|
||||
glucoseUnit = EffectiveProfileSwitch.GlucoseUnit.MMOL,
|
||||
originalProfileName = "",
|
||||
originalCustomizedName = "",
|
||||
originalTimeshift = 0,
|
||||
originalPercentage = 100,
|
||||
originalDuration = 0,
|
||||
originalEnd = 0,
|
||||
insulinConfiguration = InsulinConfiguration("", 0, 0)
|
||||
)
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Int?>(1)
|
||||
String.format(rh.gs(string), arg1)
|
||||
}.`when`(rh).gs(anyInt(), anyInt())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Double?>(1)
|
||||
String.format(rh.gs(string), arg1)
|
||||
}.`when`(rh).gs(anyInt(), anyDouble())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<String?>(1)
|
||||
String.format(rh.gs(string), arg1)
|
||||
}.`when`(rh).gs(anyInt(), anyString())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<String?>(1)
|
||||
val arg2 = invocation.getArgument<String?>(2)
|
||||
String.format(rh.gs(string), arg1, arg2)
|
||||
}.`when`(rh).gs(anyInt(), anyString(), anyString())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<String?>(1)
|
||||
val arg2 = invocation.getArgument<Int?>(2)
|
||||
String.format(rh.gs(string), arg1, arg2)
|
||||
}.`when`(rh).gs(anyInt(), anyString(), anyInt())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Double?>(1)
|
||||
val arg2 = invocation.getArgument<String?>(2)
|
||||
String.format(rh.gs(string), arg1, arg2)
|
||||
}.`when`(rh).gs(anyInt(), anyDouble(), anyString())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Double?>(1)
|
||||
val arg2 = invocation.getArgument<Int?>(2)
|
||||
String.format(rh.gs(string), arg1, arg2)
|
||||
}.`when`(rh).gs(anyInt(), anyDouble(), anyInt())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Int?>(1)
|
||||
val arg2 = invocation.getArgument<Int?>(2)
|
||||
String.format(rh.gs(string), arg1, arg2)
|
||||
}.`when`(rh).gs(anyInt(), anyInt(), anyInt())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Int?>(1)
|
||||
val arg2 = invocation.getArgument<String?>(2)
|
||||
String.format(rh.gs(string), arg1, arg2)
|
||||
}.`when`(rh).gs(anyInt(), anyInt(), anyString())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Int?>(1)
|
||||
val arg2 = invocation.getArgument<Int?>(2)
|
||||
val arg3 = invocation.getArgument<String?>(3)
|
||||
String.format(rh.gs(string), arg1, arg2, arg3)
|
||||
}.`when`(rh).gs(anyInt(), anyInt(), anyInt(), anyString())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Int?>(1)
|
||||
val arg2 = invocation.getArgument<String?>(2)
|
||||
val arg3 = invocation.getArgument<String?>(3)
|
||||
String.format(rh.gs(string), arg1, arg2, arg3)
|
||||
}.`when`(rh).gs(anyInt(), anyInt(), anyString(), anyString())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Double?>(1)
|
||||
val arg2 = invocation.getArgument<Int?>(2)
|
||||
val arg3 = invocation.getArgument<String?>(3)
|
||||
String.format(rh.gs(string), arg1, arg2, arg3)
|
||||
}.`when`(rh).gs(anyInt(), anyDouble(), anyInt(), anyString())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<String?>(1)
|
||||
val arg2 = invocation.getArgument<Int?>(2)
|
||||
val arg3 = invocation.getArgument<String?>(3)
|
||||
String.format(rh.gs(string), arg1, arg2, arg3)
|
||||
}.`when`(rh).gs(anyInt(), anyString(), anyInt(), anyString())
|
||||
|
||||
}
|
||||
|
||||
fun getValidProfileStore(): ProfileStore {
|
||||
val json = JSONObject()
|
||||
val store = JSONObject()
|
||||
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
|
||||
json.put("defaultProfile", TESTPROFILENAME)
|
||||
json.put("store", store)
|
||||
return ProfileStoreObject(profileInjector, json, dateUtil)
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
package info.nightscout.androidaps
|
||||
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.interfaces.profile.Profile
|
||||
import info.nightscout.interfaces.pump.DetailedBolusInfo
|
||||
import info.nightscout.interfaces.pump.Pump
|
||||
import info.nightscout.interfaces.pump.PumpEnactResult
|
||||
import info.nightscout.interfaces.pump.PumpSync
|
||||
import info.nightscout.interfaces.pump.defs.ManufacturerType
|
||||
import info.nightscout.interfaces.pump.defs.PumpDescription
|
||||
import info.nightscout.interfaces.pump.defs.PumpType
|
||||
import info.nightscout.interfaces.utils.TimeChangeType
|
||||
import org.json.JSONObject
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
class TestPumpPlugin(val injector: HasAndroidInjector) : Pump {
|
||||
|
||||
var connected = false
|
||||
var isProfileSet = true
|
||||
|
||||
override fun isConnected() = connected
|
||||
override fun isConnecting() = false
|
||||
override fun isHandshakeInProgress() = false
|
||||
val lastData = 0L
|
||||
|
||||
val baseBasal = 0.0
|
||||
override val pumpDescription = PumpDescription()
|
||||
|
||||
override fun isInitialized(): Boolean = true
|
||||
override fun isSuspended(): Boolean = false
|
||||
override fun isBusy(): Boolean = false
|
||||
override fun connect(reason: String) {
|
||||
connected = true
|
||||
}
|
||||
|
||||
override fun disconnect(reason: String) {
|
||||
connected = false
|
||||
}
|
||||
|
||||
override fun stopConnecting() {
|
||||
connected = false
|
||||
}
|
||||
|
||||
override fun waitForDisconnectionInSeconds(): Int = 0
|
||||
override fun getPumpStatus(reason: String) {}
|
||||
override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector)
|
||||
override fun isThisProfileSet(profile: Profile): Boolean = isProfileSet
|
||||
override fun lastDataTime(): Long = lastData
|
||||
override val baseBasalRate: Double = baseBasal
|
||||
override val reservoirLevel: Double = 0.0
|
||||
override val batteryLevel: Int = 0
|
||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||
override fun stopBolusDelivering() {}
|
||||
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult =
|
||||
PumpEnactResult(injector).success(true)
|
||||
|
||||
override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult =
|
||||
PumpEnactResult(injector).success(true)
|
||||
|
||||
override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||
override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||
override fun cancelExtendedBolus(): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||
override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject = JSONObject()
|
||||
override fun manufacturer(): ManufacturerType = ManufacturerType.AAPS
|
||||
override fun model(): PumpType = PumpType.GENERIC_AAPS
|
||||
override fun serialNumber(): String = "1"
|
||||
override fun shortStatus(veryShort: Boolean): String = ""
|
||||
override val isFakingTempsByExtendedBoluses: Boolean = false
|
||||
override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||
override fun canHandleDST(): Boolean = true
|
||||
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package info.nightscout.ui.defaultProfile
|
||||
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.core.profile.ProfileSealed
|
||||
import info.nightscout.interfaces.GlucoseUnit
|
||||
import org.junit.Assert.assertEquals
|
||||
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class DefaultProfileTest : TestBaseWithProfile() {
|
||||
|
@ -12,18 +12,18 @@ class DefaultProfileTest : TestBaseWithProfile() {
|
|||
fun profile() {
|
||||
val dp = DefaultProfile(dateUtil).profile(5, 5.1 / 0.3, 0.0, GlucoseUnit.MMOL)
|
||||
var p = ProfileSealed.Pure(dp!!)
|
||||
assertEquals(0.150, p.getBasalTimeFromMidnight(0), 0.001)
|
||||
assertEquals(15.0, p.getIcTimeFromMidnight(0), 0.001)
|
||||
assertEquals(11.8, p.getIsfTimeFromMidnight(0), 0.001)
|
||||
Assertions.assertEquals(0.150, p.getBasalTimeFromMidnight(0), 0.001)
|
||||
Assertions.assertEquals(15.0, p.getIcTimeFromMidnight(0), 0.001)
|
||||
Assertions.assertEquals(11.8, p.getIsfTimeFromMidnight(0), 0.001)
|
||||
|
||||
p = ProfileSealed.Pure(DefaultProfile(dateUtil).profile(7, 10.0 / 0.4, 0.0, GlucoseUnit.MMOL)!!)
|
||||
assertEquals(0.350, p.getBasalTimeFromMidnight(0), 0.001)
|
||||
assertEquals(15.0, p.getIcTimeFromMidnight(0), 0.001)
|
||||
assertEquals(6.8, p.getIsfTimeFromMidnight(0), 0.001)
|
||||
Assertions.assertEquals(0.350, p.getBasalTimeFromMidnight(0), 0.001)
|
||||
Assertions.assertEquals(15.0, p.getIcTimeFromMidnight(0), 0.001)
|
||||
Assertions.assertEquals(6.8, p.getIsfTimeFromMidnight(0), 0.001)
|
||||
|
||||
p = ProfileSealed.Pure(DefaultProfile(dateUtil).profile(12, 25.0 / 0.5, 0.0, GlucoseUnit.MMOL)!!)
|
||||
assertEquals(0.80, p.getBasalTimeFromMidnight(0), 0.001)
|
||||
assertEquals(10.0, p.getIcTimeFromMidnight(0), 0.001)
|
||||
assertEquals(2.2, p.getIsfTimeFromMidnight(0), 0.001)
|
||||
Assertions.assertEquals(0.80, p.getBasalTimeFromMidnight(0), 0.001)
|
||||
Assertions.assertEquals(10.0, p.getIcTimeFromMidnight(0), 0.001)
|
||||
Assertions.assertEquals(2.2, p.getIsfTimeFromMidnight(0), 0.001)
|
||||
}
|
||||
}
|
|
@ -105,6 +105,7 @@ dependencies {
|
|||
implementation 'androidx.wear:wear:1.3.0'
|
||||
implementation 'androidx.wear.tiles:tiles:1.1.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
testImplementation project(':app-wear-shared:shared-tests')
|
||||
|
||||
compileOnly "com.google.android.wearable:wearable:$wearable_version"
|
||||
implementation "com.google.android.support:wearable:$wearable_version"
|
||||
|
|
|
@ -6,32 +6,22 @@ import info.nightscout.androidaps.interaction.utils.Persistence
|
|||
import info.nightscout.androidaps.interaction.utils.WearUtil
|
||||
import info.nightscout.androidaps.testing.mockers.WearUtilMocker
|
||||
import info.nightscout.androidaps.testing.mocks.SharedPreferencesMock
|
||||
import info.nightscout.rx.logging.AAPSLoggerTest
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import org.junit.Before
|
||||
import info.nightscout.sharedtests.TestBase
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.junit.jupiter.MockitoExtension
|
||||
import org.mockito.junit.jupiter.MockitoSettings
|
||||
import org.mockito.quality.Strictness
|
||||
import java.util.Locale
|
||||
|
||||
@ExtendWith(MockitoExtension::class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
open class TestBase {
|
||||
open class WearTestBase : TestBase() {
|
||||
|
||||
@Mock lateinit var context: Context
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var dateUtil: DateUtil
|
||||
@Mock lateinit var wearUtil: WearUtil
|
||||
|
||||
val aapsLogger = AAPSLoggerTest()
|
||||
|
||||
//val wearUtil: WearUtil = Mockito.mock(WearUtil::class.java)
|
||||
lateinit var wearUtilMocker: WearUtilMocker
|
||||
lateinit var persistence: Persistence
|
||||
|
@ -60,21 +50,4 @@ open class TestBase {
|
|||
persistence = Mockito.spy(Persistence(aapsLogger, dateUtil, sp))
|
||||
|
||||
}
|
||||
|
||||
@Before
|
||||
fun setupLocale() {
|
||||
Locale.setDefault(Locale.ENGLISH)
|
||||
System.setProperty("disableFirebase", "true")
|
||||
}
|
||||
|
||||
// Workaround for Kotlin nullability.
|
||||
// https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
|
||||
// https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin
|
||||
fun <T> anyObject(): T {
|
||||
Mockito.any<T>()
|
||||
return uninitialized()
|
||||
}
|
||||
|
||||
@Suppress("Unchecked_Cast")
|
||||
fun <T> uninitialized(): T = null as T
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
package info.nightscout.androidaps.interaction.utils
|
||||
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.WearTestBase
|
||||
import info.nightscout.androidaps.data.RawDisplayData
|
||||
import info.nightscout.androidaps.testing.mockers.RawDataMocker
|
||||
import org.junit.Assert
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.Mockito
|
||||
|
@ -13,7 +13,7 @@ import org.mockito.Mockito
|
|||
* This test covers DisplayFormat class (directly)
|
||||
* but also SmallestDoubleString - due to carefully chosen input data to format
|
||||
*/
|
||||
class DisplayFormatTest : TestBase() {
|
||||
class DisplayFormatTest : WearTestBase() {
|
||||
|
||||
private lateinit var displayFormat: DisplayFormat
|
||||
private lateinit var rawDataMocker: RawDataMocker
|
||||
|
@ -33,142 +33,142 @@ class DisplayFormatTest : TestBase() {
|
|||
}
|
||||
|
||||
@Test fun shortTimeSinceTest() {
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 0, 0)), "0'")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 0, 5)), "0'")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 0, 55)), "0'")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 1, 0)), "1'")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 1, 59)), "1'")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 2, 0)), "2'")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 3, 0)), "3'")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 4, 0)), "4'")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 10, 0)), "10'")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 30, 0)), "30'")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 59, 0)), "59'")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 59, 59)), "59'")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 1, 0, 0)), "1h")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 1, 30, 0)), "1h")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 1, 59, 59)), "1h")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 2, 0, 0)), "2h")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 3, 0, 0)), "3h")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 4, 0, 0)), "4h")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 5, 0, 0)), "5h")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 12, 0, 0)), "12h")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 18, 0, 0)), "18h")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 23, 59, 59)), "23h")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(1, 0, 0, 0)), "1d")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(1, 12, 0, 0)), "1d")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(1, 23, 59, 59)), "1d")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(2, 0, 0, 0)), "2d")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(3, 0, 0, 0)), "3d")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(4, 0, 0, 0)), "4d")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(5, 0, 0, 0)), "5d")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(6, 0, 0, 0)), "6d")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(6, 23, 59, 59)), "6d")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(7, 0, 0, 0)), "1w")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(8, 0, 0, 0)), "1w")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(9, 0, 0, 0)), "1w")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(13, 23, 59, 59)), "1w")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(14, 0, 0, 0)), "2w")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(21, 0, 0, 0)), "3w")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(28, 0, 0, 0)), "4w")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(31, 0, 0, 0)), "4w")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(32, 0, 0, 0)), "4w")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(35, 0, 0, 0)), "5w")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(100, 0, 0, 0)), "14w")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(200, 0, 0, 0)), "28w")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(365, 0, 0, 0)), "52w")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(366, 0, 0, 0)), "52w")
|
||||
Assert.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(367, 0, 0, 0)), "52w")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 0, 0)), "0'")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 0, 5)), "0'")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 0, 55)), "0'")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 1, 0)), "1'")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 1, 59)), "1'")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 2, 0)), "2'")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 3, 0)), "3'")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 4, 0)), "4'")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 10, 0)), "10'")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 30, 0)), "30'")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 59, 0)), "59'")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 0, 59, 59)), "59'")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 1, 0, 0)), "1h")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 1, 30, 0)), "1h")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 1, 59, 59)), "1h")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 2, 0, 0)), "2h")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 3, 0, 0)), "3h")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 4, 0, 0)), "4h")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 5, 0, 0)), "5h")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 12, 0, 0)), "12h")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 18, 0, 0)), "18h")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(0, 23, 59, 59)), "23h")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(1, 0, 0, 0)), "1d")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(1, 12, 0, 0)), "1d")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(1, 23, 59, 59)), "1d")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(2, 0, 0, 0)), "2d")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(3, 0, 0, 0)), "3d")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(4, 0, 0, 0)), "4d")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(5, 0, 0, 0)), "5d")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(6, 0, 0, 0)), "6d")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(6, 23, 59, 59)), "6d")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(7, 0, 0, 0)), "1w")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(8, 0, 0, 0)), "1w")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(9, 0, 0, 0)), "1w")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(13, 23, 59, 59)), "1w")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(14, 0, 0, 0)), "2w")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(21, 0, 0, 0)), "3w")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(28, 0, 0, 0)), "4w")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(31, 0, 0, 0)), "4w")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(32, 0, 0, 0)), "4w")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(35, 0, 0, 0)), "5w")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(100, 0, 0, 0)), "14w")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(200, 0, 0, 0)), "28w")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(365, 0, 0, 0)), "52w")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(366, 0, 0, 0)), "52w")
|
||||
Assertions.assertEquals(displayFormat.shortTimeSince(wearUtilMocker.backInTime(367, 0, 0, 0)), "52w")
|
||||
}
|
||||
|
||||
@Test fun shortTrendTest() {
|
||||
val raw = RawDisplayData()
|
||||
Assert.assertEquals(displayFormat.shortTrend(raw), "-- Δ--")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(raw), "-- Δ--")
|
||||
raw.singleBg.timeStamp = wearUtilMocker.backInTime(0, 0, 2, 0)
|
||||
Assert.assertEquals(displayFormat.shortTrend(raw), "2' Δ--")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(raw), "2' Δ--")
|
||||
Mockito.`when`(sp.getBoolean("complication_unicode", true)).thenReturn(true)
|
||||
|
||||
// shortening
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(2, "1.2")), "2' Δ1.2")
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(11, "1.2")), "11' 1.2")
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(12, "0.7")), "12' Δ.7")
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(10, "1.0")), "10' Δ1")
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(14, "-5.0")), "14' Δ-5")
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(13, "-5.1")), "13' -5")
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(15, "0.87")), "15' .87")
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(10, "-1.78")), "10' -2")
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(3, "2.549")), "3' 2.55")
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(1, "-1.563")), "1' -1.6")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(2, "1.2")), "2' Δ1.2")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(11, "1.2")), "11' 1.2")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(12, "0.7")), "12' Δ.7")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(10, "1.0")), "10' Δ1")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(14, "-5.0")), "14' Δ-5")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(13, "-5.1")), "13' -5")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(15, "0.87")), "15' .87")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(10, "-1.78")), "10' -2")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(3, "2.549")), "3' 2.55")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(1, "-1.563")), "1' -1.6")
|
||||
|
||||
// preserving separator
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(2, "1,2")), "2' Δ1,2")
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(15, "0,87")), "15' ,87")
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(3, "+2,549")), "3' 2,55")
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(1, "-1,563")), "1' -1,6")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(2, "1,2")), "2' Δ1,2")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(15, "0,87")), "15' ,87")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(3, "+2,549")), "3' 2,55")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(1, "-1,563")), "1' -1,6")
|
||||
|
||||
// UTF-off mode - without delta symbol
|
||||
Mockito.`when`(sp.getBoolean("complication_unicode", true)).thenReturn(false)
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(2, "1.2")), "2' 1.2")
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(12, "0.7")), "12' 0.7")
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(10, "1.0")), "10' 1.0")
|
||||
Assert.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(14, "-5.0")), "14' -5")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(2, "1.2")), "2' 1.2")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(12, "0.7")), "12' 0.7")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(10, "1.0")), "10' 1.0")
|
||||
Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(14, "-5.0")), "14' -5")
|
||||
}
|
||||
|
||||
@Test fun longGlucoseLine() {
|
||||
Assert.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("125", 2, "1.2")), "125→ Δ1.2 (2')")
|
||||
Assert.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("97", 11, "5.2")), "97↗ Δ5.2 (11')")
|
||||
Assert.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("110", 12, "0.7")), "110→ Δ.7 (12')")
|
||||
Assert.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("65", 10, "7.0")), "65↗ Δ7 (10')")
|
||||
Assert.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("215", 14, "-5.0")), "215↘ Δ-5 (14')")
|
||||
Assert.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("8.3", 13, "-5.1")), "8.3↘ Δ-5.1 (13')")
|
||||
Assert.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("6.8", 15, "10.83")), "6.8↑ Δ10.83 (15')")
|
||||
Assert.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("13.2", 10, "-11.78")), "13.2↓ Δ-11.78 (10')")
|
||||
Assert.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("3.9", 3, "2.549")), "3.9→ Δ2.549 (3')")
|
||||
Assert.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("11.1", 1, "-15.563")), "11.1↓ Δ-15.563 (1')")
|
||||
Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("125", 2, "1.2")), "125→ Δ1.2 (2')")
|
||||
Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("97", 11, "5.2")), "97↗ Δ5.2 (11')")
|
||||
Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("110", 12, "0.7")), "110→ Δ.7 (12')")
|
||||
Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("65", 10, "7.0")), "65↗ Δ7 (10')")
|
||||
Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("215", 14, "-5.0")), "215↘ Δ-5 (14')")
|
||||
Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("8.3", 13, "-5.1")), "8.3↘ Δ-5.1 (13')")
|
||||
Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("6.8", 15, "10.83")), "6.8↑ Δ10.83 (15')")
|
||||
Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("13.2", 10, "-11.78")), "13.2↓ Δ-11.78 (10')")
|
||||
Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("3.9", 3, "2.549")), "3.9→ Δ2.549 (3')")
|
||||
Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("11.1", 1, "-15.563")), "11.1↓ Δ-15.563 (1')")
|
||||
}
|
||||
|
||||
@Test fun longDetailsLineTest() {
|
||||
Mockito.`when`(sp.getBoolean("complication_unicode", true)).thenReturn(true)
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("0g", "0U", "3.5U/h")), "0g ⁞ 0U ⁞ ⎍ 3.5U/h")
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("50g", "7.56U", "0%")), "50g ⁞ 7.56U ⁞ ⎍ 0%")
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("12g", "3.23U", "120%")), "12g ⁞ 3.23U ⁞ 120%")
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("2(40)g", "-1.5U", "0.55U/h")), "2(40)g ⁞ -2U ⁞ 0.55U/h")
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("0(24)g", "0.05U", "160%")), "0(24)g ⁞ 0.05U ⁞ 160%")
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("47g", "13.87U", "220%")), "47g ⁞ 13.87U ⁞ 220%")
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("13(5)g", "5.90U", "300%")), "13(5)g ⁞ 5.90U ⁞ 300%")
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("11(50)g", "0U", "70%")), "11(50)g ⁞ 0U ⁞ 70%")
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("7g", "0.54U", "30%")), "7g ⁞ 0.54U ⁞ ⎍ 30%")
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("19(38)g", "35.545U", "12.9U/h")), "19g ⁞ 36U ⁞ 12.9U/h")
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("100(1)g", "12.345U", "6.98647U/h")), "100g 12U 6.98647U/h")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("0g", "0U", "3.5U/h")), "0g ⁞ 0U ⁞ ⎍ 3.5U/h")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("50g", "7.56U", "0%")), "50g ⁞ 7.56U ⁞ ⎍ 0%")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("12g", "3.23U", "120%")), "12g ⁞ 3.23U ⁞ 120%")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("2(40)g", "-1.5U", "0.55U/h")), "2(40)g ⁞ -2U ⁞ 0.55U/h")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("0(24)g", "0.05U", "160%")), "0(24)g ⁞ 0.05U ⁞ 160%")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("47g", "13.87U", "220%")), "47g ⁞ 13.87U ⁞ 220%")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("13(5)g", "5.90U", "300%")), "13(5)g ⁞ 5.90U ⁞ 300%")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("11(50)g", "0U", "70%")), "11(50)g ⁞ 0U ⁞ 70%")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("7g", "0.54U", "30%")), "7g ⁞ 0.54U ⁞ ⎍ 30%")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("19(38)g", "35.545U", "12.9U/h")), "19g ⁞ 36U ⁞ 12.9U/h")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("100(1)g", "12.345U", "6.98647U/h")), "100g 12U 6.98647U/h")
|
||||
Mockito.`when`(sp.getBoolean("complication_unicode", true)).thenReturn(false)
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("0g", "0U", "3.5U/h")), "0g | 0U | 3.5U/h")
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("50g", "7.56U", "0%")), "50g | 7.56U | 0%")
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("12g", "3.23U", "120%")), "12g | 3.23U | 120%")
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("7g", "0.54U", "30%")), "7g | 0.54U | 30%")
|
||||
Assert.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("19(38)g", "35.545U", "12.9U/h")), "19g | 36U | 12.9U/h")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("0g", "0U", "3.5U/h")), "0g | 0U | 3.5U/h")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("50g", "7.56U", "0%")), "50g | 7.56U | 0%")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("12g", "3.23U", "120%")), "12g | 3.23U | 120%")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("7g", "0.54U", "30%")), "7g | 0.54U | 30%")
|
||||
Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("19(38)g", "35.545U", "12.9U/h")), "19g | 36U | 12.9U/h")
|
||||
}
|
||||
|
||||
@Test fun detailedIobTest() {
|
||||
Assert.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-1.29U", "(0,910|-2,20)")), Pair.create("-1.29U", ",91 -2"))
|
||||
Assert.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("3.50U", "")), Pair.create("3.50U", ""))
|
||||
Assert.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("12.5U", "(+1,4|-4.78)")), Pair.create("12.5U", "1,4 -5"))
|
||||
Assert.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("0.67U", "some junks")), Pair.create(".67U", ""))
|
||||
Assert.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-11.0U", "(broken|data)")), Pair.create("-11U", "-- --"))
|
||||
Assert.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("5.52U", "(0,5439|wrong)")), Pair.create("5.52U", ",54 --"))
|
||||
Assert.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-8.1U", "(|-8,1)")), Pair.create("-8.1U", "-- -8"))
|
||||
Assert.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-8.1U", "(|-8,1)")), Pair.create("-8.1U", "-- -8"))
|
||||
Assert.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("7.6U", "(malformed)")), Pair.create("7.6U", ""))
|
||||
Assert.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-4.26U", "(6,97|1,3422|too much)")), Pair.create("-4.26U", "7 1,3"))
|
||||
Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-1.29U", "(0,910|-2,20)")), Pair.create("-1.29U", ",91 -2"))
|
||||
Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("3.50U", "")), Pair.create("3.50U", ""))
|
||||
Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("12.5U", "(+1,4|-4.78)")), Pair.create("12.5U", "1,4 -5"))
|
||||
Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("0.67U", "some junks")), Pair.create(".67U", ""))
|
||||
Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-11.0U", "(broken|data)")), Pair.create("-11U", "-- --"))
|
||||
Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("5.52U", "(0,5439|wrong)")), Pair.create("5.52U", ",54 --"))
|
||||
Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-8.1U", "(|-8,1)")), Pair.create("-8.1U", "-- -8"))
|
||||
Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-8.1U", "(|-8,1)")), Pair.create("-8.1U", "-- -8"))
|
||||
Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("7.6U", "(malformed)")), Pair.create("7.6U", ""))
|
||||
Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-4.26U", "(6,97|1,3422|too much)")), Pair.create("-4.26U", "7 1,3"))
|
||||
}
|
||||
|
||||
@Test fun detailedCobTest() {
|
||||
Assert.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("0g")), Pair.create("0g", ""))
|
||||
Assert.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("50g")), Pair.create("50g", ""))
|
||||
Assert.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("2(40)g")), Pair.create("2g", "40g"))
|
||||
Assert.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("0(24)g")), Pair.create("0g", "24g"))
|
||||
Assert.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("13(5)g")), Pair.create("13g", "5g"))
|
||||
Assert.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("11(50)g")), Pair.create("11g", "50g"))
|
||||
Assert.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("19(38)g")), Pair.create("19g", "38g"))
|
||||
Assert.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("100(1)g")), Pair.create("100g", "1g"))
|
||||
Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("0g")), Pair.create("0g", ""))
|
||||
Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("50g")), Pair.create("50g", ""))
|
||||
Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("2(40)g")), Pair.create("2g", "40g"))
|
||||
Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("0(24)g")), Pair.create("0g", "24g"))
|
||||
Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("13(5)g")), Pair.create("13g", "5g"))
|
||||
Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("11(50)g")), Pair.create("11g", "50g"))
|
||||
Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("19(38)g")), Pair.create("19g", "38g"))
|
||||
Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("100(1)g")), Pair.create("100g", "1g"))
|
||||
}
|
||||
}
|
|
@ -1,26 +1,26 @@
|
|||
package info.nightscout.androidaps.interaction.utils
|
||||
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.WearTestBase
|
||||
import info.nightscout.androidaps.testing.mockers.WearUtilMocker
|
||||
import org.junit.Assert
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
/**
|
||||
* Created by dlvoy on 22.11.2019.
|
||||
*/
|
||||
@Suppress("SpellCheckingInspection")
|
||||
class WearUtilTest : TestBase() {
|
||||
class WearUtilTest : WearTestBase() {
|
||||
|
||||
@Test fun timestampAndTimeDiffsTest() {
|
||||
|
||||
// smoke for mocks - since we freeze "now" to get stable tests
|
||||
Assert.assertEquals(WearUtilMocker.REF_NOW, wearUtil.timestamp())
|
||||
Assert.assertEquals(0L, wearUtil.msTill(WearUtilMocker.REF_NOW))
|
||||
Assert.assertEquals(3456L, wearUtil.msTill(WearUtilMocker.REF_NOW + 3456L))
|
||||
Assert.assertEquals(-6294L, wearUtil.msTill(WearUtilMocker.REF_NOW - 6294L))
|
||||
Assert.assertEquals(0L, wearUtil.msTill(WearUtilMocker.REF_NOW))
|
||||
Assert.assertEquals(-3456L, wearUtil.msSince(WearUtilMocker.REF_NOW + 3456L))
|
||||
Assert.assertEquals(6294L, wearUtil.msSince(WearUtilMocker.REF_NOW - 6294L))
|
||||
Assertions.assertEquals(WearUtilMocker.REF_NOW, wearUtil.timestamp())
|
||||
Assertions.assertEquals(0L, wearUtil.msTill(WearUtilMocker.REF_NOW))
|
||||
Assertions.assertEquals(3456L, wearUtil.msTill(WearUtilMocker.REF_NOW + 3456L))
|
||||
Assertions.assertEquals(-6294L, wearUtil.msTill(WearUtilMocker.REF_NOW - 6294L))
|
||||
Assertions.assertEquals(0L, wearUtil.msTill(WearUtilMocker.REF_NOW))
|
||||
Assertions.assertEquals(-3456L, wearUtil.msSince(WearUtilMocker.REF_NOW + 3456L))
|
||||
Assertions.assertEquals(6294L, wearUtil.msSince(WearUtilMocker.REF_NOW - 6294L))
|
||||
}
|
||||
|
||||
@Test fun joinSetTest() {
|
||||
|
@ -36,10 +36,10 @@ class WearUtilTest : TestBase() {
|
|||
// THEN
|
||||
// we cannot guarantee order of items in joined string
|
||||
// but all items have to be there
|
||||
Assert.assertEquals(joined.length, "element1".length + "second-elem".length + "3rd".length + "|".length * 2)
|
||||
Assert.assertTrue("|$joined|".contains("|" + "element1" + "|"))
|
||||
Assert.assertTrue("|$joined|".contains("|" + "second-elem" + "|"))
|
||||
Assert.assertTrue("|$joined|".contains("|" + "3rd" + "|"))
|
||||
Assertions.assertEquals(joined.length, "element1".length + "second-elem".length + "3rd".length + "|".length * 2)
|
||||
Assertions.assertTrue("|$joined|".contains("|" + "element1" + "|"))
|
||||
Assertions.assertTrue("|$joined|".contains("|" + "second-elem" + "|"))
|
||||
Assertions.assertTrue("|$joined|".contains("|" + "3rd" + "|"))
|
||||
}
|
||||
|
||||
@Test fun explodeSetTest() {
|
||||
|
@ -50,10 +50,10 @@ class WearUtilTest : TestBase() {
|
|||
val set = persistence.explodeSet(serializedSet, ":")
|
||||
|
||||
// THEN
|
||||
Assert.assertEquals(set.size, 3)
|
||||
Assert.assertTrue(set.contains("element1"))
|
||||
Assert.assertTrue(set.contains("second-elem"))
|
||||
Assert.assertTrue(set.contains("3rd"))
|
||||
Assertions.assertEquals(set.size, 3)
|
||||
Assertions.assertTrue(set.contains("element1"))
|
||||
Assertions.assertTrue(set.contains("second-elem"))
|
||||
Assertions.assertTrue(set.contains("3rd"))
|
||||
}
|
||||
|
||||
@Test fun explodeSetEmptyElemsTest() {
|
||||
|
@ -64,9 +64,9 @@ class WearUtilTest : TestBase() {
|
|||
val set = persistence.explodeSet(serializedSet, ",")
|
||||
|
||||
// THEN
|
||||
Assert.assertEquals(set.size, 2)
|
||||
Assert.assertEquals(true, set.contains("real"))
|
||||
Assert.assertEquals(true, set.contains("another"))
|
||||
Assertions.assertEquals(set.size, 2)
|
||||
Assertions.assertEquals(true, set.contains("real"))
|
||||
Assertions.assertEquals(true, set.contains("another"))
|
||||
}
|
||||
|
||||
@Test fun joinExplodeStabilityTest() {
|
||||
|
@ -84,7 +84,7 @@ class WearUtilTest : TestBase() {
|
|||
val explodedSet = persistence.explodeSet(joinedSet, "#")
|
||||
|
||||
// THEN
|
||||
Assert.assertEquals(explodedSet, refSet)
|
||||
Assertions.assertEquals(explodedSet, refSet)
|
||||
}
|
||||
|
||||
/* Mike: failing with new mockito
|
||||
|
@ -100,8 +100,8 @@ class WearUtilTest : TestBase() {
|
|||
|
||||
// THEN
|
||||
// we cannot guarantee to be exact to the millisecond - we add some margin of error
|
||||
Assert.assertTrue(60L > measuredSleepDuration)
|
||||
Assert.assertTrue(requestedSleepDuration + measuringMargin < measuredSleepDuration)
|
||||
Assertions.assertTrue(60L > measuredSleepDuration)
|
||||
Assertions.assertTrue(requestedSleepDuration + measuringMargin < measuredSleepDuration)
|
||||
}
|
||||
*/
|
||||
@Test fun rateLimitTest() {
|
||||
|
@ -115,9 +115,9 @@ class WearUtilTest : TestBase() {
|
|||
val callAfterRateLimit = wearUtil.isBelowRateLimit("test-limit", 3)
|
||||
|
||||
// THEN
|
||||
Assert.assertTrue(firstCall)
|
||||
Assert.assertFalse(callAfterward)
|
||||
Assert.assertFalse(callTooSoon)
|
||||
Assert.assertTrue(callAfterRateLimit)
|
||||
Assertions.assertTrue(firstCall)
|
||||
Assertions.assertFalse(callAfterward)
|
||||
Assertions.assertFalse(callTooSoon)
|
||||
Assertions.assertTrue(callAfterRateLimit)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue