|
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
4 | 4 |
|
5 |
| -import org.junit.jupiter.api.Test; |
| 5 | +import java.util.stream.Stream; |
| 6 | +import org.junit.jupiter.params.ParameterizedTest; |
| 7 | +import org.junit.jupiter.params.provider.CsvSource; |
| 8 | +import org.junit.jupiter.params.provider.MethodSource; |
6 | 9 |
|
7 | 10 | public class CeilTest {
|
8 | 11 |
|
9 |
| - @Test |
10 |
| - void testCeil() { |
11 |
| - assertEquals(8, Ceil.ceil(7.057)); |
12 |
| - assertEquals(8, Ceil.ceil(7.004)); |
13 |
| - assertEquals(-13, Ceil.ceil(-13.004)); |
14 |
| - assertEquals(1, Ceil.ceil(.98)); |
15 |
| - assertEquals(-11, Ceil.ceil(-11.357)); |
| 12 | + @ParameterizedTest |
| 13 | + @CsvSource({"7.057, 8", "7.004, 8", "-13.004, -13", "0.98, 1", "-11.357, -11"}) |
| 14 | + void testCeil(double input, int expected) { |
| 15 | + assertEquals(expected, Ceil.ceil(input)); |
| 16 | + } |
| 17 | + |
| 18 | + @ParameterizedTest |
| 19 | + @MethodSource("edgeCaseProvider") |
| 20 | + void testEdgeCases(TestData data) { |
| 21 | + assertEquals(Ceil.ceil(data.input), data.expected); |
| 22 | + } |
| 23 | + |
| 24 | + record TestData(double input, double expected) { |
| 25 | + } |
| 26 | + |
| 27 | + static Stream<TestData> edgeCaseProvider() { |
| 28 | + return Stream.of(new TestData(Double.MAX_VALUE, Double.MAX_VALUE), new TestData(Double.MIN_VALUE, Math.ceil(Double.MIN_VALUE)), new TestData(0.0, Math.ceil(0.0)), new TestData(-0.0, Math.ceil(-0.0)), new TestData(Double.NaN, Math.ceil(Double.NaN)), |
| 29 | + new TestData(Double.NEGATIVE_INFINITY, Math.ceil(Double.NEGATIVE_INFINITY)), new TestData(Double.POSITIVE_INFINITY, Math.ceil(Double.POSITIVE_INFINITY))); |
16 | 30 | }
|
17 | 31 | }
|
0 commit comments