From 309f823cc49298625c187402ccb85680f2db4e3a Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Wed, 20 Sep 2023 23:07:43 -0700 Subject: [PATCH] Rewrites RoundTest with matchers Issue #2745 --- .../info/nightscout/core/utils/RoundTest.kt | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/utils/RoundTest.kt b/core/main/src/test/java/info/nightscout/core/utils/RoundTest.kt index 0980add1fe..6d57c65c02 100644 --- a/core/main/src/test/java/info/nightscout/core/utils/RoundTest.kt +++ b/core/main/src/test/java/info/nightscout/core/utils/RoundTest.kt @@ -1,41 +1,41 @@ package info.nightscout.core.utils +import com.google.common.truth.Truth.assertThat import info.nightscout.interfaces.utils.Round -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test class RoundTest { @Test fun roundToTest() { - Assertions.assertEquals(0.55, Round.roundTo(0.54, 0.05), 0.00000000000000000001) - Assertions.assertEquals(-3.26, Round.roundTo(-3.2553715764602713, 0.01), 0.00000000000000000001) - Assertions.assertEquals(0.816, Round.roundTo(0.8156666666666667, 0.001), 0.00000000000000000001) - Assertions.assertEquals(0.235, Round.roundTo(0.235, 0.001), 0.00000000000000000001) - Assertions.assertEquals(0.3, Round.roundTo(0.3, 0.1), 0.00000000000000001) - Assertions.assertEquals(0.0017, Round.roundTo(0.0016960652144170627, 0.0001), 0.00000000000000000001) - Assertions.assertEquals(0.0078, Round.roundTo(0.007804436682291013, 0.0001), 0.00000000000000000001) - Assertions.assertEquals(0.6, Round.roundTo(0.6, 0.05), 0.00000000000000000001) - Assertions.assertEquals(1.0, Round.roundTo(1.49, 1.0), 0.00000000000000000001) - Assertions.assertEquals(0.0, Round.roundTo(0.0, 1.0), 0.00000000000000000001) + assertThat(Round.roundTo(0.54, 0.05)).isWithin(0.00000000000000000001).of(0.55) + assertThat(Round.roundTo(-3.2553715764602713, 0.01)).isWithin(0.00000000000000000001).of(-3.26) + assertThat(Round.roundTo(0.8156666666666667, 0.001)).isWithin(0.00000000000000000001).of(0.816) + assertThat(Round.roundTo(0.235, 0.001)).isWithin(0.00000000000000000001).of(0.235) + assertThat(Round.roundTo(0.3, 0.1)).isWithin(0.00000000000000001).of(0.3) + assertThat(Round.roundTo(0.0016960652144170627, 0.0001)).isWithin(0.00000000000000000001).of(0.0017) + assertThat(Round.roundTo(0.007804436682291013, 0.0001)).isWithin(0.00000000000000000001).of(0.0078) + assertThat(Round.roundTo(0.6, 0.05)).isWithin(0.00000000000000000001).of(0.6) + assertThat(Round.roundTo(1.49, 1.0)).isWithin(0.00000000000000000001).of(1.0) + assertThat(Round.roundTo(0.0, 1.0)).isWithin(0.00000000000000000001).of(0.0) } @Test fun floorToTest() { - Assertions.assertEquals(0.5, Round.floorTo(0.54, 0.05), 0.00000001) - Assertions.assertEquals(1.0, Round.floorTo(1.59, 1.0), 0.00000001) - Assertions.assertEquals(0.0, Round.floorTo(0.0, 1.0), 0.00000001) + assertThat(Round.floorTo(0.54, 0.05)).isWithin(0.00000001).of(0.5) + assertThat(Round.floorTo(1.59, 1.0)).isWithin(0.00000001).of(1.0) + assertThat(Round.floorTo(0.0, 1.0)).isWithin(0.00000001).of(0.0) } @Test fun ceilToTest() { - Assertions.assertEquals(0.6, Round.ceilTo(0.54, 0.1), 0.00000001) - Assertions.assertEquals(2.0, Round.ceilTo(1.49999, 1.0), 0.00000001) - Assertions.assertEquals(0.0, Round.ceilTo(0.0, 1.0), 0.00000001) + assertThat(Round.ceilTo(0.54, 0.1)).isWithin(0.00000001).of(0.6) + assertThat(Round.ceilTo(1.49999, 1.0)).isWithin(0.00000001).of(2.0) + assertThat(Round.ceilTo(0.0, 1.0)).isWithin(0.00000001).of(0.0) } @Test fun isSameTest() { - Assertions.assertTrue(Round.isSame(0.54, 0.54)) + assertThat(Round.isSame(0.54, 0.54)).isTrue() } -} \ No newline at end of file +}