mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-28 23:15:17 +08:00
Add FloorTest
and clean-up Floor
(#4769)
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Ricardo Ramos <0102016812@grupotel.corp>
This commit is contained in:
@ -1,15 +1,8 @@
|
||||
package com.thealgorithms.maths;
|
||||
|
||||
import java.util.Random;
|
||||
public final class Floor {
|
||||
|
||||
public class Floor {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Random random = new Random();
|
||||
for (int i = 1; i <= 1000; ++i) {
|
||||
double randomNumber = random.nextDouble();
|
||||
assert floor(randomNumber) == Math.floor(randomNumber);
|
||||
}
|
||||
private Floor() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
28
src/test/java/com/thealgorithms/maths/FloorTest.java
Normal file
28
src/test/java/com/thealgorithms/maths/FloorTest.java
Normal file
@ -0,0 +1,28 @@
|
||||
package com.thealgorithms.maths;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
public class FloorTest {
|
||||
@Test
|
||||
public void testFloorWholeNumber() {
|
||||
assertEquals(0, Floor.floor(0));
|
||||
assertEquals(1, Floor.floor(1));
|
||||
assertEquals(-1, Floor.floor(-1));
|
||||
assertEquals(42, Floor.floor(42));
|
||||
assertEquals(-42, Floor.floor(-42));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloorDoubleNumber() {
|
||||
assertEquals(0, Floor.floor(0.1));
|
||||
assertEquals(1, Floor.floor(1.9));
|
||||
assertEquals(-2, Floor.floor(-1.1));
|
||||
assertEquals(-43, Floor.floor(-42.7));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloorNegativeZero() {
|
||||
assertEquals(-0.0, Floor.floor(-0.0));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user