Merge pull request #8462 from eugenp/BAEL-3517

BAEL-3517: Code Review Feedback Applied
This commit is contained in:
Eric Martin 2020-01-01 22:06:49 -06:00 committed by GitHub
commit 65a461f702
4 changed files with 66 additions and 38 deletions

View File

@ -3,7 +3,6 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>java-numbers-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>java-numbers-3</name>
<packaging>jar</packaging>
@ -13,7 +12,6 @@
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<build>
<finalName>java-numbers-3</finalName>

View File

@ -1,36 +0,0 @@
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_whenMathRoundUseds_thenLongValueReturned() {
Assert.assertEquals(10000L, Math.round(VALUE));
}
@Test
public void givenDoubleValue_whenMathCeilUsed_thenLongValueReturned() {
Assert.assertEquals(10000L, Math.ceil(VALUE), 0);
}
@Test
public void givenDoubleValue_whenMathFloorUsed_thenLongValueReturned() {
Assert.assertEquals(9999L, Math.floor(VALUE), 0);
}
@Test
public void givenDoubleValue_whenTypeCasted_thenLongValueReturned() {
Assert.assertEquals(9999L, (long) VALUE);
}
}

View File

@ -0,0 +1,64 @@
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_thenRoundUp() {
Assert.assertEquals(10000L, Math.round(VALUE));
}
@Test
public void givenDoubleValue_whenMathRoundUsed_thenRoundDown() {
Assert.assertEquals(9999L, Math.round(9999.444));
}
@Test
public void givenDoubleValue_whenMathRoundUsed_thenSameValueReturned() {
Assert.assertEquals(9999L, Math.round(9999.0));
}
@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_whenMathFloorUsed_thenDifferentThanCeil() {
Assert.assertEquals(9999L, Math.floor(9999.444), 0);
}
@Test
public void givenDoubleValue_whenTypeCasted_thenLongValueReturned() {
Assert.assertEquals(9999L, (long) VALUE);
}
}

View File

@ -512,6 +512,7 @@
<module>java-math-2</module> <!-- Added for BAEL-3506 -->
<module>java-numbers</module>
<module>java-numbers-2</module>
<module>java-numbers-3</module>
<module>java-rmi</module>
<module>java-spi</module>
<module>java-vavr-stream</module>
@ -1146,6 +1147,7 @@
<module>java-math-2</module> <!-- Added for BAEL-3506 -->
<module>java-numbers</module>
<module>java-numbers-2</module>
<module>java-numbers-3</module>
<module>java-rmi</module>
<module>java-spi</module>
<module>java-vavr-stream</module>