parent
88cd20c4d6
commit
8966f0b8cc
1 changed files with 20 additions and 20 deletions
|
@ -8,10 +8,10 @@ import app.aaps.plugins.automation.elements.Comparator
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.junit.jupiter.api.Assertions
|
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class TriggerTempTargetValueTest : TriggerTestBase() {
|
class TriggerTempTargetValueTest : TriggerTestBase() {
|
||||||
|
|
||||||
|
@ -36,37 +36,37 @@ class TriggerTempTargetValueTest : TriggerTestBase() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
var t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
|
var t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(141.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(141.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(141.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(141.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerTempTargetValue(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
t = TriggerTempTargetValue(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
`when`(repository.getTemporaryTargetActiveAt(dateUtil.now())).thenReturn(Single.just(ValueWrapper.Absent()))
|
`when`(repository.getTemporaryTargetActiveAt(dateUtil.now())).thenReturn(Single.just(ValueWrapper.Absent()))
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun copyConstructorTest() {
|
fun copyConstructorTest() {
|
||||||
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
val t1 = t.duplicate() as TriggerTempTargetValue
|
val t1 = t.duplicate() as TriggerTempTargetValue
|
||||||
Assertions.assertEquals(140.0, t1.ttValue.value, 0.01)
|
assertThat(t1.ttValue.value).isWithin(0.01).of(140.0)
|
||||||
Assertions.assertEquals(GlucoseUnit.MGDL, t1.ttValue.units)
|
assertThat(t1.ttValue.units).isEqualTo(GlucoseUnit.MGDL)
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var ttJson = "{\"data\":{\"tt\":7.7,\"comparator\":\"IS_EQUAL\",\"units\":\"mmol\"},\"type\":\"TriggerTempTargetValue\"}"
|
private var ttJson = "{\"data\":{\"tt\":7.7,\"comparator\":\"IS_EQUAL\",\"units\":\"mmol\"},\"type\":\"TriggerTempTargetValue\"}"
|
||||||
|
@ -74,16 +74,16 @@ class TriggerTempTargetValueTest : TriggerTestBase() {
|
||||||
@Test
|
@Test
|
||||||
fun toJSONTest() {
|
fun toJSONTest() {
|
||||||
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(ttJson, t.toJSON())
|
JSONAssert.assertEquals(ttJson, t.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun fromJSONTest() {
|
fun fromJSONTest() {
|
||||||
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
|
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTempTargetValue
|
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTempTargetValue
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(7.7, t2.ttValue.value, 0.01)
|
assertThat(t2.ttValue.value).isWithin(0.01).of(7.7)
|
||||||
Assertions.assertEquals(GlucoseUnit.MMOL, t2.ttValue.units)
|
assertThat(t2.ttValue.units).isEqualTo(GlucoseUnit.MMOL)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue