BAEL-3517: Code Review Feedback Applied

This commit is contained in:
eric-martin
2020-01-01 16:59:11 -06:00
parent 2abb6a3955
commit 139664a549
3 changed files with 24 additions and 6 deletions

View File

@@ -0,0 +1,54 @@
package com.baeldung.doubletolong;
import org.junit.Assert;
import org.junit.Test;
public class DoubleToLongUnitTest {
final static double VALUE = 9999.999;
@Test
public void givenDoubleValue_whenLongValueCalled_thenLongValueReturned() {
Assert.assertEquals(9999L, Double.valueOf(VALUE).longValue());
}
@Test
public void givenDoubleValue_whenMathRoundUsed_thenLongValueReturned() {
Assert.assertEquals(10000L, Math.round(VALUE));
}
@Test
public void givenDoubleValue_whenMathRoundUsed_thenRoundDown() {
Assert.assertEquals(9999L, Math.round(9999.444));
}
@Test
public void givenDoubleValue_whenMathCeilUsed_thenLongValueReturned() {
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);
}
@Test
public void givenDoubleValue_whenMathFloorUsed_thenLongValueReturned() {
Assert.assertEquals(9999L, Math.floor(VALUE), 0);
}
@Test
public void givenDoubleValue_whenMathFloorUsed_thenSameValueReturned() {
Assert.assertEquals(9999L, Math.floor(9999.0), 0);
}
@Test
public void givenDoubleValue_whenTypeCasted_thenLongValueReturned() {
Assert.assertEquals(9999L, (long) VALUE);
}
}