Skip to content

Commit 155567b

Browse files
authored
Make Division of Two Integers Result in a Float (eugenp#12658)
1 parent ae0d5f4 commit 155567b

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.baeldung.intdivision;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
class IntegerDivisionUnitTest {
8+
@Test
9+
void givenTwoInt_whenExecDivision_shouldGetInteger() {
10+
int i = 10 / 4;
11+
assertEquals(2, i);
12+
13+
float x = 10 / 4;
14+
assertEquals(2, x);
15+
}
16+
17+
@Test
18+
void givenTwoInt_whenCastAnyoneToFloat_shouldGetFloatResult() {
19+
float x = (float) 10 / 4;
20+
assertEquals(2.5, x);
21+
22+
float y = 10 / (float) 8;
23+
assertEquals(1.25, y);
24+
}
25+
26+
}

0 commit comments

Comments
 (0)