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 io.reactivex.rxjava3.core.Single
|
||||
import org.json.JSONObject
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.skyscreamer.jsonassert.JSONAssert
|
||||
|
||||
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)
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isFalse()
|
||||
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)
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
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)
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isFalse()
|
||||
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)
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isFalse()
|
||||
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)
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isFalse()
|
||||
assertThat(t.shouldRun()).isFalse()
|
||||
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()))
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun copyConstructorTest() {
|
||||
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
val t1 = t.duplicate() as TriggerTempTargetValue
|
||||
Assertions.assertEquals(140.0, t1.ttValue.value, 0.01)
|
||||
Assertions.assertEquals(GlucoseUnit.MGDL, t1.ttValue.units)
|
||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
||||
assertThat(t1.ttValue.value).isWithin(0.01).of(140.0)
|
||||
assertThat(t1.ttValue.units).isEqualTo(GlucoseUnit.MGDL)
|
||||
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\"}"
|
||||
|
@ -74,16 +74,16 @@ class TriggerTempTargetValueTest : TriggerTestBase() {
|
|||
@Test
|
||||
fun toJSONTest() {
|
||||
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
|
||||
fun fromJSONTest() {
|
||||
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
|
||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
||||
Assertions.assertEquals(7.7, t2.ttValue.value, 0.01)
|
||||
Assertions.assertEquals(GlucoseUnit.MMOL, t2.ttValue.units)
|
||||
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
|
||||
assertThat(t2.ttValue.value).isWithin(0.01).of(7.7)
|
||||
assertThat(t2.ttValue.units).isEqualTo(GlucoseUnit.MMOL)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue