65 lines
1.8 KiB
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() {
Assert.assertEquals(9999L, Double.valueOf(VALUE).longValue());
2019-12-14 20:56:56 +05:30
}
@Test
2020-01-01 17:51:52 -06:00
public void givenDoubleValue_whenMathRoundUsed_thenRoundUp() {
2019-12-14 20:56:56 +05:30
Assert.assertEquals(10000L, Math.round(VALUE));
}
@Test
public void givenDoubleValue_whenMathRoundUsed_thenRoundDown() {
Assert.assertEquals(9999L, Math.round(9999.444));
}
2020-01-01 17:51:52 -06:00
@Test
public void givenDoubleValue_whenMathRoundUsed_thenSameValueReturned() {
Assert.assertEquals(9999L, Math.round(9999.0));
}
2019-12-14 20:56:56 +05:30
@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
public void givenDoubleValue_whenMathCeilUsed_thenSameValueReturned() {
Assert.assertEquals(9999L, Math.ceil(9999.0), 0);
}
@Test
public void givenDoubleValue_whenMathCeilUsed_thenDifferentThanRound() {
Assert.assertEquals(10000L, Math.ceil(9999.444), 0);
}
2019-12-14 20:56:56 +05:30
@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
public void givenDoubleValue_whenMathFloorUsed_thenSameValueReturned() {
Assert.assertEquals(9999L, Math.floor(9999.0), 0);
}
2020-01-01 17:51:52 -06:00
@Test
public void givenDoubleValue_whenMathFloorUsed_thenDifferentThanCeil() {
Assert.assertEquals(9999L, Math.floor(9999.444), 0);
}
2019-12-14 20:56:56 +05:30
@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);
}
}