parent
e259d8e45e
commit
c7c858a46b
1 changed files with 16 additions and 16 deletions
|
@ -5,11 +5,11 @@ import app.aaps.plugins.automation.R
|
|||
import app.aaps.plugins.automation.elements.Comparator
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
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.ArgumentMatchers
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.skyscreamer.jsonassert.JSONAssert
|
||||
|
||||
class TriggerIobTest : TriggerTestBase() {
|
||||
|
||||
|
@ -20,43 +20,43 @@ class TriggerIobTest : TriggerTestBase() {
|
|||
@Test fun shouldRunTest() {
|
||||
`when`(iobCobCalculator.calculateFromTreatmentsAndTemps(ArgumentMatchers.anyLong(), anyObject())).thenReturn(generateIobRecordData())
|
||||
var t: TriggerIob = TriggerIob(injector).setValue(1.1).comparator(Comparator.Compare.IS_EQUAL)
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isFalse()
|
||||
t = TriggerIob(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
t = TriggerIob(injector).setValue(0.8).comparator(Comparator.Compare.IS_GREATER)
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
t = TriggerIob(injector).setValue(0.8).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
t = TriggerIob(injector).setValue(0.9).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
t = TriggerIob(injector).setValue(1.2).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
t = TriggerIob(injector).setValue(1.1).comparator(Comparator.Compare.IS_EQUAL)
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isFalse()
|
||||
t = TriggerIob(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
t = TriggerIob(injector).setValue(0.9).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isFalse()
|
||||
}
|
||||
|
||||
@Test fun copyConstructorTest() {
|
||||
val t: TriggerIob = TriggerIob(injector).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
Assertions.assertEquals(213.0, t.insulin.value, 0.01)
|
||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
||||
assertThat(t.insulin.value).isWithin(0.01).of(213.0)
|
||||
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
}
|
||||
|
||||
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"insulin\":4.1},\"type\":\"TriggerIob\"}"
|
||||
@Test fun toJSONTest() {
|
||||
val t: TriggerIob = TriggerIob(injector).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
|
||||
Assertions.assertEquals(bgJson, t.toJSON())
|
||||
JSONAssert.assertEquals(bgJson, t.toJSON(), true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromJSONTest() {
|
||||
val t: TriggerIob = TriggerIob(injector).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
|
||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerIob
|
||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
||||
Assertions.assertEquals(4.1, t2.insulin.value, 0.01)
|
||||
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
|
||||
assertThat(t2.insulin.value).isWithin(0.01).of(4.1)
|
||||
}
|
||||
|
||||
@Test fun iconTest() {
|
||||
|
@ -68,4 +68,4 @@ class TriggerIobTest : TriggerTestBase() {
|
|||
iobTotal.iob = 1.0
|
||||
return iobTotal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue