Skip to content

Commit 3ae3b2a

Browse files
add floor
1 parent debb8dd commit 3ae3b2a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.examplehub.maths;
2+
3+
public class Floor {
4+
public static int floor(double number) {
5+
return number - (int) number >= 0 ? (int) number : (int) number - 1;
6+
}
7+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.examplehub.maths;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class FloorTest {
8+
@Test
9+
void testFloor() {
10+
assertEquals(Math.floor(123.45), Floor.floor(123.45));
11+
assertEquals(Math.floor(3.14), Floor.floor(3.14));
12+
assertEquals(Math.floor(1), Floor.floor(1));
13+
assertEquals(Math.floor(0), Floor.floor(0));
14+
assertEquals(Math.floor(-3.14), Floor.floor(-3.14));
15+
assertEquals(Math.floor(-3.14), Floor.floor(-3.14));
16+
assertEquals(Math.floor(-3), Floor.floor(-3));
17+
assertEquals(Math.floor(-123.45), Floor.floor(-123.45));
18+
}
19+
}

0 commit comments

Comments
 (0)