Rewrites IobTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-09-08 19:14:28 -07:00
parent 75ff796510
commit f639a78ff4

View file

@ -1,7 +1,7 @@
package info.nightscout.core.data
import com.google.common.truth.Truth.assertThat
import info.nightscout.interfaces.iob.Iob
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class IobTest {
@ -10,23 +10,23 @@ class IobTest {
val a = Iob().iobContrib(1.0).activityContrib(2.0)
val b = Iob().iobContrib(3.0).activityContrib(4.0)
a.plus(b)
Assertions.assertEquals(4.0, a.iobContrib, 0.01)
Assertions.assertEquals(6.0, a.activityContrib, 0.01)
assertThat(a.iobContrib).isWithin(0.01).of(4.0)
assertThat(a.activityContrib).isWithin(0.01).of(6.0)
}
@Test fun equalTest() {
val a1 = Iob().iobContrib(1.0).activityContrib(2.0)
val a2 = Iob().iobContrib(1.0).activityContrib(2.0)
val b = Iob().iobContrib(3.0).activityContrib(4.0)
Assertions.assertTrue(a1 == a2)
Assertions.assertFalse(a1 == b)
@Suppress("SENSELESS_COMPARISON")
Assertions.assertFalse(a1 == null)
Assertions.assertFalse(a1 == Any())
assertThat(a1).isEqualTo(a1)
assertThat(a1).isEqualTo(a2)
assertThat(a1).isNotEqualTo(b)
assertThat(a1).isNotNull()
assertThat(a1).isNotEqualTo(Any())
}
@Test fun hashCodeTest() {
val a = Iob().iobContrib(1.0).activityContrib(2.0)
Assertions.assertNotEquals(0, a.hashCode().toLong())
assertThat(a.hashCode().toLong()).isNotEqualTo(0L)
}
}