|
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; |
4 | 4 |
|
| 5 | +import java.util.Arrays; |
| 6 | +import java.util.Collection; |
| 7 | + |
5 | 8 | import org.junit.jupiter.params.ParameterizedTest; |
6 | | -import org.junit.jupiter.params.provider.CsvSource; |
| 9 | +import org.junit.jupiter.params.provider.MethodSource; |
7 | 10 |
|
8 | 11 | import es.codeurjc.test.complex.Complex; |
9 | 12 |
|
10 | 13 | public class ComplexAbsTest { |
11 | 14 |
|
12 | | - @ParameterizedTest |
13 | | - @CsvSource({ |
14 | | - "0, 0, 0", |
15 | | - "1, 1, 1.41421", |
16 | | - "2, 2, 2.82843", |
17 | | - "5, 5, 7.07107", |
18 | | - "10, 10, 14.1421", |
19 | | - "10, 1, 10.0498", |
20 | | - "20, 2, 20.099" |
21 | | - }) |
22 | | - public void absoluteTest(double real, double imag, double abs) { |
23 | | - |
24 | | - Complex complex = new Complex(real, imag); |
25 | | - assertEquals(complex.abs(), abs, 0.001); |
| 15 | + @ParameterizedTest(name = "{index}: ({0}).abs() == {1}") |
| 16 | + @MethodSource("values") |
| 17 | + public void absoluteTest(Complex complex, double result) { |
| 18 | + assertEquals(complex.abs(), result, 0.001); |
26 | 19 | } |
27 | 20 |
|
| 21 | + public static Collection<Object[]> values() { |
| 22 | + Object[][] data = { |
| 23 | + { new Complex(0,0),0 }, |
| 24 | + { new Complex(1,1),1.41421}, |
| 25 | + { new Complex(2,2),2.82843}, |
| 26 | + { new Complex(5,5),7.07107}, |
| 27 | + { new Complex(10,10),14.1421}, |
| 28 | + { new Complex(10,1),10.0498}, |
| 29 | + { new Complex(20,2),20.099} |
| 30 | + }; |
| 31 | + |
| 32 | + return Arrays.asList(data); |
| 33 | + } |
28 | 34 | } |
0 commit comments