parent
f51206e417
commit
88cd20c4d6
1 changed files with 21 additions and 20 deletions
|
@ -6,10 +6,11 @@ import app.aaps.database.entities.GlucoseValue
|
|||
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 com.google.common.truth.Truth.assertThat
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.skyscreamer.jsonassert.JSONAssert
|
||||
|
||||
class TriggerBgTest : TriggerTestBase() {
|
||||
|
||||
|
@ -22,37 +23,37 @@ class TriggerBgTest : TriggerTestBase() {
|
|||
fun shouldRunTest() {
|
||||
`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateOneCurrentRecordBgData())
|
||||
var t: TriggerBg = TriggerBg(injector).setUnits(GlucoseUnit.MMOL).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isFalse()
|
||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(214.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(214.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(214.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(215.0).comparator(Comparator.Compare.IS_EQUAL)
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isFalse()
|
||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(215.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(215.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isFalse()
|
||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isFalse()
|
||||
`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(ArrayList())
|
||||
t = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isFalse()
|
||||
t = TriggerBg(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun copyConstructorTest() {
|
||||
val t: TriggerBg = TriggerBg(injector).setUnits(GlucoseUnit.MGDL).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
val t1 = t.duplicate() as TriggerBg
|
||||
Assertions.assertEquals(213.0, t1.bg.value, 0.01)
|
||||
Assertions.assertEquals(GlucoseUnit.MGDL, t1.bg.units)
|
||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
||||
assertThat(t1.bg.value).isWithin(0.01).of(213.0)
|
||||
assertThat(t1.bg.units).isEqualTo(GlucoseUnit.MGDL)
|
||||
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||
}
|
||||
|
||||
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"bg\":4.1,\"units\":\"mmol\"},\"type\":\"TriggerBg\"}"
|
||||
|
@ -60,16 +61,16 @@ class TriggerBgTest : TriggerTestBase() {
|
|||
@Test
|
||||
fun toJSONTest() {
|
||||
val t: TriggerBg = TriggerBg(injector).setUnits(GlucoseUnit.MMOL).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
|
||||
Assertions.assertEquals(bgJson, t.toJSON())
|
||||
JSONAssert.assertEquals(bgJson, t.toJSON(), true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromJSONTest() {
|
||||
val t: TriggerBg = TriggerBg(injector).setUnits(GlucoseUnit.MMOL).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
|
||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerBg
|
||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
||||
Assertions.assertEquals(4.1, t2.bg.value, 0.01)
|
||||
Assertions.assertEquals(GlucoseUnit.MMOL, t2.bg.units)
|
||||
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
|
||||
assertThat(t2.bg.value).isWithin(0.01).of(4.1)
|
||||
assertThat(t2.bg.units).isEqualTo(GlucoseUnit.MMOL)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue