shared-tests #4
This commit is contained in:
parent
24c2f47e84
commit
d950c7986c
38 changed files with 709 additions and 997 deletions
|
@ -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,4 +1,4 @@
|
||||||
package info.nightscout.androidaps.mocks
|
package info.nightscout.shared.impl
|
||||||
|
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
|
|
@ -1,14 +1,19 @@
|
||||||
package info.nightscout.shared.impl.logging
|
package info.nightscout.shared.impl.logging
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBase
|
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import org.junit.jupiter.api.Assertions
|
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.junit.jupiter.api.extension.ExtendWith
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension
|
||||||
|
import org.mockito.junit.jupiter.MockitoSettings
|
||||||
|
import org.mockito.quality.Strictness
|
||||||
|
|
||||||
class LImplTest : TestBase() {
|
@ExtendWith(MockitoExtension::class)
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
|
class LImplTest {
|
||||||
|
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
package info.nightscout.shared.impl.sharedPreferences
|
package info.nightscout.shared.impl.sharedPreferences
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import info.nightscout.androidaps.TestBase
|
import info.nightscout.shared.impl.SharedPreferencesMock
|
||||||
import info.nightscout.androidaps.mocks.SharedPreferencesMock
|
|
||||||
import org.junit.jupiter.api.Assertions
|
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.junit.jupiter.api.extension.ExtendWith
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension
|
||||||
|
import org.mockito.junit.jupiter.MockitoSettings
|
||||||
|
import org.mockito.quality.Strictness
|
||||||
|
|
||||||
class SPImplementationTest : TestBase() {
|
@ExtendWith(MockitoExtension::class)
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
|
class SPImplementationTest {
|
||||||
|
|
||||||
private val sharedPreferences: SharedPreferencesMock = SharedPreferencesMock()
|
private val sharedPreferences: SharedPreferencesMock = SharedPreferencesMock()
|
||||||
@Mock lateinit var context: Context
|
@Mock lateinit var context: Context
|
||||||
|
|
|
@ -20,6 +20,8 @@ dependencies {
|
||||||
implementation project(':core:ui')
|
implementation project(':core:ui')
|
||||||
implementation project(':core:utils')
|
implementation project(':core:utils')
|
||||||
|
|
||||||
|
testImplementation project(':app-wear-shared:shared-tests')
|
||||||
|
|
||||||
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
|
|
||||||
api "com.google.guava:guava:$guava_version"
|
api "com.google.guava:guava:$guava_version"
|
||||||
|
|
|
@ -1,83 +0,0 @@
|
||||||
package info.nightscout.androidaps
|
|
||||||
|
|
||||||
import info.nightscout.interfaces.utils.HardLimits
|
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlin.math.max
|
|
||||||
import kotlin.math.min
|
|
||||||
|
|
||||||
class HardLimitsMock @Inject constructor(
|
|
||||||
private val sp: SP,
|
|
||||||
private val rh: ResourceHelper
|
|
||||||
) : HardLimits {
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
private const val CHILD = 0
|
|
||||||
private const val TEENAGE = 1
|
|
||||||
private const val ADULT = 2
|
|
||||||
private const val RESISTANT_ADULT = 3
|
|
||||||
private const val PREGNANT = 4
|
|
||||||
private val MAX_BOLUS = doubleArrayOf(5.0, 10.0, 17.0, 25.0, 60.0)
|
|
||||||
|
|
||||||
// Very Hard Limits Ranges
|
|
||||||
// First value is the Lowest and second value is the Highest a Limit can define
|
|
||||||
val VERY_HARD_LIMIT_MIN_BG = doubleArrayOf(80.0, 180.0)
|
|
||||||
val VERY_HARD_LIMIT_MAX_BG = doubleArrayOf(90.0, 200.0)
|
|
||||||
val VERY_HARD_LIMIT_TARGET_BG = doubleArrayOf(80.0, 200.0)
|
|
||||||
|
|
||||||
// Very Hard Limits Ranges for Temp Targets
|
|
||||||
val VERY_HARD_LIMIT_TEMP_MIN_BG = intArrayOf(72, 180)
|
|
||||||
val VERY_HARD_LIMIT_TEMP_MAX_BG = intArrayOf(72, 270)
|
|
||||||
val VERY_HARD_LIMIT_TEMP_TARGET_BG = intArrayOf(72, 200)
|
|
||||||
val MIN_DIA = doubleArrayOf(5.0, 5.0, 5.0, 5.0, 5.0)
|
|
||||||
val MAX_DIA = doubleArrayOf(9.0, 9.0, 9.0, 9.0, 10.0)
|
|
||||||
val MIN_IC = doubleArrayOf(2.0, 2.0, 2.0, 2.0, 0.3)
|
|
||||||
val MAX_IC = doubleArrayOf(100.0, 100.0, 100.0, 100.0, 100.0)
|
|
||||||
const val MIN_ISF = 2.0 // mgdl
|
|
||||||
const val MAX_ISF = 1000.0 // mgdl
|
|
||||||
val MAX_IOB_AMA = doubleArrayOf(3.0, 5.0, 7.0, 12.0, 25.0)
|
|
||||||
val MAX_IOB_SMB = doubleArrayOf(7.0, 13.0, 22.0, 30.0, 70.0)
|
|
||||||
val MAX_BASAL = doubleArrayOf(2.0, 5.0, 10.0, 12.0, 25.0)
|
|
||||||
|
|
||||||
//LGS Hard limits
|
|
||||||
//No IOB at all
|
|
||||||
const val MAX_IOB_LGS = 0.0
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun loadAge(): Int = when (sp.getString(info.nightscout.core.utils.R.string.key_age, "")) {
|
|
||||||
rh.gs(info.nightscout.core.utils.R.string.key_child) -> CHILD
|
|
||||||
rh.gs(info.nightscout.core.utils.R.string.key_teenage) -> TEENAGE
|
|
||||||
rh.gs(info.nightscout.core.utils.R.string.key_adult) -> ADULT
|
|
||||||
rh.gs(info.nightscout.core.utils.R.string.key_resistantadult) -> RESISTANT_ADULT
|
|
||||||
rh.gs(info.nightscout.core.utils.R.string.key_pregnant) -> PREGNANT
|
|
||||||
else -> ADULT
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun maxBolus(): Double = MAX_BOLUS[loadAge()]
|
|
||||||
override fun maxIobAMA(): Double = MAX_IOB_AMA[loadAge()]
|
|
||||||
override fun maxIobSMB(): Double = MAX_IOB_SMB[loadAge()]
|
|
||||||
override fun maxBasal(): Double = MAX_BASAL[loadAge()]
|
|
||||||
override fun minDia(): Double = MIN_DIA[loadAge()]
|
|
||||||
override fun maxDia(): Double = MAX_DIA[loadAge()]
|
|
||||||
override fun minIC(): Double = MIN_IC[loadAge()]
|
|
||||||
override fun maxIC(): Double = MAX_IC[loadAge()]
|
|
||||||
|
|
||||||
// safety checks
|
|
||||||
override fun checkHardLimits(value: Double, valueName: Int, lowLimit: Double, highLimit: Double): Boolean =
|
|
||||||
value == verifyHardLimits(value, valueName, lowLimit, highLimit)
|
|
||||||
|
|
||||||
override fun isInRange(value: Double, lowLimit: Double, highLimit: Double): Boolean =
|
|
||||||
value in lowLimit..highLimit
|
|
||||||
|
|
||||||
override fun verifyHardLimits(value: Double, valueName: Int, lowLimit: Double, highLimit: Double): Double {
|
|
||||||
var newValue = value
|
|
||||||
if (newValue < lowLimit || newValue > highLimit) {
|
|
||||||
newValue = max(newValue, lowLimit)
|
|
||||||
newValue = min(newValue, highLimit)
|
|
||||||
}
|
|
||||||
return newValue
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,38 +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.Before
|
|
||||||
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
|
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
|
||||||
@ExtendWith(MockitoExtension::class)
|
|
||||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
|
||||||
open class TestBase {
|
|
||||||
|
|
||||||
val aapsLogger = AAPSLoggerTest()
|
|
||||||
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
|
|
||||||
|
|
||||||
@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,61 +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.interfaces.Config
|
|
||||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
|
||||||
import info.nightscout.interfaces.profile.DefaultValueHelper
|
|
||||||
import info.nightscout.interfaces.profile.Profile
|
|
||||||
import info.nightscout.interfaces.profile.ProfileFunction
|
|
||||||
import info.nightscout.interfaces.utils.HardLimits
|
|
||||||
import info.nightscout.rx.bus.RxBus
|
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
|
||||||
import info.nightscout.shared.utils.DateUtil
|
|
||||||
import org.json.JSONObject
|
|
||||||
import org.junit.jupiter.api.BeforeEach
|
|
||||||
import org.mockito.Mock
|
|
||||||
import org.mockito.Mockito.`when`
|
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
|
||||||
open class TestBaseWithProfile : TestBase() {
|
|
||||||
|
|
||||||
@Mock lateinit var activePluginProvider: ActivePlugin
|
|
||||||
@Mock lateinit var rh: ResourceHelper
|
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
|
||||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
|
||||||
@Mock lateinit var dateUtil: DateUtil
|
|
||||||
@Mock lateinit var config: Config
|
|
||||||
@Mock lateinit var sp: SP
|
|
||||||
@Mock lateinit var context: Context
|
|
||||||
|
|
||||||
private lateinit var hardLimits: HardLimits
|
|
||||||
lateinit var testPumpPlugin: TestPumpPlugin
|
|
||||||
|
|
||||||
val rxBus = RxBus(aapsSchedulers, aapsLogger)
|
|
||||||
|
|
||||||
val profileInjector = HasAndroidInjector { AndroidInjector { } }
|
|
||||||
|
|
||||||
private lateinit var invalidProfileJSON: String
|
|
||||||
private lateinit var validProfileJSON: String
|
|
||||||
lateinit var validProfile: Profile
|
|
||||||
lateinit var invalidProfile: Profile
|
|
||||||
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
fun prepareMock() {
|
|
||||||
invalidProfileJSON = "{\"dia\":\"1\",\"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\"}"
|
|
||||||
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\"}"
|
|
||||||
validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!)
|
|
||||||
testPumpPlugin = TestPumpPlugin(profileInjector)
|
|
||||||
`when`(activePluginProvider.activePump).thenReturn(testPumpPlugin)
|
|
||||||
hardLimits = HardLimitsMock(sp, rh)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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 var 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,55 +0,0 @@
|
||||||
package info.nightscout.androidaps.data
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBase
|
|
||||||
import info.nightscout.interfaces.constraints.Constraint
|
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.jupiter.api.BeforeEach
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 19.03.2018.
|
|
||||||
*/
|
|
||||||
class ConstraintTest : TestBase() {
|
|
||||||
|
|
||||||
@Test fun doTests() {
|
|
||||||
val b = Constraint(true)
|
|
||||||
Assert.assertEquals(true, b.value())
|
|
||||||
Assert.assertEquals("", b.getReasons(aapsLogger))
|
|
||||||
Assert.assertEquals("", b.getMostLimitedReasons(aapsLogger))
|
|
||||||
b.set(aapsLogger, false)
|
|
||||||
Assert.assertEquals(false, b.value())
|
|
||||||
Assert.assertEquals("", b.getReasons(aapsLogger))
|
|
||||||
Assert.assertEquals("", b.getMostLimitedReasons(aapsLogger))
|
|
||||||
b.set(aapsLogger, true, "Set true", this)
|
|
||||||
Assert.assertEquals(true, b.value())
|
|
||||||
Assert.assertEquals("ConstraintTest: Set true", b.getReasons(aapsLogger))
|
|
||||||
Assert.assertEquals("ConstraintTest: Set true", b.getMostLimitedReasons(aapsLogger))
|
|
||||||
b.set(aapsLogger, false, "Set false", this)
|
|
||||||
Assert.assertEquals(false, b.value())
|
|
||||||
Assert.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getReasons(aapsLogger))
|
|
||||||
Assert.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getMostLimitedReasons(aapsLogger))
|
|
||||||
val d = Constraint(10.0)
|
|
||||||
d.set(aapsLogger, 5.0, "Set 5d", this)
|
|
||||||
Assert.assertEquals(5.0, d.value(), 0.01)
|
|
||||||
Assert.assertEquals("ConstraintTest: Set 5d", d.getReasons(aapsLogger))
|
|
||||||
Assert.assertEquals("ConstraintTest: Set 5d", d.getMostLimitedReasons(aapsLogger))
|
|
||||||
d.setIfSmaller(aapsLogger, 6.0, "Set 6d", this)
|
|
||||||
Assert.assertEquals(5.0, d.value(), 0.01)
|
|
||||||
Assert.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d", d.getReasons(aapsLogger))
|
|
||||||
Assert.assertEquals("ConstraintTest: Set 5d", d.getMostLimitedReasons(aapsLogger))
|
|
||||||
d.setIfSmaller(aapsLogger, 4.0, "Set 4d", this)
|
|
||||||
Assert.assertEquals(4.0, d.value(), 0.01)
|
|
||||||
Assert.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d", d.getReasons(aapsLogger))
|
|
||||||
Assert.assertEquals("ConstraintTest: Set 4d", d.getMostLimitedReasons(aapsLogger))
|
|
||||||
Assert.assertEquals(10.0, d.originalValue(), 0.01)
|
|
||||||
d.setIfDifferent(aapsLogger, 7.0, "Set 7d", this)
|
|
||||||
Assert.assertEquals(7.0, d.value(), 0.01)
|
|
||||||
Assert.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d\nConstraintTest: Set 7d", d.getReasons(aapsLogger))
|
|
||||||
Assert.assertEquals("ConstraintTest: Set 4d\nConstraintTest: Set 7d", d.getMostLimitedReasons(aapsLogger))
|
|
||||||
Assert.assertEquals(10.0, d.originalValue(), 0.01)
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
fun prepareMock() {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,134 +0,0 @@
|
||||||
package info.nightscout.androidaps.extensions
|
|
||||||
|
|
||||||
import info.nightscout.core.extensions.blockValueBySeconds
|
|
||||||
import info.nightscout.core.extensions.highTargetBlockValueBySeconds
|
|
||||||
import info.nightscout.core.extensions.lowTargetBlockValueBySeconds
|
|
||||||
import info.nightscout.core.extensions.shiftBlock
|
|
||||||
import info.nightscout.core.extensions.shiftTargetBlock
|
|
||||||
import info.nightscout.core.extensions.targetBlockValueBySeconds
|
|
||||||
import info.nightscout.database.entities.data.Block
|
|
||||||
import info.nightscout.database.entities.data.TargetBlock
|
|
||||||
import info.nightscout.database.entities.data.checkSanity
|
|
||||||
import info.nightscout.shared.utils.T
|
|
||||||
import org.junit.Assert
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
|
|
||||||
class BlockExtensionKtTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun shiftBlock() {
|
|
||||||
val b = arrayListOf<Block>()
|
|
||||||
b.add(Block(T.hours(1).msecs(), 1.0))
|
|
||||||
b.add(Block(T.hours(1).msecs(), 2.0))
|
|
||||||
b.add(Block(T.hours(10).msecs(), 3.0))
|
|
||||||
b.add(Block(T.hours(12).msecs(), 4.0))
|
|
||||||
|
|
||||||
Assert.assertTrue(b.checkSanity())
|
|
||||||
|
|
||||||
Assert.assertEquals(1.0, b.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
Assert.assertEquals(2.0, b.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
Assert.assertEquals(3.0, b.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
Assert.assertEquals(3.0, b.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
Assert.assertEquals(4.0, b.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
Assert.assertEquals(4.0, b.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
|
|
||||||
val s1 = b.shiftBlock(1.0, -1)
|
|
||||||
|
|
||||||
Assert.assertTrue(s1.checkSanity())
|
|
||||||
|
|
||||||
Assert.assertEquals(1.0, s1.blockValueBySeconds(T.hours(23).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
Assert.assertEquals(2.0, s1.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
Assert.assertEquals(3.0, s1.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
Assert.assertEquals(3.0, s1.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
Assert.assertEquals(4.0, s1.blockValueBySeconds(T.hours(11).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
Assert.assertEquals(4.0, s1.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
|
|
||||||
val s2 = b.shiftBlock(2.0, 1)
|
|
||||||
|
|
||||||
Assert.assertTrue(s2.checkSanity())
|
|
||||||
|
|
||||||
Assert.assertEquals(2.0, s2.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
Assert.assertEquals(4.0, s2.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
Assert.assertEquals(6.0, s2.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
Assert.assertEquals(6.0, s2.blockValueBySeconds(T.hours(4).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
Assert.assertEquals(8.0, s2.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
Assert.assertEquals(8.0, s2.blockValueBySeconds(T.hours(14).secs().toInt(), 1.0, 0), 0.01)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun shiftTargetBlock() {
|
|
||||||
val b = arrayListOf<TargetBlock>()
|
|
||||||
b.add(TargetBlock(T.hours(1).msecs(), 1.0, 2.0))
|
|
||||||
b.add(TargetBlock(T.hours(1).msecs(), 2.0, 3.0))
|
|
||||||
b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0))
|
|
||||||
b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0))
|
|
||||||
|
|
||||||
Assert.assertTrue(b.checkSanity())
|
|
||||||
|
|
||||||
Assert.assertEquals(1.5, b.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(2.5, b.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(3.5, b.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(3.5, b.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(4.5, b.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(4.5, b.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01)
|
|
||||||
|
|
||||||
val s1 = b.shiftTargetBlock(-1)
|
|
||||||
|
|
||||||
Assert.assertTrue(s1.checkSanity())
|
|
||||||
|
|
||||||
Assert.assertEquals(1.5, s1.targetBlockValueBySeconds(T.hours(23).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(2.5, s1.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(3.5, s1.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(3.5, s1.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(4.5, s1.targetBlockValueBySeconds(T.hours(11).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(4.5, s1.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01)
|
|
||||||
|
|
||||||
val s2 = b.shiftTargetBlock(1)
|
|
||||||
|
|
||||||
Assert.assertTrue(s2.checkSanity())
|
|
||||||
|
|
||||||
Assert.assertEquals(1.5, s2.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(2.5, s2.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(3.5, s2.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(3.5, s2.targetBlockValueBySeconds(T.hours(4).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(4.5, s2.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(4.5, s2.targetBlockValueBySeconds(T.hours(14).secs().toInt(), 0), 0.01)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun lowTargetBlockValueBySeconds() {
|
|
||||||
val b = arrayListOf<TargetBlock>()
|
|
||||||
b.add(TargetBlock(T.hours(1).msecs(), 1.0, 2.0))
|
|
||||||
b.add(TargetBlock(T.hours(1).msecs(), 2.0, 3.0))
|
|
||||||
b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0))
|
|
||||||
b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0))
|
|
||||||
|
|
||||||
Assert.assertTrue(b.checkSanity())
|
|
||||||
|
|
||||||
Assert.assertEquals(1.0, b.lowTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(2.0, b.lowTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(3.0, b.lowTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(3.0, b.lowTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(4.0, b.lowTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(4.0, b.lowTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun highTargetBlockValueBySeconds() {
|
|
||||||
val b = arrayListOf<TargetBlock>()
|
|
||||||
b.add(TargetBlock(T.hours(1).msecs(), 1.0, 2.0))
|
|
||||||
b.add(TargetBlock(T.hours(1).msecs(), 2.0, 3.0))
|
|
||||||
b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0))
|
|
||||||
b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0))
|
|
||||||
|
|
||||||
Assert.assertTrue(b.checkSanity())
|
|
||||||
|
|
||||||
Assert.assertEquals(2.0, b.highTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(3.0, b.highTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(4.0, b.highTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(4.0, b.highTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(5.0, b.highTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01)
|
|
||||||
Assert.assertEquals(5.0, b.highTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
package info.nightscout.androidaps.interfaces
|
|
||||||
|
|
||||||
import info.nightscout.interfaces.pump.defs.PumpCapability
|
|
||||||
import info.nightscout.interfaces.pump.defs.PumpDescription
|
|
||||||
import info.nightscout.interfaces.pump.defs.PumpTempBasalType
|
|
||||||
import info.nightscout.interfaces.pump.defs.PumpType
|
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
|
|
||||||
class PumpDescriptionTest {
|
|
||||||
|
|
||||||
@Test fun setPumpDescription() {
|
|
||||||
val pumpDescription = PumpDescription()
|
|
||||||
pumpDescription.fillFor(PumpType.ACCU_CHEK_COMBO)
|
|
||||||
Assert.assertEquals(pumpDescription.bolusStep, PumpType.ACCU_CHEK_COMBO.bolusSize, 0.1)
|
|
||||||
Assert.assertEquals(pumpDescription.basalMinimumRate, PumpType.ACCU_CHEK_COMBO.baseBasalStep, 0.1)
|
|
||||||
Assert.assertEquals(pumpDescription.basalStep, PumpType.ACCU_CHEK_COMBO.baseBasalStep, 0.1)
|
|
||||||
Assert.assertEquals(pumpDescription.extendedBolusDurationStep, PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.durationStep?.toDouble())
|
|
||||||
Assert.assertEquals(pumpDescription.extendedBolusMaxDuration, PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.maxDuration?.toDouble())
|
|
||||||
Assert.assertEquals(pumpDescription.extendedBolusStep, PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.step)
|
|
||||||
Assert.assertEquals(pumpDescription.isExtendedBolusCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.ExtendedBolus))
|
|
||||||
Assert.assertEquals(pumpDescription.isBolusCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.Bolus))
|
|
||||||
Assert.assertEquals(pumpDescription.isRefillingCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.Refill))
|
|
||||||
Assert.assertEquals(pumpDescription.isSetBasalProfileCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.BasalProfileSet))
|
|
||||||
Assert.assertEquals(pumpDescription.isTempBasalCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.TempBasal))
|
|
||||||
Assert.assertEquals(pumpDescription.maxTempPercent.toDouble(), PumpType.ACCU_CHEK_COMBO.tbrSettings?.maxDose)
|
|
||||||
Assert.assertEquals(pumpDescription.tempPercentStep.toDouble(), PumpType.ACCU_CHEK_COMBO.tbrSettings?.step)
|
|
||||||
Assert.assertEquals(pumpDescription.tempBasalStyle, if (PumpType.ACCU_CHEK_COMBO.pumpTempBasalType == PumpTempBasalType.Percent) PumpDescription.PERCENT else PumpDescription.ABSOLUTE)
|
|
||||||
Assert.assertEquals(pumpDescription.tempDurationStep.toLong(), PumpType.ACCU_CHEK_COMBO.tbrSettings?.durationStep?.toLong())
|
|
||||||
Assert.assertEquals(pumpDescription.tempDurationStep15mAllowed, PumpType.ACCU_CHEK_COMBO.specialBasalDurations?.hasCapability(PumpCapability.BasalRate_Duration15minAllowed))
|
|
||||||
Assert.assertEquals(pumpDescription.tempDurationStep30mAllowed, PumpType.ACCU_CHEK_COMBO.specialBasalDurations?.hasCapability(PumpCapability.BasalRate_Duration30minAllowed))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
package info.nightscout.androidaps.utils
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import info.nightscout.androidaps.TestBase
|
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
|
||||||
import info.nightscout.shared.utils.DateUtil
|
|
||||||
import info.nightscout.shared.utils.T
|
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
import org.mockito.Mock
|
|
||||||
import org.mockito.Mockito.`when`
|
|
||||||
import java.util.Date
|
|
||||||
|
|
||||||
class DateUtilTest : TestBase() {
|
|
||||||
|
|
||||||
@Mock lateinit var context: Context
|
|
||||||
@Mock lateinit var rh: ResourceHelper
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun fromISODateStringTest() {
|
|
||||||
Assert.assertEquals(1511124634417L, DateUtil(context).fromISODateString("2017-11-19T22:50:34.417+0200"))
|
|
||||||
Assert.assertEquals(1511124634000L, DateUtil(context).fromISODateString("2017-11-19T22:50:34+0200"))
|
|
||||||
Assert.assertEquals(1512317365000L, DateUtil(context).fromISODateString("2017-12-03T16:09:25.000Z"))
|
|
||||||
Assert.assertEquals(1513902750000L, DateUtil(context).fromISODateString("2017-12-22T00:32:30Z"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun toISOStringTest() {
|
|
||||||
Assert.assertEquals("2017-12-22T00:32:30.000Z", DateUtil(context).toISOString(1513902750000L))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test fun secondsOfTheDayToMillisecondsTest() {
|
|
||||||
Assert.assertTrue(Date(DateUtil(context).secondsOfTheDayToMilliseconds((T.hours(1).secs() + T.mins(1).secs() + 1).toInt())).toString().contains("01:01:00"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test fun toSecondsTest() {
|
|
||||||
Assert.assertEquals(3600, DateUtil(context).toSeconds("01:00").toLong())
|
|
||||||
Assert.assertEquals(3600, DateUtil(context).toSeconds("01:00 a.m.").toLong())
|
|
||||||
Assert.assertEquals(3600, DateUtil(context).toSeconds("01:00 AM").toLong())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test fun dateStringTest() {
|
|
||||||
Assert.assertTrue(DateUtil(context).dateString(1513902750000L).contains("22"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test fun timeStringTest() {
|
|
||||||
Assert.assertTrue(DateUtil(context).timeString(1513902750000L).contains("32"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test fun dateAndTimeStringTest() {
|
|
||||||
Assert.assertTrue(DateUtil(context).dateAndTimeString(1513902750000L).contains("22"))
|
|
||||||
Assert.assertTrue(DateUtil(context).dateAndTimeString(1513902750000L).contains("32"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test fun dateAndTimeRangeStringTest() {
|
|
||||||
Assert.assertTrue(DateUtil(context).dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("22"))
|
|
||||||
Assert.assertTrue(DateUtil(context).dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("32"))
|
|
||||||
Assert.assertTrue(DateUtil(context).dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("22"))
|
|
||||||
Assert.assertTrue(DateUtil(context).dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("32"))
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
@Test
|
|
||||||
public void timeStringFromSecondsTest() {
|
|
||||||
Assert.assertEquals("1:00 AM", DateUtil.timeStringFromSeconds((int) T.hours(1).secs()));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
@Test fun timeFrameStringTest() {
|
|
||||||
`when`(rh.gs(info.nightscout.shared.R.string.shorthour)).thenReturn("h")
|
|
||||||
Assert.assertEquals("(1h 1')", DateUtil(context).timeFrameString(T.hours(1).msecs() + T.mins(1).msecs(), rh))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package info.nightscout.androidaps.utils
|
|
||||||
|
|
||||||
import info.nightscout.interfaces.utils.DecimalFormatter
|
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
|
|
||||||
class DecimalFormatterTest {
|
|
||||||
|
|
||||||
@Test fun to0DecimalTest() {
|
|
||||||
Assert.assertEquals("1", DecimalFormatter.to0Decimal(1.33).replace(",", "."))
|
|
||||||
Assert.assertEquals("1U", DecimalFormatter.to0Decimal(1.33, "U").replace(",", "."))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test fun to1DecimalTest() {
|
|
||||||
Assert.assertEquals("1.3", DecimalFormatter.to1Decimal(1.33).replace(",", "."))
|
|
||||||
Assert.assertEquals("1.3U", DecimalFormatter.to1Decimal(1.33, "U").replace(",", "."))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test fun to2DecimalTest() {
|
|
||||||
Assert.assertEquals("1.33", DecimalFormatter.to2Decimal(1.3333).replace(",", "."))
|
|
||||||
Assert.assertEquals("1.33U", DecimalFormatter.to2Decimal(1.3333, "U").replace(",", "."))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test fun to3DecimalTest() {
|
|
||||||
Assert.assertEquals("1.333", DecimalFormatter.to3Decimal(1.3333).replace(",", "."))
|
|
||||||
Assert.assertEquals("1.333U", DecimalFormatter.to3Decimal(1.3333, "U").replace(",", "."))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,80 +0,0 @@
|
||||||
package info.nightscout.androidaps.utils
|
|
||||||
|
|
||||||
import info.nightscout.interfaces.utils.JsonHelper
|
|
||||||
import org.json.JSONObject
|
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
|
||||||
class JsonHelperTest {
|
|
||||||
|
|
||||||
private val jsonString = "{\"d\":\"3.0\",\"i\":\"4\",\"s\":\"5\",\"b\":\"true\",\"j\":{\"a\": \"1\"}}"
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun safeGetObjectTest() {
|
|
||||||
val json = JSONObject(jsonString)
|
|
||||||
val o = Any()
|
|
||||||
Assert.assertEquals(o, JsonHelper.safeGetObject(null, "x", o))
|
|
||||||
Assert.assertEquals(o, JsonHelper.safeGetObject(json, "x", o))
|
|
||||||
Assert.assertNotEquals(o, JsonHelper.safeGetObject(json, "d", o))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun safeGetJSONObjectTest() {
|
|
||||||
val json = JSONObject(jsonString)
|
|
||||||
val o = JSONObject()
|
|
||||||
Assert.assertEquals(o, JsonHelper.safeGetJSONObject(null, "x", o))
|
|
||||||
Assert.assertTrue(JsonHelper.safeGetJSONObject(json, "j", o)!!.has("a"))
|
|
||||||
Assert.assertEquals(o, JsonHelper.safeGetJSONObject(json, "d", o))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun safeGetStringTest() {
|
|
||||||
val json = JSONObject(jsonString)
|
|
||||||
Assert.assertNull(JsonHelper.safeGetString(null, "s"))
|
|
||||||
Assert.assertNull(JsonHelper.safeGetString(json, "notexisting"))
|
|
||||||
Assert.assertEquals("5", JsonHelper.safeGetString(json, "s"))
|
|
||||||
Assert.assertEquals("default", JsonHelper.safeGetString(null, "notexisting", "default"))
|
|
||||||
Assert.assertEquals("default", JsonHelper.safeGetString(json, "notexisting", "default"))
|
|
||||||
Assert.assertEquals("5", JsonHelper.safeGetString(json, "s", "default"))
|
|
||||||
Assert.assertEquals("default", JsonHelper.safeGetStringAllowNull(null, "notexisting", "default"))
|
|
||||||
Assert.assertEquals("default", JsonHelper.safeGetStringAllowNull(json, "notexisting", "default"))
|
|
||||||
Assert.assertNull(JsonHelper.safeGetStringAllowNull(json, "notexisting", null))
|
|
||||||
Assert.assertEquals("5", JsonHelper.safeGetStringAllowNull(json, "s", "default"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun safeGetDoubleTest() {
|
|
||||||
val json = JSONObject(jsonString)
|
|
||||||
Assert.assertEquals(0.0, JsonHelper.safeGetDouble(json, "notexisting"), 0.0)
|
|
||||||
Assert.assertEquals(0.0, JsonHelper.safeGetDouble(null, "notexisting"), 0.0)
|
|
||||||
Assert.assertEquals(3.0, JsonHelper.safeGetDouble(json, "d"), 0.000001)
|
|
||||||
Assert.assertEquals(6.0, JsonHelper.safeGetDouble(null, "notexisting", 6.0), 0.0)
|
|
||||||
Assert.assertEquals(6.0, JsonHelper.safeGetDouble(json, "notexisting", 6.0), 0.0)
|
|
||||||
Assert.assertEquals(3.0, JsonHelper.safeGetDouble(json, "d", 6.0), 0.0)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun safeGetLntTest() {
|
|
||||||
val json = JSONObject(jsonString)
|
|
||||||
Assert.assertEquals(0, JsonHelper.safeGetInt(null, "notexisting").toLong())
|
|
||||||
Assert.assertEquals(0, JsonHelper.safeGetInt(json, "notexisting").toLong())
|
|
||||||
Assert.assertEquals(4, JsonHelper.safeGetInt(json, "i").toLong())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun safeGetLongTest() {
|
|
||||||
val json = JSONObject(jsonString)
|
|
||||||
Assert.assertEquals(0, JsonHelper.safeGetInt(null, "notexisting").toLong())
|
|
||||||
Assert.assertEquals(0, JsonHelper.safeGetInt(json, "notexisting").toLong())
|
|
||||||
Assert.assertEquals(4, JsonHelper.safeGetInt(json, "i").toLong())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun safeGetBooleanTest() {
|
|
||||||
val json = JSONObject(jsonString)
|
|
||||||
Assert.assertFalse(JsonHelper.safeGetBoolean(null, "notexisting"))
|
|
||||||
Assert.assertFalse(JsonHelper.safeGetBoolean(json, "notexisting"))
|
|
||||||
Assert.assertTrue(JsonHelper.safeGetBoolean(json, "b"))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
package info.nightscout.androidaps.utils
|
|
||||||
|
|
||||||
import info.nightscout.interfaces.utils.MidnightTime
|
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
import java.util.Calendar
|
|
||||||
|
|
||||||
class MidnightTimeTest {
|
|
||||||
|
|
||||||
@Test fun calc() {
|
|
||||||
// We get real midnight
|
|
||||||
val now = System.currentTimeMillis()
|
|
||||||
Assert.assertTrue(now >= MidnightTime.calc())
|
|
||||||
val c = Calendar.getInstance()
|
|
||||||
c.timeInMillis = MidnightTime.calc()
|
|
||||||
Assert.assertEquals(c[Calendar.HOUR_OF_DAY].toLong(), 0)
|
|
||||||
Assert.assertEquals(c[Calendar.MINUTE].toLong(), 0)
|
|
||||||
Assert.assertEquals(c[Calendar.SECOND].toLong(), 0)
|
|
||||||
Assert.assertEquals(c[Calendar.MILLISECOND].toLong(), 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test fun calc_time() {
|
|
||||||
// We get real midnight
|
|
||||||
val now = System.currentTimeMillis()
|
|
||||||
val midnight = MidnightTime.calc(now)
|
|
||||||
Assert.assertTrue(now >= midnight)
|
|
||||||
val c = Calendar.getInstance()
|
|
||||||
c.timeInMillis = MidnightTime.calc(now)
|
|
||||||
Assert.assertEquals(c[Calendar.HOUR_OF_DAY].toLong(), 0)
|
|
||||||
Assert.assertEquals(c[Calendar.MINUTE].toLong(), 0)
|
|
||||||
Assert.assertEquals(c[Calendar.SECOND].toLong(), 0)
|
|
||||||
Assert.assertEquals(c[Calendar.MILLISECOND].toLong(), 0)
|
|
||||||
// Assure we get the same time from cache
|
|
||||||
Assert.assertEquals(midnight, MidnightTime.calc(now))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test fun resetCache() {
|
|
||||||
val now = System.currentTimeMillis()
|
|
||||||
MidnightTime.calc(now)
|
|
||||||
MidnightTime.resetCache()
|
|
||||||
Assert.assertEquals(0, MidnightTime.times.size().toLong())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test fun log() {
|
|
||||||
val now = System.currentTimeMillis()
|
|
||||||
MidnightTime.calc(now)
|
|
||||||
Assert.assertTrue(MidnightTime.log().startsWith("Hits:"))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
package info.nightscout.androidaps.utils
|
|
||||||
|
|
||||||
import info.nightscout.interfaces.utils.Round
|
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
|
|
||||||
class RoundTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun roundToTest() {
|
|
||||||
Assert.assertEquals(0.55, Round.roundTo(0.54, 0.05), 0.00000000000000000001)
|
|
||||||
Assert.assertEquals(-3.26, Round.roundTo(-3.2553715764602713, 0.01), 0.00000000000000000001)
|
|
||||||
Assert.assertEquals(0.816, Round.roundTo(0.8156666666666667, 0.001), 0.00000000000000000001)
|
|
||||||
Assert.assertEquals(0.235, Round.roundTo(0.235, 0.001), 0.00000000000000000001)
|
|
||||||
Assert.assertEquals(0.3, Round.roundTo(0.3, 0.1), 0.00000000000000001)
|
|
||||||
Assert.assertEquals(0.0017, Round.roundTo(0.0016960652144170627, 0.0001), 0.00000000000000000001)
|
|
||||||
Assert.assertEquals(0.0078, Round.roundTo(0.007804436682291013, 0.0001), 0.00000000000000000001)
|
|
||||||
Assert.assertEquals(0.6, Round.roundTo(0.6, 0.05), 0.00000000000000000001)
|
|
||||||
Assert.assertEquals(1.0, Round.roundTo(1.49, 1.0), 0.00000000000000000001)
|
|
||||||
Assert.assertEquals(0.0, Round.roundTo(0.0, 1.0), 0.00000000000000000001)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun floorToTest() {
|
|
||||||
Assert.assertEquals(0.5, Round.floorTo(0.54, 0.05), 0.00000001)
|
|
||||||
Assert.assertEquals(1.0, Round.floorTo(1.59, 1.0), 0.00000001)
|
|
||||||
Assert.assertEquals(0.0, Round.floorTo(0.0, 1.0), 0.00000001)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun ceilToTest() {
|
|
||||||
Assert.assertEquals(0.6, Round.ceilTo(0.54, 0.1), 0.00000001)
|
|
||||||
Assert.assertEquals(2.0, Round.ceilTo(1.49999, 1.0), 0.00000001)
|
|
||||||
Assert.assertEquals(0.0, Round.ceilTo(0.0, 1.0), 0.00000001)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun isSameTest() {
|
|
||||||
Assert.assertTrue(Round.isSame(0.54, 0.54))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
package info.nightscout.androidaps.utils
|
|
||||||
|
|
||||||
import info.nightscout.core.utils.receivers.StringUtils
|
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
|
|
||||||
class StringUtilsTest {
|
|
||||||
|
|
||||||
@Test fun removeSurroundingQuotesTest() {
|
|
||||||
var compareString = "test"
|
|
||||||
Assert.assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString))
|
|
||||||
Assert.assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\""))
|
|
||||||
Assert.assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString))
|
|
||||||
compareString = "te\"st"
|
|
||||||
Assert.assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString))
|
|
||||||
Assert.assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\""))
|
|
||||||
Assert.assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
package info.nightscout.androidaps.utils
|
|
||||||
|
|
||||||
import info.nightscout.shared.utils.T
|
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
import kotlin.math.abs
|
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
|
||||||
class TTest {
|
|
||||||
|
|
||||||
@Test fun toUnits() {
|
|
||||||
Assert.assertEquals(1, T.msecs(1000).secs())
|
|
||||||
Assert.assertEquals(1, T.secs(60).mins())
|
|
||||||
Assert.assertEquals(1, T.mins(60).hours())
|
|
||||||
Assert.assertEquals(1, T.hours(24).days())
|
|
||||||
Assert.assertEquals(24, T.days(1).hours())
|
|
||||||
Assert.assertEquals(60000, T.mins(1).msecs())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test fun now() {
|
|
||||||
Assert.assertTrue(abs(T.now().msecs() - System.currentTimeMillis()) < 5000)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test fun additions() {
|
|
||||||
val nowMsecs = System.currentTimeMillis()
|
|
||||||
val now = T.msecs(nowMsecs)
|
|
||||||
Assert.assertEquals(now.plus(T.secs(5)).msecs(), nowMsecs + 5 * 1000)
|
|
||||||
Assert.assertEquals(now.plus(T.mins(5)).msecs(), nowMsecs + 5 * 60 * 1000)
|
|
||||||
Assert.assertEquals(now.plus(T.hours(5)).msecs(), nowMsecs + 5 * 60 * 60 * 1000)
|
|
||||||
Assert.assertEquals(now.plus(T.days(5)).msecs(), nowMsecs + 5 * 24 * 60 * 60 * 1000)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test fun subtractions() {
|
|
||||||
val nowMsecs = System.currentTimeMillis()
|
|
||||||
val now = T.msecs(nowMsecs)
|
|
||||||
Assert.assertEquals(now.minus(T.secs(5)).msecs(), nowMsecs - 5 * 1000)
|
|
||||||
Assert.assertEquals(now.minus(T.mins(5)).msecs(), nowMsecs - 5 * 60 * 1000)
|
|
||||||
Assert.assertEquals(now.minus(T.hours(5)).msecs(), nowMsecs - 5 * 60 * 60 * 1000)
|
|
||||||
Assert.assertEquals(now.minus(T.days(5)).msecs(), nowMsecs - 5 * 24 * 60 * 60 * 1000)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package info.nightscout.core.data
|
||||||
|
|
||||||
|
import info.nightscout.interfaces.constraints.Constraint
|
||||||
|
import info.nightscout.sharedtests.TestBase
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 19.03.2018.
|
||||||
|
*/
|
||||||
|
class ConstraintTest : TestBase() {
|
||||||
|
|
||||||
|
@Test fun doTests() {
|
||||||
|
val b = Constraint(true)
|
||||||
|
Assertions.assertEquals(true, b.value())
|
||||||
|
Assertions.assertEquals("", b.getReasons(aapsLogger))
|
||||||
|
Assertions.assertEquals("", b.getMostLimitedReasons(aapsLogger))
|
||||||
|
b.set(aapsLogger, false)
|
||||||
|
Assertions.assertEquals(false, b.value())
|
||||||
|
Assertions.assertEquals("", b.getReasons(aapsLogger))
|
||||||
|
Assertions.assertEquals("", b.getMostLimitedReasons(aapsLogger))
|
||||||
|
b.set(aapsLogger, true, "Set true", this)
|
||||||
|
Assertions.assertEquals(true, b.value())
|
||||||
|
Assertions.assertEquals("ConstraintTest: Set true", b.getReasons(aapsLogger))
|
||||||
|
Assertions.assertEquals("ConstraintTest: Set true", b.getMostLimitedReasons(aapsLogger))
|
||||||
|
b.set(aapsLogger, false, "Set false", this)
|
||||||
|
Assertions.assertEquals(false, b.value())
|
||||||
|
Assertions.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getReasons(aapsLogger))
|
||||||
|
Assertions.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getMostLimitedReasons(aapsLogger))
|
||||||
|
val d = Constraint(10.0)
|
||||||
|
d.set(aapsLogger, 5.0, "Set 5d", this)
|
||||||
|
Assertions.assertEquals(5.0, d.value(), 0.01)
|
||||||
|
Assertions.assertEquals("ConstraintTest: Set 5d", d.getReasons(aapsLogger))
|
||||||
|
Assertions.assertEquals("ConstraintTest: Set 5d", d.getMostLimitedReasons(aapsLogger))
|
||||||
|
d.setIfSmaller(aapsLogger, 6.0, "Set 6d", this)
|
||||||
|
Assertions.assertEquals(5.0, d.value(), 0.01)
|
||||||
|
Assertions.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d", d.getReasons(aapsLogger))
|
||||||
|
Assertions.assertEquals("ConstraintTest: Set 5d", d.getMostLimitedReasons(aapsLogger))
|
||||||
|
d.setIfSmaller(aapsLogger, 4.0, "Set 4d", this)
|
||||||
|
Assertions.assertEquals(4.0, d.value(), 0.01)
|
||||||
|
Assertions.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d", d.getReasons(aapsLogger))
|
||||||
|
Assertions.assertEquals("ConstraintTest: Set 4d", d.getMostLimitedReasons(aapsLogger))
|
||||||
|
Assertions.assertEquals(10.0, d.originalValue(), 0.01)
|
||||||
|
d.setIfDifferent(aapsLogger, 7.0, "Set 7d", this)
|
||||||
|
Assertions.assertEquals(7.0, d.value(), 0.01)
|
||||||
|
Assertions.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d\nConstraintTest: Set 7d", d.getReasons(aapsLogger))
|
||||||
|
Assertions.assertEquals("ConstraintTest: Set 4d\nConstraintTest: Set 7d", d.getMostLimitedReasons(aapsLogger))
|
||||||
|
Assertions.assertEquals(10.0, d.originalValue(), 0.01)
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun prepareMock() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,12 +1,12 @@
|
||||||
package info.nightscout.androidaps.data
|
package info.nightscout.core.data
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import info.nightscout.androidaps.TestBase
|
|
||||||
import info.nightscout.database.entities.Bolus
|
import info.nightscout.database.entities.Bolus
|
||||||
import info.nightscout.database.entities.BolusCalculatorResult
|
import info.nightscout.database.entities.BolusCalculatorResult
|
||||||
import info.nightscout.database.entities.TherapyEvent
|
import info.nightscout.database.entities.TherapyEvent
|
||||||
import info.nightscout.interfaces.pump.DetailedBolusInfo
|
import info.nightscout.interfaces.pump.DetailedBolusInfo
|
||||||
|
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.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
|
@ -1,7 +1,7 @@
|
||||||
package info.nightscout.androidaps.data
|
package info.nightscout.core.data
|
||||||
|
|
||||||
import info.nightscout.interfaces.iob.Iob
|
import info.nightscout.interfaces.iob.Iob
|
||||||
import org.junit.Assert
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class IobTest {
|
class IobTest {
|
||||||
|
@ -10,24 +10,23 @@ class IobTest {
|
||||||
val a = Iob().iobContrib(1.0).activityContrib(2.0)
|
val a = Iob().iobContrib(1.0).activityContrib(2.0)
|
||||||
val b = Iob().iobContrib(3.0).activityContrib(4.0)
|
val b = Iob().iobContrib(3.0).activityContrib(4.0)
|
||||||
a.plus(b)
|
a.plus(b)
|
||||||
Assert.assertEquals(4.0, a.iobContrib, 0.01)
|
Assertions.assertEquals(4.0, a.iobContrib, 0.01)
|
||||||
Assert.assertEquals(6.0, a.activityContrib, 0.01)
|
Assertions.assertEquals(6.0, a.activityContrib, 0.01)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun equalTest() {
|
@Test fun equalTest() {
|
||||||
val a1 = Iob().iobContrib(1.0).activityContrib(2.0)
|
val a1 = Iob().iobContrib(1.0).activityContrib(2.0)
|
||||||
val a2 = Iob().iobContrib(1.0).activityContrib(2.0)
|
val a2 = Iob().iobContrib(1.0).activityContrib(2.0)
|
||||||
val b = Iob().iobContrib(3.0).activityContrib(4.0)
|
val b = Iob().iobContrib(3.0).activityContrib(4.0)
|
||||||
Assert.assertTrue(a1 == a1)
|
Assertions.assertTrue(a1 == a2)
|
||||||
Assert.assertTrue(a1 == a2)
|
Assertions.assertFalse(a1 == b)
|
||||||
Assert.assertFalse(a1 == b)
|
|
||||||
@Suppress("SENSELESS_COMPARISON")
|
@Suppress("SENSELESS_COMPARISON")
|
||||||
Assert.assertFalse(a1 == null)
|
Assertions.assertFalse(a1 == null)
|
||||||
Assert.assertFalse(a1 == Any())
|
Assertions.assertFalse(a1 == Any())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun hashCodeTest() {
|
@Test fun hashCodeTest() {
|
||||||
val a = Iob().iobContrib(1.0).activityContrib(2.0)
|
val a = Iob().iobContrib(1.0).activityContrib(2.0)
|
||||||
Assert.assertNotEquals(0, a.hashCode().toLong())
|
Assertions.assertNotEquals(0, a.hashCode().toLong())
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
package info.nightscout.androidaps.data
|
package info.nightscout.core.data
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import info.nightscout.androidaps.TestBase
|
|
||||||
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
|
||||||
|
@ -10,7 +9,8 @@ import info.nightscout.core.iob.plus
|
||||||
import info.nightscout.core.iob.round
|
import info.nightscout.core.iob.round
|
||||||
import info.nightscout.interfaces.iob.IobTotal
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import org.junit.Assert
|
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
|
||||||
|
@ -33,7 +33,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()
|
||||||
Assert.assertEquals(a.iob, b.iob, 0.01)
|
Assertions.assertEquals(a.iob, b.iob, 0.01)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun plusTest() {
|
@Test fun plusTest() {
|
||||||
|
@ -47,14 +47,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())
|
||||||
Assert.assertEquals(20.0, a.iob, 0.01)
|
Assertions.assertEquals(20.0, a.iob, 0.01)
|
||||||
Assert.assertEquals(20.0, a.activity, 0.01)
|
Assertions.assertEquals(20.0, a.activity, 0.01)
|
||||||
Assert.assertEquals(20.0, a.bolussnooze, 0.01)
|
Assertions.assertEquals(20.0, a.bolussnooze, 0.01)
|
||||||
Assert.assertEquals(20.0, a.basaliob, 0.01)
|
Assertions.assertEquals(20.0, a.basaliob, 0.01)
|
||||||
Assert.assertEquals(20.0, a.netbasalinsulin, 0.01)
|
Assertions.assertEquals(20.0, a.netbasalinsulin, 0.01)
|
||||||
Assert.assertEquals(20.0, a.hightempinsulin, 0.01)
|
Assertions.assertEquals(20.0, a.hightempinsulin, 0.01)
|
||||||
Assert.assertEquals(20.0, a.netInsulin, 0.01)
|
Assertions.assertEquals(20.0, a.netInsulin, 0.01)
|
||||||
Assert.assertEquals(20.0, a.extendedBolusInsulin, 0.01)
|
Assertions.assertEquals(20.0, a.extendedBolusInsulin, 0.01)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun combineTest() {
|
@Test fun combineTest() {
|
||||||
|
@ -69,15 +69,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)
|
||||||
Assert.assertEquals(a.time.toDouble(), c.time.toDouble(), 0.01)
|
Assertions.assertEquals(a.time.toDouble(), c.time.toDouble(), 0.01)
|
||||||
Assert.assertEquals(23.0, c.iob, 0.01)
|
Assertions.assertEquals(23.0, c.iob, 0.01)
|
||||||
Assert.assertEquals(22.0, c.activity, 0.01)
|
Assertions.assertEquals(22.0, c.activity, 0.01)
|
||||||
Assert.assertEquals(12.0, c.bolussnooze, 0.01)
|
Assertions.assertEquals(12.0, c.bolussnooze, 0.01)
|
||||||
Assert.assertEquals(26.0, c.basaliob, 0.01)
|
Assertions.assertEquals(26.0, c.basaliob, 0.01)
|
||||||
Assert.assertEquals(28.0, c.netbasalinsulin, 0.01)
|
Assertions.assertEquals(28.0, c.netbasalinsulin, 0.01)
|
||||||
Assert.assertEquals(30.0, c.hightempinsulin, 0.01)
|
Assertions.assertEquals(30.0, c.hightempinsulin, 0.01)
|
||||||
Assert.assertEquals(32.0, c.netInsulin, 0.01)
|
Assertions.assertEquals(32.0, c.netInsulin, 0.01)
|
||||||
Assert.assertEquals(34.0, c.extendedBolusInsulin, 0.01)
|
Assertions.assertEquals(34.0, c.extendedBolusInsulin, 0.01)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun roundTest() {
|
@Test fun roundTest() {
|
||||||
|
@ -91,14 +91,14 @@ class IobTotalTest : TestBase() {
|
||||||
a.netInsulin = 1.1111111111111
|
a.netInsulin = 1.1111111111111
|
||||||
a.extendedBolusInsulin = 1.1111111111111
|
a.extendedBolusInsulin = 1.1111111111111
|
||||||
a.round()
|
a.round()
|
||||||
Assert.assertEquals(1.111, a.iob, 0.00001)
|
Assertions.assertEquals(1.111, a.iob, 0.00001)
|
||||||
Assert.assertEquals(1.1111, a.activity, 0.00001)
|
Assertions.assertEquals(1.1111, a.activity, 0.00001)
|
||||||
Assert.assertEquals(1.1111, a.bolussnooze, 0.00001)
|
Assertions.assertEquals(1.1111, a.bolussnooze, 0.00001)
|
||||||
Assert.assertEquals(1.111, a.basaliob, 0.00001)
|
Assertions.assertEquals(1.111, a.basaliob, 0.00001)
|
||||||
Assert.assertEquals(1.111, a.netbasalinsulin, 0.00001)
|
Assertions.assertEquals(1.111, a.netbasalinsulin, 0.00001)
|
||||||
Assert.assertEquals(1.111, a.hightempinsulin, 0.00001)
|
Assertions.assertEquals(1.111, a.hightempinsulin, 0.00001)
|
||||||
Assert.assertEquals(1.111, a.netInsulin, 0.00001)
|
Assertions.assertEquals(1.111, a.netInsulin, 0.00001)
|
||||||
Assert.assertEquals(1.111, a.extendedBolusInsulin, 0.00001)
|
Assertions.assertEquals(1.111, a.extendedBolusInsulin, 0.00001)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun jsonTest() {
|
@Test fun jsonTest() {
|
||||||
|
@ -113,12 +113,12 @@ class IobTotalTest : TestBase() {
|
||||||
a.extendedBolusInsulin = 17.0
|
a.extendedBolusInsulin = 17.0
|
||||||
try {
|
try {
|
||||||
val j = a.json(dateUtil)
|
val j = a.json(dateUtil)
|
||||||
Assert.assertEquals(a.iob, j.getDouble("iob"), 0.0000001)
|
Assertions.assertEquals(a.iob, j.getDouble("iob"), 0.0000001)
|
||||||
Assert.assertEquals(a.basaliob, j.getDouble("basaliob"), 0.0000001)
|
Assertions.assertEquals(a.basaliob, j.getDouble("basaliob"), 0.0000001)
|
||||||
Assert.assertEquals(a.activity, j.getDouble("activity"), 0.0000001)
|
Assertions.assertEquals(a.activity, j.getDouble("activity"), 0.0000001)
|
||||||
Assert.assertEquals(now, dateUtil.fromISODateString(j.getString("time")))
|
Assertions.assertEquals(now, dateUtil.fromISODateString(j.getString("time")))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Assert.fail("Exception: " + e.message)
|
Assertions.fail("Exception: " + e.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,15 +135,15 @@ class IobTotalTest : TestBase() {
|
||||||
a.iobWithZeroTemp = IobTotal(now)
|
a.iobWithZeroTemp = IobTotal(now)
|
||||||
try {
|
try {
|
||||||
val j = a.determineBasalJson(dateUtil)
|
val j = a.determineBasalJson(dateUtil)
|
||||||
Assert.assertEquals(a.iob, j.getDouble("iob"), 0.0000001)
|
Assertions.assertEquals(a.iob, j.getDouble("iob"), 0.0000001)
|
||||||
Assert.assertEquals(a.basaliob, j.getDouble("basaliob"), 0.0000001)
|
Assertions.assertEquals(a.basaliob, j.getDouble("basaliob"), 0.0000001)
|
||||||
Assert.assertEquals(a.bolussnooze, j.getDouble("bolussnooze"), 0.0000001)
|
Assertions.assertEquals(a.bolussnooze, j.getDouble("bolussnooze"), 0.0000001)
|
||||||
Assert.assertEquals(a.activity, j.getDouble("activity"), 0.0000001)
|
Assertions.assertEquals(a.activity, j.getDouble("activity"), 0.0000001)
|
||||||
Assert.assertEquals(0, j.getLong("lastBolusTime"))
|
Assertions.assertEquals(0, j.getLong("lastBolusTime"))
|
||||||
Assert.assertEquals(now, dateUtil.fromISODateString(j.getString("time")))
|
Assertions.assertEquals(now, dateUtil.fromISODateString(j.getString("time")))
|
||||||
Assert.assertNotNull(j.getJSONObject("iobWithZeroTemp"))
|
Assertions.assertNotNull(j.getJSONObject("iobWithZeroTemp"))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Assert.fail("Exception: " + e.message)
|
Assertions.fail("Exception: " + e.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,13 +1,13 @@
|
||||||
package info.nightscout.androidaps.data
|
package info.nightscout.core.data
|
||||||
|
|
||||||
import info.nightscout.interfaces.iob.MealData
|
import info.nightscout.interfaces.iob.MealData
|
||||||
import org.junit.Assert
|
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()
|
||||||
Assert.assertEquals(0.0, md.carbs, 0.01)
|
Assertions.assertEquals(0.0, md.carbs, 0.01)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,10 +1,7 @@
|
||||||
package info.nightscout.androidaps.data
|
package info.nightscout.core.data
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import info.nightscout.androidaps.HardLimitsMock
|
|
||||||
import info.nightscout.androidaps.TestBase
|
|
||||||
import info.nightscout.androidaps.TestPumpPlugin
|
|
||||||
import info.nightscout.core.extensions.pureProfileFromJson
|
import info.nightscout.core.extensions.pureProfileFromJson
|
||||||
import info.nightscout.core.profile.ProfileSealed
|
import info.nightscout.core.profile.ProfileSealed
|
||||||
import info.nightscout.interfaces.Config
|
import info.nightscout.interfaces.Config
|
||||||
|
@ -17,8 +14,11 @@ import info.nightscout.rx.bus.RxBus
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
|
import info.nightscout.sharedtests.HardLimitsMock
|
||||||
|
import info.nightscout.sharedtests.TestBase
|
||||||
|
import info.nightscout.sharedtests.TestPumpPlugin
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.junit.Assert
|
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
|
||||||
|
@ -76,84 +76,84 @@ 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)!!)
|
||||||
Assert.assertEquals(true, p.isValid("Test", testPumpPlugin, config, rh, rxBus, hardLimits, false).isValid)
|
Assertions.assertEquals(true, p.isValid("Test", testPumpPlugin, config, rh, rxBus, hardLimits, false).isValid)
|
||||||
// Assert.assertEquals(true, p.log().contains("NS units: mmol"))
|
// Assertions.assertEquals(true, p.log().contains("NS units: mmol"))
|
||||||
// JSONAssert.assertEquals(JSONObject(okProfile), p.toPureNsJson(dateUtil), false)
|
// JSONAssertions.assertEquals(JSONObject(okProfile), p.toPureNsJson(dateUtil), false)
|
||||||
Assert.assertEquals(5.0, p.dia, 0.01)
|
Assertions.assertEquals(5.0, p.dia, 0.01)
|
||||||
// Assert.assertEquals(TimeZone.getTimeZone("UTC"), p.timeZone)
|
// Assertions.assertEquals(TimeZone.getTimeZone("UTC"), p.timeZone)
|
||||||
Assert.assertEquals("00:30", dateUtil.formatHHMM(30 * 60))
|
Assertions.assertEquals("00:30", dateUtil.formatHHMM(30 * 60))
|
||||||
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
|
||||||
Assert.assertEquals(108.0, p.getIsfMgdl(c.timeInMillis), 0.01)
|
Assertions.assertEquals(108.0, p.getIsfMgdl(c.timeInMillis), 0.01)
|
||||||
c[Calendar.HOUR_OF_DAY] = 2
|
c[Calendar.HOUR_OF_DAY] = 2
|
||||||
Assert.assertEquals(111.6, p.getIsfMgdl(c.timeInMillis), 0.01)
|
Assertions.assertEquals(111.6, p.getIsfMgdl(c.timeInMillis), 0.01)
|
||||||
// Assert.assertEquals(110.0, p.getIsfTimeFromMidnight(2 * 60 * 60), 0.01)
|
// Assertions.assertEquals(110.0, p.getIsfTimeFromMidnight(2 * 60 * 60), 0.01)
|
||||||
Assert.assertEquals(
|
Assertions.assertEquals(
|
||||||
"""
|
"""
|
||||||
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(), p.getIsfList(rh, dateUtil).replace(".", ",")
|
||||||
)
|
)
|
||||||
Assert.assertEquals(30.0, p.getIc(c.timeInMillis), 0.01)
|
Assertions.assertEquals(30.0, p.getIc(c.timeInMillis), 0.01)
|
||||||
Assert.assertEquals(30.0, p.getIcTimeFromMidnight(2 * 60 * 60), 0.01)
|
Assertions.assertEquals(30.0, p.getIcTimeFromMidnight(2 * 60 * 60), 0.01)
|
||||||
Assert.assertEquals("00:00 30,0 g/U", p.getIcList(rh, dateUtil).replace(".", ","))
|
Assertions.assertEquals("00:00 30,0 g/U", p.getIcList(rh, dateUtil).replace(".", ","))
|
||||||
Assert.assertEquals(0.1, p.getBasal(c.timeInMillis), 0.01)
|
Assertions.assertEquals(0.1, p.getBasal(c.timeInMillis), 0.01)
|
||||||
Assert.assertEquals(0.1, p.getBasalTimeFromMidnight(2 * 60 * 60), 0.01)
|
Assertions.assertEquals(0.1, p.getBasalTimeFromMidnight(2 * 60 * 60), 0.01)
|
||||||
Assert.assertEquals("00:00 0,10 U/h", p.getBasalList(rh, dateUtil).replace(".", ","))
|
Assertions.assertEquals("00:00 0,10 U/h", p.getBasalList(rh, dateUtil).replace(".", ","))
|
||||||
Assert.assertEquals(0.1, p.getBasalValues()[0].value, 0.01)
|
Assertions.assertEquals(0.1, p.getBasalValues()[0].value, 0.01)
|
||||||
Assert.assertEquals(0.1, p.getMaxDailyBasal(), 0.01)
|
Assertions.assertEquals(0.1, p.getMaxDailyBasal(), 0.01)
|
||||||
Assert.assertEquals(2.4, p.percentageBasalSum(), 0.01)
|
Assertions.assertEquals(2.4, p.percentageBasalSum(), 0.01)
|
||||||
Assert.assertEquals(2.4, p.baseBasalSum(), 0.01)
|
Assertions.assertEquals(2.4, p.baseBasalSum(), 0.01)
|
||||||
// Assert.assertEquals(81.0, p.getTargetMgdl(2 * 60 * 60), 0.01)
|
// Assertions.assertEquals(81.0, p.getTargetMgdl(2 * 60 * 60), 0.01)
|
||||||
Assert.assertEquals(90.0, p.getTargetLowMgdl(c.timeInMillis), 0.01)
|
Assertions.assertEquals(90.0, p.getTargetLowMgdl(c.timeInMillis), 0.01)
|
||||||
// Assert.assertEquals(4.0, p.getTargetLowTimeFromMidnight(2 * 60 * 60), 0.01)
|
// Assertions.assertEquals(4.0, p.getTargetLowTimeFromMidnight(2 * 60 * 60), 0.01)
|
||||||
Assert.assertEquals(90.0, p.getTargetHighMgdl(c.timeInMillis), 0.01)
|
Assertions.assertEquals(90.0, p.getTargetHighMgdl(c.timeInMillis), 0.01)
|
||||||
// Assert.assertEquals(5.0, p.getTargetHighTimeFromMidnight(2 * 60 * 60), 0.01)
|
// Assertions.assertEquals(5.0, p.getTargetHighTimeFromMidnight(2 * 60 * 60), 0.01)
|
||||||
Assert.assertEquals("00:00 5,0 - 5,0 mmol", p.getTargetList(rh, dateUtil).replace(".", ","))
|
Assertions.assertEquals("00:00 5,0 - 5,0 mmol", p.getTargetList(rh, dateUtil).replace(".", ","))
|
||||||
Assert.assertEquals(100, p.percentage)
|
Assertions.assertEquals(100, p.percentage)
|
||||||
Assert.assertEquals(0, p.timeshift)
|
Assertions.assertEquals(0, p.timeshift)
|
||||||
Assert.assertEquals(0.1, Profile.toMgdl(0.1, GlucoseUnit.MGDL), 0.01)
|
Assertions.assertEquals(0.1, Profile.toMgdl(0.1, GlucoseUnit.MGDL), 0.01)
|
||||||
Assert.assertEquals(18.0, Profile.toMgdl(1.0, GlucoseUnit.MMOL), 0.01)
|
Assertions.assertEquals(18.0, Profile.toMgdl(1.0, GlucoseUnit.MMOL), 0.01)
|
||||||
Assert.assertEquals(1.0, Profile.toMmol(18.0, GlucoseUnit.MGDL), 0.01)
|
Assertions.assertEquals(1.0, Profile.toMmol(18.0, GlucoseUnit.MGDL), 0.01)
|
||||||
Assert.assertEquals(18.0, Profile.toMmol(18.0, GlucoseUnit.MMOL), 0.01)
|
Assertions.assertEquals(18.0, Profile.toMmol(18.0, GlucoseUnit.MMOL), 0.01)
|
||||||
Assert.assertEquals(18.0, Profile.fromMgdlToUnits(18.0, GlucoseUnit.MGDL), 0.01)
|
Assertions.assertEquals(18.0, Profile.fromMgdlToUnits(18.0, GlucoseUnit.MGDL), 0.01)
|
||||||
Assert.assertEquals(1.0, Profile.fromMgdlToUnits(18.0, GlucoseUnit.MMOL), 0.01)
|
Assertions.assertEquals(1.0, Profile.fromMgdlToUnits(18.0, GlucoseUnit.MMOL), 0.01)
|
||||||
Assert.assertEquals(18.0, Profile.toUnits(18.0, 1.0, GlucoseUnit.MGDL), 0.01)
|
Assertions.assertEquals(18.0, Profile.toUnits(18.0, 1.0, GlucoseUnit.MGDL), 0.01)
|
||||||
Assert.assertEquals(1.0, Profile.toUnits(18.0, 1.0, GlucoseUnit.MMOL), 0.01)
|
Assertions.assertEquals(1.0, Profile.toUnits(18.0, 1.0, GlucoseUnit.MMOL), 0.01)
|
||||||
Assert.assertEquals("18", Profile.toUnitsString(18.0, 1.0, GlucoseUnit.MGDL))
|
Assertions.assertEquals("18", Profile.toUnitsString(18.0, 1.0, GlucoseUnit.MGDL))
|
||||||
Assert.assertEquals("1,0", Profile.toUnitsString(18.0, 1.0, GlucoseUnit.MMOL).replace(".", ","))
|
Assertions.assertEquals("1,0", Profile.toUnitsString(18.0, 1.0, GlucoseUnit.MMOL).replace(".", ","))
|
||||||
Assert.assertEquals("5 - 6", Profile.toTargetRangeString(5.0, 6.0, GlucoseUnit.MGDL, GlucoseUnit.MGDL))
|
Assertions.assertEquals("5 - 6", Profile.toTargetRangeString(5.0, 6.0, GlucoseUnit.MGDL, GlucoseUnit.MGDL))
|
||||||
Assert.assertEquals("4", Profile.toTargetRangeString(4.0, 4.0, GlucoseUnit.MGDL, GlucoseUnit.MGDL))
|
Assertions.assertEquals("4", Profile.toTargetRangeString(4.0, 4.0, GlucoseUnit.MGDL, GlucoseUnit.MGDL))
|
||||||
|
|
||||||
//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
|
||||||
Assert.assertNull(pureProfileFromJson(JSONObject(noUnitsValidProfile), dateUtil))
|
Assertions.assertNull(pureProfileFromJson(JSONObject(noUnitsValidProfile), dateUtil))
|
||||||
|
|
||||||
//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)!!)
|
||||||
Assert.assertEquals(30.0, p.getIc(0), 0.01)
|
Assertions.assertEquals(30.0, p.getIc(0), 0.01)
|
||||||
|
|
||||||
// Test wrong profile
|
// Test wrong profile
|
||||||
Assert.assertNull(pureProfileFromJson(JSONObject(wrongProfile), dateUtil))
|
Assertions.assertNull(pureProfileFromJson(JSONObject(wrongProfile), dateUtil))
|
||||||
|
|
||||||
// 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
|
||||||
Assert.assertEquals(0.05, p.getBasal(c.timeInMillis), 0.01)
|
Assertions.assertEquals(0.05, p.getBasal(c.timeInMillis), 0.01)
|
||||||
Assert.assertEquals(1.2, p.percentageBasalSum(), 0.01)
|
Assertions.assertEquals(1.2, p.percentageBasalSum(), 0.01)
|
||||||
Assert.assertEquals(60.0, p.getIc(c.timeInMillis), 0.01)
|
Assertions.assertEquals(60.0, p.getIc(c.timeInMillis), 0.01)
|
||||||
Assert.assertEquals(223.2, p.getIsfMgdl(c.timeInMillis), 0.01)
|
Assertions.assertEquals(223.2, p.getIsfMgdl(c.timeInMillis), 0.01)
|
||||||
|
|
||||||
// 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
|
||||||
Assert.assertEquals(
|
Assertions.assertEquals(
|
||||||
"""
|
"""
|
||||||
00:00 6.2 mmol/U
|
00:00 6.2 mmol/U
|
||||||
01:00 6.0 mmol/U
|
01:00 6.0 mmol/U
|
|
@ -0,0 +1,127 @@
|
||||||
|
package info.nightscout.core.extensions
|
||||||
|
|
||||||
|
import info.nightscout.database.entities.data.Block
|
||||||
|
import info.nightscout.database.entities.data.TargetBlock
|
||||||
|
import info.nightscout.database.entities.data.checkSanity
|
||||||
|
import info.nightscout.shared.utils.T
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class BlockExtensionKtTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shiftBlock() {
|
||||||
|
val b = arrayListOf<Block>()
|
||||||
|
b.add(Block(T.hours(1).msecs(), 1.0))
|
||||||
|
b.add(Block(T.hours(1).msecs(), 2.0))
|
||||||
|
b.add(Block(T.hours(10).msecs(), 3.0))
|
||||||
|
b.add(Block(T.hours(12).msecs(), 4.0))
|
||||||
|
|
||||||
|
Assertions.assertTrue(b.checkSanity())
|
||||||
|
|
||||||
|
Assertions.assertEquals(1.0, b.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
Assertions.assertEquals(2.0, b.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
Assertions.assertEquals(3.0, b.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
Assertions.assertEquals(3.0, b.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
Assertions.assertEquals(4.0, b.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
Assertions.assertEquals(4.0, b.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
|
||||||
|
val s1 = b.shiftBlock(1.0, -1)
|
||||||
|
|
||||||
|
Assertions.assertTrue(s1.checkSanity())
|
||||||
|
|
||||||
|
Assertions.assertEquals(1.0, s1.blockValueBySeconds(T.hours(23).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
Assertions.assertEquals(2.0, s1.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
Assertions.assertEquals(3.0, s1.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
Assertions.assertEquals(3.0, s1.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
Assertions.assertEquals(4.0, s1.blockValueBySeconds(T.hours(11).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
Assertions.assertEquals(4.0, s1.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
|
||||||
|
val s2 = b.shiftBlock(2.0, 1)
|
||||||
|
|
||||||
|
Assertions.assertTrue(s2.checkSanity())
|
||||||
|
|
||||||
|
Assertions.assertEquals(2.0, s2.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
Assertions.assertEquals(4.0, s2.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
Assertions.assertEquals(6.0, s2.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
Assertions.assertEquals(6.0, s2.blockValueBySeconds(T.hours(4).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
Assertions.assertEquals(8.0, s2.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
Assertions.assertEquals(8.0, s2.blockValueBySeconds(T.hours(14).secs().toInt(), 1.0, 0), 0.01)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shiftTargetBlock() {
|
||||||
|
val b = arrayListOf<TargetBlock>()
|
||||||
|
b.add(TargetBlock(T.hours(1).msecs(), 1.0, 2.0))
|
||||||
|
b.add(TargetBlock(T.hours(1).msecs(), 2.0, 3.0))
|
||||||
|
b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0))
|
||||||
|
b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0))
|
||||||
|
|
||||||
|
Assertions.assertTrue(b.checkSanity())
|
||||||
|
|
||||||
|
Assertions.assertEquals(1.5, b.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(2.5, b.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(3.5, b.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(3.5, b.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(4.5, b.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(4.5, b.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01)
|
||||||
|
|
||||||
|
val s1 = b.shiftTargetBlock(-1)
|
||||||
|
|
||||||
|
Assertions.assertTrue(s1.checkSanity())
|
||||||
|
|
||||||
|
Assertions.assertEquals(1.5, s1.targetBlockValueBySeconds(T.hours(23).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(2.5, s1.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(3.5, s1.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(3.5, s1.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(4.5, s1.targetBlockValueBySeconds(T.hours(11).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(4.5, s1.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01)
|
||||||
|
|
||||||
|
val s2 = b.shiftTargetBlock(1)
|
||||||
|
|
||||||
|
Assertions.assertTrue(s2.checkSanity())
|
||||||
|
|
||||||
|
Assertions.assertEquals(1.5, s2.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(2.5, s2.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(3.5, s2.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(3.5, s2.targetBlockValueBySeconds(T.hours(4).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(4.5, s2.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(4.5, s2.targetBlockValueBySeconds(T.hours(14).secs().toInt(), 0), 0.01)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun lowTargetBlockValueBySeconds() {
|
||||||
|
val b = arrayListOf<TargetBlock>()
|
||||||
|
b.add(TargetBlock(T.hours(1).msecs(), 1.0, 2.0))
|
||||||
|
b.add(TargetBlock(T.hours(1).msecs(), 2.0, 3.0))
|
||||||
|
b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0))
|
||||||
|
b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0))
|
||||||
|
|
||||||
|
Assertions.assertTrue(b.checkSanity())
|
||||||
|
|
||||||
|
Assertions.assertEquals(1.0, b.lowTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(2.0, b.lowTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(3.0, b.lowTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(3.0, b.lowTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(4.0, b.lowTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(4.0, b.lowTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun highTargetBlockValueBySeconds() {
|
||||||
|
val b = arrayListOf<TargetBlock>()
|
||||||
|
b.add(TargetBlock(T.hours(1).msecs(), 1.0, 2.0))
|
||||||
|
b.add(TargetBlock(T.hours(1).msecs(), 2.0, 3.0))
|
||||||
|
b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0))
|
||||||
|
b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0))
|
||||||
|
|
||||||
|
Assertions.assertTrue(b.checkSanity())
|
||||||
|
|
||||||
|
Assertions.assertEquals(2.0, b.highTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(3.0, b.highTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(4.0, b.highTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(4.0, b.highTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(5.0, b.highTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01)
|
||||||
|
Assertions.assertEquals(5.0, b.highTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,70 +1,70 @@
|
||||||
package info.nightscout.androidaps.interfaces
|
package info.nightscout.core.interfaces
|
||||||
|
|
||||||
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.Assert
|
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)
|
||||||
Assert.assertEquals(PluginType.PUMP, pluginDescription.mainType)
|
Assertions.assertEquals(PluginType.PUMP, pluginDescription.mainType)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun fragmentClassTest() {
|
@Test fun fragmentClassTest() {
|
||||||
val pluginDescription = PluginDescription().fragmentClass(Fragment::class.java.name)
|
val pluginDescription = PluginDescription().fragmentClass(Fragment::class.java.name)
|
||||||
Assert.assertEquals(Fragment::class.java.name, pluginDescription.fragmentClass)
|
Assertions.assertEquals(Fragment::class.java.name, pluginDescription.fragmentClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun alwaysEnabledTest() {
|
@Test fun alwaysEnabledTest() {
|
||||||
val pluginDescription = PluginDescription().alwaysEnabled(true)
|
val pluginDescription = PluginDescription().alwaysEnabled(true)
|
||||||
Assert.assertEquals(true, pluginDescription.alwaysEnabled)
|
Assertions.assertEquals(true, pluginDescription.alwaysEnabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun alwaysVisibleTest() {
|
@Test fun alwaysVisibleTest() {
|
||||||
val pluginDescription = PluginDescription().alwaysVisible(true)
|
val pluginDescription = PluginDescription().alwaysVisible(true)
|
||||||
Assert.assertEquals(true, pluginDescription.alwaysVisible)
|
Assertions.assertEquals(true, pluginDescription.alwaysVisible)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun neverVisibleTest() {
|
@Test fun neverVisibleTest() {
|
||||||
val pluginDescription = PluginDescription().neverVisible(true)
|
val pluginDescription = PluginDescription().neverVisible(true)
|
||||||
Assert.assertEquals(true, pluginDescription.neverVisible)
|
Assertions.assertEquals(true, pluginDescription.neverVisible)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun showInListTest() {
|
@Test fun showInListTest() {
|
||||||
val pluginDescription = PluginDescription().showInList(false)
|
val pluginDescription = PluginDescription().showInList(false)
|
||||||
Assert.assertEquals(false, pluginDescription.showInList)
|
Assertions.assertEquals(false, pluginDescription.showInList)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun pluginIcon() {
|
@Test fun pluginIcon() {
|
||||||
val pluginDescription = PluginDescription().pluginIcon(10)
|
val pluginDescription = PluginDescription().pluginIcon(10)
|
||||||
Assert.assertEquals(10, pluginDescription.pluginIcon.toLong())
|
Assertions.assertEquals(10, pluginDescription.pluginIcon.toLong())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun pluginName() {
|
@Test fun pluginName() {
|
||||||
val pluginDescription = PluginDescription().pluginName(10)
|
val pluginDescription = PluginDescription().pluginName(10)
|
||||||
Assert.assertEquals(10, pluginDescription.pluginName.toLong())
|
Assertions.assertEquals(10, pluginDescription.pluginName.toLong())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shortNameTest() {
|
@Test fun shortNameTest() {
|
||||||
val pluginDescription = PluginDescription().shortName(10)
|
val pluginDescription = PluginDescription().shortName(10)
|
||||||
Assert.assertEquals(10, pluginDescription.shortName.toLong())
|
Assertions.assertEquals(10, pluginDescription.shortName.toLong())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun preferencesIdTest() {
|
@Test fun preferencesIdTest() {
|
||||||
val pluginDescription = PluginDescription().preferencesId(10)
|
val pluginDescription = PluginDescription().preferencesId(10)
|
||||||
Assert.assertEquals(10, pluginDescription.preferencesId.toLong())
|
Assertions.assertEquals(10, pluginDescription.preferencesId.toLong())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun enableByDefault() {
|
@Test fun enableByDefault() {
|
||||||
val pluginDescription = PluginDescription().enableByDefault(true)
|
val pluginDescription = PluginDescription().enableByDefault(true)
|
||||||
Assert.assertEquals(true, pluginDescription.enableByDefault)
|
Assertions.assertEquals(true, pluginDescription.enableByDefault)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun visibleByDefault() {
|
@Test fun visibleByDefault() {
|
||||||
val pluginDescription = PluginDescription().visibleByDefault(true)
|
val pluginDescription = PluginDescription().visibleByDefault(true)
|
||||||
Assert.assertEquals(true, pluginDescription.visibleByDefault)
|
Assertions.assertEquals(true, pluginDescription.visibleByDefault)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package info.nightscout.core.interfaces
|
||||||
|
|
||||||
|
import info.nightscout.interfaces.pump.defs.PumpCapability
|
||||||
|
import info.nightscout.interfaces.pump.defs.PumpDescription
|
||||||
|
import info.nightscout.interfaces.pump.defs.PumpTempBasalType
|
||||||
|
import info.nightscout.interfaces.pump.defs.PumpType
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class PumpDescriptionTest {
|
||||||
|
|
||||||
|
@Test fun setPumpDescription() {
|
||||||
|
val pumpDescription = PumpDescription()
|
||||||
|
pumpDescription.fillFor(PumpType.ACCU_CHEK_COMBO)
|
||||||
|
Assertions.assertEquals(pumpDescription.bolusStep, PumpType.ACCU_CHEK_COMBO.bolusSize, 0.1)
|
||||||
|
Assertions.assertEquals(pumpDescription.basalMinimumRate, PumpType.ACCU_CHEK_COMBO.baseBasalStep, 0.1)
|
||||||
|
Assertions.assertEquals(pumpDescription.basalStep, PumpType.ACCU_CHEK_COMBO.baseBasalStep, 0.1)
|
||||||
|
Assertions.assertEquals(pumpDescription.extendedBolusDurationStep, PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.durationStep?.toDouble())
|
||||||
|
Assertions.assertEquals(pumpDescription.extendedBolusMaxDuration, PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.maxDuration?.toDouble())
|
||||||
|
Assertions.assertEquals(pumpDescription.extendedBolusStep, PumpType.ACCU_CHEK_COMBO.extendedBolusSettings?.step)
|
||||||
|
Assertions.assertEquals(pumpDescription.isExtendedBolusCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.ExtendedBolus))
|
||||||
|
Assertions.assertEquals(pumpDescription.isBolusCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.Bolus))
|
||||||
|
Assertions.assertEquals(pumpDescription.isRefillingCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.Refill))
|
||||||
|
Assertions.assertEquals(pumpDescription.isSetBasalProfileCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.BasalProfileSet))
|
||||||
|
Assertions.assertEquals(pumpDescription.isTempBasalCapable, PumpType.ACCU_CHEK_COMBO.pumpCapability?.hasCapability(PumpCapability.TempBasal))
|
||||||
|
Assertions.assertEquals(pumpDescription.maxTempPercent.toDouble(), PumpType.ACCU_CHEK_COMBO.tbrSettings?.maxDose)
|
||||||
|
Assertions.assertEquals(pumpDescription.tempPercentStep.toDouble(), PumpType.ACCU_CHEK_COMBO.tbrSettings?.step)
|
||||||
|
Assertions.assertEquals(pumpDescription.tempBasalStyle, 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())
|
||||||
|
Assertions.assertEquals(pumpDescription.tempDurationStep15mAllowed, PumpType.ACCU_CHEK_COMBO.specialBasalDurations?.hasCapability(PumpCapability.BasalRate_Duration15minAllowed))
|
||||||
|
Assertions.assertEquals(pumpDescription.tempDurationStep30mAllowed, PumpType.ACCU_CHEK_COMBO.specialBasalDurations?.hasCapability(PumpCapability.BasalRate_Duration30minAllowed))
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,21 +1,21 @@
|
||||||
package info.nightscout.androidaps.pump.common.utils;
|
package info.nightscout.core.pump.common.utils;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import info.nightscout.core.utils.DateTimeUtil;
|
import info.nightscout.core.utils.DateTimeUtil;
|
||||||
|
|
||||||
public class DateTimeUtilUTest {
|
class DateTimeUtilUTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getATechDateDifferenceAsMinutes() {
|
void getATechDateDifferenceAsMinutes() {
|
||||||
|
|
||||||
long dt1 = 20191001182301L;
|
long dt1 = 20191001182301L;
|
||||||
long dt2 = 20191001192805L;
|
long dt2 = 20191001192805L;
|
||||||
|
|
||||||
int aTechDateDifferenceAsMinutes = DateTimeUtil.getATechDateDifferenceAsMinutes(dt1, dt2);
|
int aTechDateDifferenceAsMinutes = DateTimeUtil.getATechDateDifferenceAsMinutes(dt1, dt2);
|
||||||
|
|
||||||
Assert.assertEquals(65, aTechDateDifferenceAsMinutes);
|
Assertions.assertEquals(65, aTechDateDifferenceAsMinutes);
|
||||||
|
|
||||||
//Log.d("DateTimeUtilUTest", "Time difference: " + aTechDateDifferenceAsMinutes);
|
//Log.d("DateTimeUtilUTest", "Time difference: " + aTechDateDifferenceAsMinutes);
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package info.nightscout.androidaps.utils
|
package info.nightscout.core.utils
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBase
|
import info.nightscout.sharedtests.TestBase
|
||||||
import info.nightscout.core.utils.CryptoUtil
|
|
||||||
import org.hamcrest.CoreMatchers.containsString
|
import org.hamcrest.CoreMatchers.containsString
|
||||||
import org.hamcrest.CoreMatchers.not
|
import org.hamcrest.CoreMatchers.not
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.Assume.assumeThat
|
import org.junit.Assume.assumeThat
|
||||||
|
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
|
||||||
|
@ -34,11 +33,11 @@ class CryptoUtilTest : TestBase() {
|
||||||
|
|
||||||
val encrypted = cryptoUtil.encrypt(password, salt, payload)
|
val encrypted = cryptoUtil.encrypt(password, salt, payload)
|
||||||
assumeAES256isSupported(cryptoUtil)
|
assumeAES256isSupported(cryptoUtil)
|
||||||
Assert.assertNotNull(encrypted)
|
Assertions.assertNotNull(encrypted)
|
||||||
|
|
||||||
val decrypted = cryptoUtil.decrypt(password, salt, encrypted!!)
|
val decrypted = cryptoUtil.decrypt(password, salt, encrypted!!)
|
||||||
assumeAES256isSupported(cryptoUtil)
|
assumeAES256isSupported(cryptoUtil)
|
||||||
Assert.assertEquals(decrypted, payload)
|
Assertions.assertEquals(decrypted, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -50,18 +49,18 @@ class CryptoUtilTest : TestBase() {
|
||||||
|
|
||||||
val encrypted = cryptoUtil.encrypt(password, salt, payload)
|
val encrypted = cryptoUtil.encrypt(password, salt, payload)
|
||||||
assumeAES256isSupported(cryptoUtil)
|
assumeAES256isSupported(cryptoUtil)
|
||||||
Assert.assertNotNull(encrypted)
|
Assertions.assertNotNull(encrypted)
|
||||||
|
|
||||||
val decrypted = cryptoUtil.decrypt(password, salt, encrypted!!)
|
val decrypted = cryptoUtil.decrypt(password, salt, encrypted!!)
|
||||||
assumeAES256isSupported(cryptoUtil)
|
assumeAES256isSupported(cryptoUtil)
|
||||||
Assert.assertEquals(decrypted, payload)
|
Assertions.assertEquals(decrypted, 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)
|
||||||
Assert.assertEquals(hash, "a1aafe3ed6cc127e6d102ddbc40a205147230e9cfd178daf108c83543bbdcd13")
|
Assertions.assertEquals(hash, "a1aafe3ed6cc127e6d102ddbc40a205147230e9cfd178daf108c83543bbdcd13")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -70,24 +69,24 @@ 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)
|
||||||
Assert.assertEquals(hash, expectedHmac)
|
Assertions.assertEquals(hash, expectedHmac)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testPlainPasswordCheck() {
|
fun testPlainPasswordCheck() {
|
||||||
Assert.assertTrue(cryptoUtil.checkPassword("same", "same"))
|
Assertions.assertTrue(cryptoUtil.checkPassword("same", "same"))
|
||||||
Assert.assertFalse(cryptoUtil.checkPassword("same", "other"))
|
Assertions.assertFalse(cryptoUtil.checkPassword("same", "other"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testHashedPasswordCheck() {
|
fun testHashedPasswordCheck() {
|
||||||
Assert.assertTrue(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("givenSecret")))
|
Assertions.assertTrue(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("givenSecret")))
|
||||||
Assert.assertFalse(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("otherSecret")))
|
Assertions.assertFalse(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("otherSecret")))
|
||||||
|
|
||||||
Assert.assertTrue(cryptoUtil.checkPassword("givenHashToCheck", "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1"))
|
Assertions.assertTrue(cryptoUtil.checkPassword("givenHashToCheck", "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1"))
|
||||||
Assert.assertFalse(cryptoUtil.checkPassword("givenMashToCheck", "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1"))
|
Assertions.assertFalse(cryptoUtil.checkPassword("givenMashToCheck", "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1"))
|
||||||
Assert.assertFalse(cryptoUtil.checkPassword("givenHashToCheck", "hmac:0fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1"))
|
Assertions.assertFalse(cryptoUtil.checkPassword("givenHashToCheck", "hmac:0fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1"))
|
||||||
Assert.assertFalse(cryptoUtil.checkPassword("givenHashToCheck", "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:b0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1"))
|
Assertions.assertFalse(cryptoUtil.checkPassword("givenHashToCheck", "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:b0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1"))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
package info.nightscout.core.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
|
import info.nightscout.shared.utils.DateUtil
|
||||||
|
import info.nightscout.shared.utils.T
|
||||||
|
import info.nightscout.sharedtests.TestBase
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
class DateUtilTest : TestBase() {
|
||||||
|
|
||||||
|
@Mock lateinit var context: Context
|
||||||
|
@Mock lateinit var rh: ResourceHelper
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun fromISODateStringTest() {
|
||||||
|
Assertions.assertEquals(1511124634417L, DateUtil(context).fromISODateString("2017-11-19T22:50:34.417+0200"))
|
||||||
|
Assertions.assertEquals(1511124634000L, DateUtil(context).fromISODateString("2017-11-19T22:50:34+0200"))
|
||||||
|
Assertions.assertEquals(1512317365000L, DateUtil(context).fromISODateString("2017-12-03T16:09:25.000Z"))
|
||||||
|
Assertions.assertEquals(1513902750000L, DateUtil(context).fromISODateString("2017-12-22T00:32:30Z"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun toISOStringTest() {
|
||||||
|
Assertions.assertEquals("2017-12-22T00:32:30.000Z", DateUtil(context).toISOString(1513902750000L))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun secondsOfTheDayToMillisecondsTest() {
|
||||||
|
Assertions.assertTrue(Date(DateUtil(context).secondsOfTheDayToMilliseconds((T.hours(1).secs() + T.mins(1).secs() + 1).toInt())).toString().contains("01:01:00"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun toSecondsTest() {
|
||||||
|
Assertions.assertEquals(3600, DateUtil(context).toSeconds("01:00").toLong())
|
||||||
|
Assertions.assertEquals(3600, DateUtil(context).toSeconds("01:00 a.m.").toLong())
|
||||||
|
Assertions.assertEquals(3600, DateUtil(context).toSeconds("01:00 AM").toLong())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun dateStringTest() {
|
||||||
|
Assertions.assertTrue(DateUtil(context).dateString(1513902750000L).contains("22"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun timeStringTest() {
|
||||||
|
Assertions.assertTrue(DateUtil(context).timeString(1513902750000L).contains("32"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun dateAndTimeStringTest() {
|
||||||
|
Assertions.assertTrue(DateUtil(context).dateAndTimeString(1513902750000L).contains("22"))
|
||||||
|
Assertions.assertTrue(DateUtil(context).dateAndTimeString(1513902750000L).contains("32"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun dateAndTimeRangeStringTest() {
|
||||||
|
Assertions.assertTrue(DateUtil(context).dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("22"))
|
||||||
|
Assertions.assertTrue(DateUtil(context).dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("32"))
|
||||||
|
Assertions.assertTrue(DateUtil(context).dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("22"))
|
||||||
|
Assertions.assertTrue(DateUtil(context).dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("32"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Test
|
||||||
|
public void timeStringFromSecondsTest() {
|
||||||
|
Assertions.assertEquals("1:00 AM", DateUtil.timeStringFromSeconds((int) T.hours(1).secs()));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
@Test fun timeFrameStringTest() {
|
||||||
|
`when`(rh.gs(info.nightscout.shared.R.string.shorthour)).thenReturn("h")
|
||||||
|
Assertions.assertEquals("(1h 1')", DateUtil(context).timeFrameString(T.hours(1).msecs() + T.mins(1).msecs(), rh))
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package info.nightscout.core.utils
|
||||||
|
|
||||||
|
import info.nightscout.interfaces.utils.DecimalFormatter
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class DecimalFormatterTest {
|
||||||
|
|
||||||
|
@Test fun to0DecimalTest() {
|
||||||
|
Assertions.assertEquals("1", DecimalFormatter.to0Decimal(1.33).replace(",", "."))
|
||||||
|
Assertions.assertEquals("1U", DecimalFormatter.to0Decimal(1.33, "U").replace(",", "."))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun to1DecimalTest() {
|
||||||
|
Assertions.assertEquals("1.3", DecimalFormatter.to1Decimal(1.33).replace(",", "."))
|
||||||
|
Assertions.assertEquals("1.3U", DecimalFormatter.to1Decimal(1.33, "U").replace(",", "."))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun to2DecimalTest() {
|
||||||
|
Assertions.assertEquals("1.33", DecimalFormatter.to2Decimal(1.3333).replace(",", "."))
|
||||||
|
Assertions.assertEquals("1.33U", DecimalFormatter.to2Decimal(1.3333, "U").replace(",", "."))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun to3DecimalTest() {
|
||||||
|
Assertions.assertEquals("1.333", DecimalFormatter.to3Decimal(1.3333).replace(",", "."))
|
||||||
|
Assertions.assertEquals("1.333U", DecimalFormatter.to3Decimal(1.3333, "U").replace(",", "."))
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
package info.nightscout.core.utils
|
||||||
|
|
||||||
|
import info.nightscout.interfaces.utils.JsonHelper
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
@Suppress("SpellCheckingInspection")
|
||||||
|
class JsonHelperTest {
|
||||||
|
|
||||||
|
private val jsonString = "{\"d\":\"3.0\",\"i\":\"4\",\"s\":\"5\",\"b\":\"true\",\"j\":{\"a\": \"1\"}}"
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun safeGetObjectTest() {
|
||||||
|
val json = JSONObject(jsonString)
|
||||||
|
val o = Any()
|
||||||
|
Assertions.assertEquals(o, JsonHelper.safeGetObject(null, "x", o))
|
||||||
|
Assertions.assertEquals(o, JsonHelper.safeGetObject(json, "x", o))
|
||||||
|
Assertions.assertNotEquals(o, JsonHelper.safeGetObject(json, "d", o))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun safeGetJSONObjectTest() {
|
||||||
|
val json = JSONObject(jsonString)
|
||||||
|
val o = JSONObject()
|
||||||
|
Assertions.assertEquals(o, JsonHelper.safeGetJSONObject(null, "x", o))
|
||||||
|
Assertions.assertTrue(JsonHelper.safeGetJSONObject(json, "j", o)!!.has("a"))
|
||||||
|
Assertions.assertEquals(o, JsonHelper.safeGetJSONObject(json, "d", o))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun safeGetStringTest() {
|
||||||
|
val json = JSONObject(jsonString)
|
||||||
|
Assertions.assertNull(JsonHelper.safeGetString(null, "s"))
|
||||||
|
Assertions.assertNull(JsonHelper.safeGetString(json, "notexisting"))
|
||||||
|
Assertions.assertEquals("5", JsonHelper.safeGetString(json, "s"))
|
||||||
|
Assertions.assertEquals("default", JsonHelper.safeGetString(null, "notexisting", "default"))
|
||||||
|
Assertions.assertEquals("default", JsonHelper.safeGetString(json, "notexisting", "default"))
|
||||||
|
Assertions.assertEquals("5", JsonHelper.safeGetString(json, "s", "default"))
|
||||||
|
Assertions.assertEquals("default", JsonHelper.safeGetStringAllowNull(null, "notexisting", "default"))
|
||||||
|
Assertions.assertEquals("default", JsonHelper.safeGetStringAllowNull(json, "notexisting", "default"))
|
||||||
|
Assertions.assertNull(JsonHelper.safeGetStringAllowNull(json, "notexisting", null))
|
||||||
|
Assertions.assertEquals("5", JsonHelper.safeGetStringAllowNull(json, "s", "default"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun safeGetDoubleTest() {
|
||||||
|
val json = JSONObject(jsonString)
|
||||||
|
Assertions.assertEquals(0.0, JsonHelper.safeGetDouble(json, "notexisting"), 0.0)
|
||||||
|
Assertions.assertEquals(0.0, JsonHelper.safeGetDouble(null, "notexisting"), 0.0)
|
||||||
|
Assertions.assertEquals(3.0, JsonHelper.safeGetDouble(json, "d"), 0.000001)
|
||||||
|
Assertions.assertEquals(6.0, JsonHelper.safeGetDouble(null, "notexisting", 6.0), 0.0)
|
||||||
|
Assertions.assertEquals(6.0, JsonHelper.safeGetDouble(json, "notexisting", 6.0), 0.0)
|
||||||
|
Assertions.assertEquals(3.0, JsonHelper.safeGetDouble(json, "d", 6.0), 0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun safeGetLntTest() {
|
||||||
|
val json = JSONObject(jsonString)
|
||||||
|
Assertions.assertEquals(0, JsonHelper.safeGetInt(null, "notexisting").toLong())
|
||||||
|
Assertions.assertEquals(0, JsonHelper.safeGetInt(json, "notexisting").toLong())
|
||||||
|
Assertions.assertEquals(4, JsonHelper.safeGetInt(json, "i").toLong())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun safeGetLongTest() {
|
||||||
|
val json = JSONObject(jsonString)
|
||||||
|
Assertions.assertEquals(0, JsonHelper.safeGetInt(null, "notexisting").toLong())
|
||||||
|
Assertions.assertEquals(0, JsonHelper.safeGetInt(json, "notexisting").toLong())
|
||||||
|
Assertions.assertEquals(4, JsonHelper.safeGetInt(json, "i").toLong())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun safeGetBooleanTest() {
|
||||||
|
val json = JSONObject(jsonString)
|
||||||
|
Assertions.assertFalse(JsonHelper.safeGetBoolean(null, "notexisting"))
|
||||||
|
Assertions.assertFalse(JsonHelper.safeGetBoolean(json, "notexisting"))
|
||||||
|
Assertions.assertTrue(JsonHelper.safeGetBoolean(json, "b"))
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package info.nightscout.core.utils
|
||||||
|
|
||||||
|
import info.nightscout.interfaces.utils.MidnightTime
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import java.util.Calendar
|
||||||
|
|
||||||
|
class MidnightTimeTest {
|
||||||
|
|
||||||
|
@Test fun calc() {
|
||||||
|
// We get real midnight
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
Assertions.assertTrue(now >= MidnightTime.calc())
|
||||||
|
val c = Calendar.getInstance()
|
||||||
|
c.timeInMillis = MidnightTime.calc()
|
||||||
|
Assertions.assertEquals(c[Calendar.HOUR_OF_DAY].toLong(), 0)
|
||||||
|
Assertions.assertEquals(c[Calendar.MINUTE].toLong(), 0)
|
||||||
|
Assertions.assertEquals(c[Calendar.SECOND].toLong(), 0)
|
||||||
|
Assertions.assertEquals(c[Calendar.MILLISECOND].toLong(), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun calc_time() {
|
||||||
|
// We get real midnight
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
val midnight = MidnightTime.calc(now)
|
||||||
|
Assertions.assertTrue(now >= midnight)
|
||||||
|
val c = Calendar.getInstance()
|
||||||
|
c.timeInMillis = MidnightTime.calc(now)
|
||||||
|
Assertions.assertEquals(c[Calendar.HOUR_OF_DAY].toLong(), 0)
|
||||||
|
Assertions.assertEquals(c[Calendar.MINUTE].toLong(), 0)
|
||||||
|
Assertions.assertEquals(c[Calendar.SECOND].toLong(), 0)
|
||||||
|
Assertions.assertEquals(c[Calendar.MILLISECOND].toLong(), 0)
|
||||||
|
// Assure we get the same time from cache
|
||||||
|
Assertions.assertEquals(midnight, MidnightTime.calc(now))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun resetCache() {
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
MidnightTime.calc(now)
|
||||||
|
MidnightTime.resetCache()
|
||||||
|
Assertions.assertEquals(0, MidnightTime.times.size().toLong())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun log() {
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
MidnightTime.calc(now)
|
||||||
|
Assertions.assertTrue(MidnightTime.log().startsWith("Hits:"))
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package info.nightscout.core.utils
|
||||||
|
|
||||||
|
import info.nightscout.interfaces.utils.Round
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class RoundTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun roundToTest() {
|
||||||
|
Assertions.assertEquals(0.55, Round.roundTo(0.54, 0.05), 0.00000000000000000001)
|
||||||
|
Assertions.assertEquals(-3.26, Round.roundTo(-3.2553715764602713, 0.01), 0.00000000000000000001)
|
||||||
|
Assertions.assertEquals(0.816, Round.roundTo(0.8156666666666667, 0.001), 0.00000000000000000001)
|
||||||
|
Assertions.assertEquals(0.235, Round.roundTo(0.235, 0.001), 0.00000000000000000001)
|
||||||
|
Assertions.assertEquals(0.3, Round.roundTo(0.3, 0.1), 0.00000000000000001)
|
||||||
|
Assertions.assertEquals(0.0017, Round.roundTo(0.0016960652144170627, 0.0001), 0.00000000000000000001)
|
||||||
|
Assertions.assertEquals(0.0078, Round.roundTo(0.007804436682291013, 0.0001), 0.00000000000000000001)
|
||||||
|
Assertions.assertEquals(0.6, Round.roundTo(0.6, 0.05), 0.00000000000000000001)
|
||||||
|
Assertions.assertEquals(1.0, Round.roundTo(1.49, 1.0), 0.00000000000000000001)
|
||||||
|
Assertions.assertEquals(0.0, Round.roundTo(0.0, 1.0), 0.00000000000000000001)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun floorToTest() {
|
||||||
|
Assertions.assertEquals(0.5, Round.floorTo(0.54, 0.05), 0.00000001)
|
||||||
|
Assertions.assertEquals(1.0, Round.floorTo(1.59, 1.0), 0.00000001)
|
||||||
|
Assertions.assertEquals(0.0, Round.floorTo(0.0, 1.0), 0.00000001)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun ceilToTest() {
|
||||||
|
Assertions.assertEquals(0.6, Round.ceilTo(0.54, 0.1), 0.00000001)
|
||||||
|
Assertions.assertEquals(2.0, Round.ceilTo(1.49999, 1.0), 0.00000001)
|
||||||
|
Assertions.assertEquals(0.0, Round.ceilTo(0.0, 1.0), 0.00000001)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun isSameTest() {
|
||||||
|
Assertions.assertTrue(Round.isSame(0.54, 0.54))
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package info.nightscout.core.utils
|
||||||
|
|
||||||
|
import info.nightscout.core.utils.receivers.StringUtils
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class StringUtilsTest {
|
||||||
|
|
||||||
|
@Test fun removeSurroundingQuotesTest() {
|
||||||
|
var compareString = "test"
|
||||||
|
Assertions.assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString))
|
||||||
|
Assertions.assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\""))
|
||||||
|
Assertions.assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString))
|
||||||
|
compareString = "te\"st"
|
||||||
|
Assertions.assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString))
|
||||||
|
Assertions.assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\""))
|
||||||
|
Assertions.assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString))
|
||||||
|
}
|
||||||
|
}
|
41
core/main/src/test/java/info/nightscout/core/utils/TTest.kt
Normal file
41
core/main/src/test/java/info/nightscout/core/utils/TTest.kt
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
package info.nightscout.core.utils
|
||||||
|
|
||||||
|
import info.nightscout.shared.utils.T
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
@Suppress("SpellCheckingInspection")
|
||||||
|
class TTest {
|
||||||
|
|
||||||
|
@Test fun toUnits() {
|
||||||
|
Assertions.assertEquals(1, T.msecs(1000).secs())
|
||||||
|
Assertions.assertEquals(1, T.secs(60).mins())
|
||||||
|
Assertions.assertEquals(1, T.mins(60).hours())
|
||||||
|
Assertions.assertEquals(1, T.hours(24).days())
|
||||||
|
Assertions.assertEquals(24, T.days(1).hours())
|
||||||
|
Assertions.assertEquals(60000, T.mins(1).msecs())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun now() {
|
||||||
|
Assertions.assertTrue(abs(T.now().msecs() - System.currentTimeMillis()) < 5000)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun additions() {
|
||||||
|
val nowMsecs = System.currentTimeMillis()
|
||||||
|
val now = T.msecs(nowMsecs)
|
||||||
|
Assertions.assertEquals(now.plus(T.secs(5)).msecs(), nowMsecs + 5 * 1000)
|
||||||
|
Assertions.assertEquals(now.plus(T.mins(5)).msecs(), nowMsecs + 5 * 60 * 1000)
|
||||||
|
Assertions.assertEquals(now.plus(T.hours(5)).msecs(), nowMsecs + 5 * 60 * 60 * 1000)
|
||||||
|
Assertions.assertEquals(now.plus(T.days(5)).msecs(), nowMsecs + 5 * 24 * 60 * 60 * 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun subtractions() {
|
||||||
|
val nowMsecs = System.currentTimeMillis()
|
||||||
|
val now = T.msecs(nowMsecs)
|
||||||
|
Assertions.assertEquals(now.minus(T.secs(5)).msecs(), nowMsecs - 5 * 1000)
|
||||||
|
Assertions.assertEquals(now.minus(T.mins(5)).msecs(), nowMsecs - 5 * 60 * 1000)
|
||||||
|
Assertions.assertEquals(now.minus(T.hours(5)).msecs(), nowMsecs - 5 * 60 * 60 * 1000)
|
||||||
|
Assertions.assertEquals(now.minus(T.days(5)).msecs(), nowMsecs - 5 * 24 * 60 * 60 * 1000)
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,10 +2,10 @@ package info.nightscout.core.wizard
|
||||||
|
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.TestBase
|
|
||||||
import info.nightscout.interfaces.aps.Loop
|
import info.nightscout.interfaces.aps.Loop
|
||||||
import info.nightscout.interfaces.profile.ProfileFunction
|
import info.nightscout.interfaces.profile.ProfileFunction
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
|
import info.nightscout.sharedtests.TestBase
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
|
Loading…
Reference in a new issue