Rewrites RoundTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-09-20 23:07:43 -07:00
parent e793620b6f
commit 309f823cc4

View file

@ -1,41 +1,41 @@
package info.nightscout.core.utils package info.nightscout.core.utils
import com.google.common.truth.Truth.assertThat
import info.nightscout.interfaces.utils.Round import info.nightscout.interfaces.utils.Round
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class RoundTest { class RoundTest {
@Test @Test
fun roundToTest() { fun roundToTest() {
Assertions.assertEquals(0.55, Round.roundTo(0.54, 0.05), 0.00000000000000000001) assertThat(Round.roundTo(0.54, 0.05)).isWithin(0.00000000000000000001).of(0.55)
Assertions.assertEquals(-3.26, Round.roundTo(-3.2553715764602713, 0.01), 0.00000000000000000001) assertThat(Round.roundTo(-3.2553715764602713, 0.01)).isWithin(0.00000000000000000001).of(-3.26)
Assertions.assertEquals(0.816, Round.roundTo(0.8156666666666667, 0.001), 0.00000000000000000001) assertThat(Round.roundTo(0.8156666666666667, 0.001)).isWithin(0.00000000000000000001).of(0.816)
Assertions.assertEquals(0.235, Round.roundTo(0.235, 0.001), 0.00000000000000000001) assertThat(Round.roundTo(0.235, 0.001)).isWithin(0.00000000000000000001).of(0.235)
Assertions.assertEquals(0.3, Round.roundTo(0.3, 0.1), 0.00000000000000001) assertThat(Round.roundTo(0.3, 0.1)).isWithin(0.00000000000000001).of(0.3)
Assertions.assertEquals(0.0017, Round.roundTo(0.0016960652144170627, 0.0001), 0.00000000000000000001) assertThat(Round.roundTo(0.0016960652144170627, 0.0001)).isWithin(0.00000000000000000001).of(0.0017)
Assertions.assertEquals(0.0078, Round.roundTo(0.007804436682291013, 0.0001), 0.00000000000000000001) assertThat(Round.roundTo(0.007804436682291013, 0.0001)).isWithin(0.00000000000000000001).of(0.0078)
Assertions.assertEquals(0.6, Round.roundTo(0.6, 0.05), 0.00000000000000000001) assertThat(Round.roundTo(0.6, 0.05)).isWithin(0.00000000000000000001).of(0.6)
Assertions.assertEquals(1.0, Round.roundTo(1.49, 1.0), 0.00000000000000000001) assertThat(Round.roundTo(1.49, 1.0)).isWithin(0.00000000000000000001).of(1.0)
Assertions.assertEquals(0.0, Round.roundTo(0.0, 1.0), 0.00000000000000000001) assertThat(Round.roundTo(0.0, 1.0)).isWithin(0.00000000000000000001).of(0.0)
} }
@Test @Test
fun floorToTest() { fun floorToTest() {
Assertions.assertEquals(0.5, Round.floorTo(0.54, 0.05), 0.00000001) assertThat(Round.floorTo(0.54, 0.05)).isWithin(0.00000001).of(0.5)
Assertions.assertEquals(1.0, Round.floorTo(1.59, 1.0), 0.00000001) assertThat(Round.floorTo(1.59, 1.0)).isWithin(0.00000001).of(1.0)
Assertions.assertEquals(0.0, Round.floorTo(0.0, 1.0), 0.00000001) assertThat(Round.floorTo(0.0, 1.0)).isWithin(0.00000001).of(0.0)
} }
@Test @Test
fun ceilToTest() { fun ceilToTest() {
Assertions.assertEquals(0.6, Round.ceilTo(0.54, 0.1), 0.00000001) assertThat(Round.ceilTo(0.54, 0.1)).isWithin(0.00000001).of(0.6)
Assertions.assertEquals(2.0, Round.ceilTo(1.49999, 1.0), 0.00000001) assertThat(Round.ceilTo(1.49999, 1.0)).isWithin(0.00000001).of(2.0)
Assertions.assertEquals(0.0, Round.ceilTo(0.0, 1.0), 0.00000001) assertThat(Round.ceilTo(0.0, 1.0)).isWithin(0.00000001).of(0.0)
} }
@Test @Test
fun isSameTest() { fun isSameTest() {
Assertions.assertTrue(Round.isSame(0.54, 0.54)) assertThat(Round.isSame(0.54, 0.54)).isTrue()
} }
} }