Rewrites ProgramBasalCommandTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-10-08 20:49:20 -07:00
parent 77964df4ae
commit 9840cf81c8

View file

@ -1,17 +1,16 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command
import com.google.common.truth.Truth.assertThat
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BasalProgram
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ProgramReminder
import org.apache.commons.codec.DecoderException
import org.apache.commons.codec.binary.Hex
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import java.util.Date
@Suppress("DEPRECATION")
class ProgramBasalCommandTest {
@Test @Throws(DecoderException::class) fun testProgramBasalCommand() {
@Test fun testProgramBasalCommand() {
val segments = listOf(
BasalProgram.Segment(0.toShort(), 48.toShort(), 300)
)
@ -28,13 +27,10 @@ class ProgramBasalCommandTest {
.build()
.encoded
Assertions.assertArrayEquals(
Hex.decodeHex("0242000128241A12494E532E0005E81D1708000CF01EF01EF01E130E40001593004C4B403840005B8D80827C"),
encoded
)
assertThat(encoded).asList().containsExactlyElementsIn(Hex.decodeHex("0242000128241A12494E532E0005E81D1708000CF01EF01EF01E130E40001593004C4B403840005B8D80827C").asList()).inOrder()
}
@Test @Throws(DecoderException::class) fun testProgramBasalCommandWithExtraAlternateSegmentPulse() {
@Test fun testProgramBasalCommandWithExtraAlternateSegmentPulse() {
val segments = listOf(
BasalProgram.Segment(0.toShort(), 48.toShort(), 5)
)
@ -51,13 +47,10 @@ class ProgramBasalCommandTest {
.build()
.encoded
Assertions.assertArrayEquals(
Hex.decodeHex("0000109130241a12494e532e0000c52e0f700000f800f800f800130e0000000707fcad8000f015752a00033b"),
encoded
)
assertThat(encoded).asList().containsExactlyElementsIn(Hex.decodeHex("0000109130241a12494e532e0000c52e0f700000f800f800f800130e0000000707fcad8000f015752a00033b").asList()).inOrder()
}
@Test @Throws(DecoderException::class) fun testProgramBasalCommandAllSegments() {
@Test fun testProgramBasalCommandAllSegments() {
val segments = mutableListOf<BasalProgram.Segment>()
for (segment in 0..23) {
val rate = when (segment) {
@ -95,15 +88,10 @@ class ProgramBasalCommandTest {
val expected =
"0000000508C41A28494E532E00018B16273000032000300130023003300430053006300730083009200A100B100C180D1398400B005E009E22E80002EB49D200000A15752A0000140ABA9500001E07270E000028055D4A800032044AA200003C0393870000460310BCDB005002AEA540005A02625A00006402255100006E01F360E8007801C9C380008201A68D13008C01885E6D0096016E360000A0015752A000AA0143209600B401312D0000BE01211D2800C80112A88000DC00F9B07400F000E4E1C0010E00CB73558158".lowercase()
Assertions.assertArrayEquals(
Hex.decodeHex(
expected
),
encoded
)
assertThat(encoded).asList().containsExactlyElementsIn(Hex.decodeHex(expected).asList()).inOrder()
}
@Test @Throws(DecoderException::class) fun testProgramBasalCommandHighRates() {
@Test fun testProgramBasalCommandHighRates() {
val segments = listOf(
BasalProgram.Segment(0.toShort(), 2.toShort(), 300),
BasalProgram.Segment(2.toShort(), 4.toShort(), 290),
@ -140,15 +128,10 @@ class ProgramBasalCommandTest {
val expected =
"000000051C981A2C494E532E00046D162178000B101E101D101C101B101A301938173816101458123810380E300D180B100A180613684008013F008954400258005B8D800244005EB5B002300062179B021C0065B9AA02080069A34403E8006DDD0003AC0074E0360384007A12000190008954400456009476C1029400A675A2024400BD6B61020800D3468900E600EED54D00C80112A880008201A68D13809b"
Assertions.assertArrayEquals(
Hex.decodeHex(
expected
),
encoded
)
assertThat(encoded).asList().containsExactlyElementsIn(Hex.decodeHex(expected).asList()).inOrder()
}
@Test @Throws(DecoderException::class) fun testProgramBasalCommandDifferentInterval() {
@Test fun testProgramBasalCommandDifferentInterval() {
val segments = listOf(
BasalProgram.Segment(0.toShort(), 2.toShort(), 50),
BasalProgram.Segment(2.toShort(), 6.toShort(), 75),
@ -177,11 +160,6 @@ class ProgramBasalCommandTest {
val expected =
"0000000528581A1C494E532E00038E161E50000E100538075000780DB01B701D58091801133840040A100032DC82006402255100012C016E36000006EB49D200043800CB73550CA80065B9AA0910005EB5B0023A01211D28001E07270E000065"
Assertions.assertArrayEquals(
Hex.decodeHex(
expected
),
encoded
)
assertThat(encoded).asList().containsExactlyElementsIn(Hex.decodeHex(expected).asList()).inOrder()
}
}