37 lines
942 B
Java
Raw Normal View History

2019-12-14 20:56:56 +05:30
package com.baeldung.doubletolong;
import org.junit.Assert;
import org.junit.Test;
public class DoubleToLongUnitTest {
final static double VALUE = 9999.999;
@Test
2019-12-31 19:25:24 +05:30
public void givenDoubleValue_whenLongValueCalled_thenLongValueReturned() {
2019-12-14 20:56:56 +05:30
Assert.assertEquals(9999L, Double.valueOf(VALUE)
.longValue());
}
@Test
2019-12-31 19:25:24 +05:30
public void givenDoubleValue_whenMathRoundUseds_thenLongValueReturned() {
2019-12-14 20:56:56 +05:30
Assert.assertEquals(10000L, Math.round(VALUE));
}
@Test
2019-12-31 19:25:24 +05:30
public void givenDoubleValue_whenMathCeilUsed_thenLongValueReturned() {
2019-12-14 20:56:56 +05:30
Assert.assertEquals(10000L, Math.ceil(VALUE), 0);
}
@Test
2019-12-31 19:25:24 +05:30
public void givenDoubleValue_whenMathFloorUsed_thenLongValueReturned() {
2019-12-14 20:56:56 +05:30
Assert.assertEquals(9999L, Math.floor(VALUE), 0);
}
@Test
2019-12-31 19:25:24 +05:30
public void givenDoubleValue_whenTypeCasted_thenLongValueReturned() {
2019-12-14 20:56:56 +05:30
Assert.assertEquals(9999L, (long) VALUE);
}
}