parent
e793620b6f
commit
309f823cc4
1 changed files with 19 additions and 19 deletions
|
@ -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()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue