Rewrites BlockExtensionKtTest with matchers

This commit is contained in:
Ryan Haining 2023-09-20 22:32:07 -07:00
parent 1448eb9394
commit 571c95a859

View file

@ -1,10 +1,10 @@
package info.nightscout.core.extensions
import com.google.common.truth.Truth.assertThat
import info.nightscout.database.entities.data.Block
import info.nightscout.database.entities.data.TargetBlock
import info.nightscout.database.entities.data.checkSanity
import info.nightscout.shared.utils.T
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class BlockExtensionKtTest {
@ -17,36 +17,36 @@ class BlockExtensionKtTest {
b.add(Block(T.hours(10).msecs(), 3.0))
b.add(Block(T.hours(12).msecs(), 4.0))
Assertions.assertTrue(b.checkSanity())
assertThat(b.checkSanity()).isTrue()
Assertions.assertEquals(1.0, b.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0), 0.01)
Assertions.assertEquals(2.0, b.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0), 0.01)
Assertions.assertEquals(3.0, b.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0), 0.01)
Assertions.assertEquals(3.0, b.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0), 0.01)
Assertions.assertEquals(4.0, b.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0), 0.01)
Assertions.assertEquals(4.0, b.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0), 0.01)
assertThat(b.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0)).isWithin(0.01).of(1.0)
assertThat(b.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0)).isWithin(0.01).of(2.0)
assertThat(b.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0)).isWithin(0.01).of(3.0)
assertThat(b.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0)).isWithin(0.01).of(3.0)
assertThat(b.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0)).isWithin(0.01).of(4.0)
assertThat(b.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0)).isWithin(0.01).of(4.0)
val s1 = b.shiftBlock(1.0, -1)
Assertions.assertTrue(s1.checkSanity())
assertThat(s1.checkSanity()).isTrue()
Assertions.assertEquals(1.0, s1.blockValueBySeconds(T.hours(23).secs().toInt(), 1.0, 0), 0.01)
Assertions.assertEquals(2.0, s1.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0), 0.01)
Assertions.assertEquals(3.0, s1.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0), 0.01)
Assertions.assertEquals(3.0, s1.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0), 0.01)
Assertions.assertEquals(4.0, s1.blockValueBySeconds(T.hours(11).secs().toInt(), 1.0, 0), 0.01)
Assertions.assertEquals(4.0, s1.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0), 0.01)
assertThat(s1.blockValueBySeconds(T.hours(23).secs().toInt(), 1.0, 0)).isWithin(0.01).of(1.0)
assertThat(s1.blockValueBySeconds(T.hours(0).secs().toInt(), 1.0, 0)).isWithin(0.01).of(2.0)
assertThat(s1.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0)).isWithin(0.01).of(3.0)
assertThat(s1.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0)).isWithin(0.01).of(3.0)
assertThat(s1.blockValueBySeconds(T.hours(11).secs().toInt(), 1.0, 0)).isWithin(0.01).of(4.0)
assertThat(s1.blockValueBySeconds(T.hours(12).secs().toInt(), 1.0, 0)).isWithin(0.01).of(4.0)
val s2 = b.shiftBlock(2.0, 1)
Assertions.assertTrue(s2.checkSanity())
assertThat(s2.checkSanity()).isTrue()
Assertions.assertEquals(2.0, s2.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0), 0.01)
Assertions.assertEquals(4.0, s2.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0), 0.01)
Assertions.assertEquals(6.0, s2.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0), 0.01)
Assertions.assertEquals(6.0, s2.blockValueBySeconds(T.hours(4).secs().toInt(), 1.0, 0), 0.01)
Assertions.assertEquals(8.0, s2.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0), 0.01)
Assertions.assertEquals(8.0, s2.blockValueBySeconds(T.hours(14).secs().toInt(), 1.0, 0), 0.01)
assertThat(s2.blockValueBySeconds(T.hours(1).secs().toInt(), 1.0, 0)).isWithin(0.01).of(2.0)
assertThat(s2.blockValueBySeconds(T.hours(2).secs().toInt(), 1.0, 0)).isWithin(0.01).of(4.0)
assertThat(s2.blockValueBySeconds(T.hours(3).secs().toInt(), 1.0, 0)).isWithin(0.01).of(6.0)
assertThat(s2.blockValueBySeconds(T.hours(4).secs().toInt(), 1.0, 0)).isWithin(0.01).of(6.0)
assertThat(s2.blockValueBySeconds(T.hours(13).secs().toInt(), 1.0, 0)).isWithin(0.01).of(8.0)
assertThat(s2.blockValueBySeconds(T.hours(14).secs().toInt(), 1.0, 0)).isWithin(0.01).of(8.0)
}
@Test
@ -57,36 +57,36 @@ class BlockExtensionKtTest {
b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0))
b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0))
Assertions.assertTrue(b.checkSanity())
assertThat(b.checkSanity()).isTrue()
Assertions.assertEquals(1.5, b.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01)
Assertions.assertEquals(2.5, b.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01)
Assertions.assertEquals(3.5, b.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01)
Assertions.assertEquals(3.5, b.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01)
Assertions.assertEquals(4.5, b.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01)
Assertions.assertEquals(4.5, b.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01)
assertThat(b.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0)).isWithin(0.01).of(1.5)
assertThat(b.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0)).isWithin(0.01).of(2.5)
assertThat(b.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0)).isWithin(0.01).of(3.5)
assertThat(b.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0)).isWithin(0.01).of(3.5)
assertThat(b.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0)).isWithin(0.01).of(4.5)
assertThat(b.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0)).isWithin(0.01).of(4.5)
val s1 = b.shiftTargetBlock(-1)
Assertions.assertTrue(s1.checkSanity())
assertThat(s1.checkSanity()).isTrue()
Assertions.assertEquals(1.5, s1.targetBlockValueBySeconds(T.hours(23).secs().toInt(), 0), 0.01)
Assertions.assertEquals(2.5, s1.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01)
Assertions.assertEquals(3.5, s1.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01)
Assertions.assertEquals(3.5, s1.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01)
Assertions.assertEquals(4.5, s1.targetBlockValueBySeconds(T.hours(11).secs().toInt(), 0), 0.01)
Assertions.assertEquals(4.5, s1.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01)
assertThat(s1.targetBlockValueBySeconds(T.hours(23).secs().toInt(), 0)).isWithin(0.01).of(1.5)
assertThat(s1.targetBlockValueBySeconds(T.hours(0).secs().toInt(), 0)).isWithin(0.01).of(2.5)
assertThat(s1.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0)).isWithin(0.01).of(3.5)
assertThat(s1.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0)).isWithin(0.01).of(3.5)
assertThat(s1.targetBlockValueBySeconds(T.hours(11).secs().toInt(), 0)).isWithin(0.01).of(4.5)
assertThat(s1.targetBlockValueBySeconds(T.hours(12).secs().toInt(), 0)).isWithin(0.01).of(4.5)
val s2 = b.shiftTargetBlock(1)
Assertions.assertTrue(s2.checkSanity())
assertThat(s2.checkSanity()).isTrue()
Assertions.assertEquals(1.5, s2.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01)
Assertions.assertEquals(2.5, s2.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01)
Assertions.assertEquals(3.5, s2.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01)
Assertions.assertEquals(3.5, s2.targetBlockValueBySeconds(T.hours(4).secs().toInt(), 0), 0.01)
Assertions.assertEquals(4.5, s2.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01)
Assertions.assertEquals(4.5, s2.targetBlockValueBySeconds(T.hours(14).secs().toInt(), 0), 0.01)
assertThat(s2.targetBlockValueBySeconds(T.hours(1).secs().toInt(), 0)).isWithin(0.01).of(1.5)
assertThat(s2.targetBlockValueBySeconds(T.hours(2).secs().toInt(), 0)).isWithin(0.01).of(2.5)
assertThat(s2.targetBlockValueBySeconds(T.hours(3).secs().toInt(), 0)).isWithin(0.01).of(3.5)
assertThat(s2.targetBlockValueBySeconds(T.hours(4).secs().toInt(), 0)).isWithin(0.01).of(3.5)
assertThat(s2.targetBlockValueBySeconds(T.hours(13).secs().toInt(), 0)).isWithin(0.01).of(4.5)
assertThat(s2.targetBlockValueBySeconds(T.hours(14).secs().toInt(), 0)).isWithin(0.01).of(4.5)
}
@Test
@ -97,14 +97,14 @@ class BlockExtensionKtTest {
b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0))
b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0))
Assertions.assertTrue(b.checkSanity())
assertThat(b.checkSanity()).isTrue()
Assertions.assertEquals(1.0, b.lowTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01)
Assertions.assertEquals(2.0, b.lowTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01)
Assertions.assertEquals(3.0, b.lowTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01)
Assertions.assertEquals(3.0, b.lowTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01)
Assertions.assertEquals(4.0, b.lowTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01)
Assertions.assertEquals(4.0, b.lowTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01)
assertThat(b.lowTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0)).isWithin(0.01).of(1.0)
assertThat(b.lowTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0)).isWithin(0.01).of(2.0)
assertThat(b.lowTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0)).isWithin(0.01).of(3.0)
assertThat(b.lowTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0)).isWithin(0.01).of(3.0)
assertThat(b.lowTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0)).isWithin(0.01).of(4.0)
assertThat(b.lowTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0)).isWithin(0.01).of(4.0)
}
@Test
@ -115,13 +115,13 @@ class BlockExtensionKtTest {
b.add(TargetBlock(T.hours(10).msecs(), 3.0, 4.0))
b.add(TargetBlock(T.hours(12).msecs(), 4.0, 5.0))
Assertions.assertTrue(b.checkSanity())
assertThat(b.checkSanity()).isTrue()
Assertions.assertEquals(2.0, b.highTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0), 0.01)
Assertions.assertEquals(3.0, b.highTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0), 0.01)
Assertions.assertEquals(4.0, b.highTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0), 0.01)
Assertions.assertEquals(4.0, b.highTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0), 0.01)
Assertions.assertEquals(5.0, b.highTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0), 0.01)
Assertions.assertEquals(5.0, b.highTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0), 0.01)
assertThat(b.highTargetBlockValueBySeconds(T.hours(0).secs().toInt(), 0)).isWithin(0.01).of(2.0)
assertThat(b.highTargetBlockValueBySeconds(T.hours(1).secs().toInt(), 0)).isWithin(0.01).of(3.0)
assertThat(b.highTargetBlockValueBySeconds(T.hours(2).secs().toInt(), 0)).isWithin(0.01).of(4.0)
assertThat(b.highTargetBlockValueBySeconds(T.hours(3).secs().toInt(), 0)).isWithin(0.01).of(4.0)
assertThat(b.highTargetBlockValueBySeconds(T.hours(12).secs().toInt(), 0)).isWithin(0.01).of(5.0)
assertThat(b.highTargetBlockValueBySeconds(T.hours(13).secs().toInt(), 0)).isWithin(0.01).of(5.0)
}
}
}