parent
8966f0b8cc
commit
350172ebe7
1 changed files with 22 additions and 24 deletions
|
@ -5,11 +5,11 @@ import app.aaps.plugins.automation.elements.Comparator
|
||||||
import app.aaps.plugins.main.iob.iobCobCalculator.data.AutosensDataObject
|
import app.aaps.plugins.main.iob.iobCobCalculator.data.AutosensDataObject
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.junit.jupiter.api.Assertions
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.ArgumentMatchers
|
import org.mockito.ArgumentMatchers
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
|
||||||
class TriggerAutosensValueTest : TriggerTestBase() {
|
class TriggerAutosensValueTest : TriggerTestBase() {
|
||||||
|
|
||||||
|
@ -20,53 +20,53 @@ class TriggerAutosensValueTest : TriggerTestBase() {
|
||||||
var t = TriggerAutosensValue(injector)
|
var t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 110.0
|
t.autosens.value = 110.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL
|
t.comparator.value = Comparator.Compare.IS_EQUAL
|
||||||
Assertions.assertEquals(110.0, t.autosens.value, 0.01)
|
assertThat(t.autosens.value).isWithin(0.01).of(110.0)
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t.comparator.value)
|
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 100.0
|
t.autosens.value = 100.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL
|
t.comparator.value = Comparator.Compare.IS_EQUAL
|
||||||
Assertions.assertEquals(100.0, t.autosens.value, 0.01)
|
assertThat(t.autosens.value).isWithin(0.01).of(100.0)
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 50.0
|
t.autosens.value = 50.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 310.0
|
t.autosens.value = 310.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 420.0
|
t.autosens.value = 420.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL
|
t.comparator.value = Comparator.Compare.IS_EQUAL
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 390.0
|
t.autosens.value = 390.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 390.0
|
t.autosens.value = 390.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 20.0
|
t.autosens.value = 20.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_GREATER
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 390.0
|
t.autosens.value = 390.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
`when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(AutosensDataObject(injector))
|
`when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(AutosensDataObject(injector))
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 80.0
|
t.autosens.value = 80.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
||||||
Assertions.assertFalse(t.shouldRun())
|
assertThat(t.shouldRun()).isFalse()
|
||||||
|
|
||||||
// Test autosensData == null and Comparator == IS_NOT_AVAILABLE
|
// Test autosensData == null and Comparator == IS_NOT_AVAILABLE
|
||||||
`when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(null)
|
`when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(null)
|
||||||
t = TriggerAutosensValue(injector)
|
t = TriggerAutosensValue(injector)
|
||||||
t.comparator.value = Comparator.Compare.IS_NOT_AVAILABLE
|
t.comparator.value = Comparator.Compare.IS_NOT_AVAILABLE
|
||||||
Assertions.assertTrue(t.shouldRun())
|
assertThat(t.shouldRun()).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -75,8 +75,8 @@ class TriggerAutosensValueTest : TriggerTestBase() {
|
||||||
t.autosens.value = 213.0
|
t.autosens.value = 213.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER
|
||||||
val t1 = t.duplicate() as TriggerAutosensValue
|
val t1 = t.duplicate() as TriggerAutosensValue
|
||||||
Assertions.assertEquals(213.0, t1.autosens.value, 0.01)
|
assertThat(t1.autosens.value).isWithin(0.01).of(213.0)
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
assertThat(t.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var asJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"value\":410},\"type\":\"TriggerAutosensValue\"}"
|
private var asJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"value\":410},\"type\":\"TriggerAutosensValue\"}"
|
||||||
|
@ -86,7 +86,7 @@ class TriggerAutosensValueTest : TriggerTestBase() {
|
||||||
val t = TriggerAutosensValue(injector)
|
val t = TriggerAutosensValue(injector)
|
||||||
t.autosens.value = 410.0
|
t.autosens.value = 410.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL
|
t.comparator.value = Comparator.Compare.IS_EQUAL
|
||||||
Assertions.assertEquals(asJson, t.toJSON())
|
JSONAssert.assertEquals(asJson, t.toJSON(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -95,15 +95,13 @@ class TriggerAutosensValueTest : TriggerTestBase() {
|
||||||
t.autosens.value = 410.0
|
t.autosens.value = 410.0
|
||||||
t.comparator.value = Comparator.Compare.IS_EQUAL
|
t.comparator.value = Comparator.Compare.IS_EQUAL
|
||||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerAutosensValue
|
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerAutosensValue
|
||||||
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
|
assertThat(t2.comparator.value).isEqualTo(Comparator.Compare.IS_EQUAL)
|
||||||
Assertions.assertEquals(410.0, t2.autosens.value, 0.01)
|
assertThat(t2.autosens.value).isWithin(0.01).of(410.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun iconTest() {
|
@Test fun iconTest() {
|
||||||
assertThat(TriggerAutosensValue(injector).icon().get()).isEqualTo(R.drawable.ic_as)
|
assertThat(TriggerAutosensValue(injector).icon().get()).isEqualTo(R.drawable.ic_as)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateAutosensData(): AutosensDataObject {
|
private fun generateAutosensData() = AutosensDataObject(injector)
|
||||||
return AutosensDataObject(injector)
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue