Skip to content

Commit 08fe4d5

Browse files
committed
Improve ejer3
1 parent 39a46e5 commit 08fe4d5

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package es.codeurjc.test.complex;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.util.stream.Stream;
6+
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.CsvSource;
9+
import org.junit.jupiter.params.provider.MethodSource;
10+
11+
import es.codeurjc.test.complex.Complex;
12+
13+
public class ComplexAbs2Test {
14+
15+
static class ComplexAndValue {
16+
17+
public Complex complex;
18+
public double value;
19+
20+
public ComplexAndValue(Complex complex, double value) {
21+
this.complex = complex;
22+
this.value = value;
23+
}
24+
}
25+
26+
@ParameterizedTest
27+
@MethodSource("values")
28+
public void absoluteTest(ComplexAndValue complexAndValue) {
29+
30+
Complex complex = complexAndValue.complex;
31+
double abs = complexAndValue.value;
32+
33+
assertEquals(complex.abs(), abs, 0.001);
34+
}
35+
36+
public static Stream<ComplexAndValue> values() {
37+
return Stream.of(
38+
new ComplexAndValue(new Complex(0, 0), 0),
39+
new ComplexAndValue(new Complex(1, 1), 1.41421),
40+
new ComplexAndValue(new Complex(2, 2), 2.82843),
41+
new ComplexAndValue(new Complex(5, 5), 7.07107),
42+
new ComplexAndValue(new Complex(10, 10), 14.1421),
43+
new ComplexAndValue(new Complex(10, 1), 10.0498),
44+
new ComplexAndValue(new Complex(20, 2), 20.099)
45+
);
46+
}
47+
48+
}

tema1_2_ejer3/src/test/java/es/codeurjc/test/complex/ComplexAbsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public class ComplexAbsTest {
1919
"10, 1, 10.0498",
2020
"20, 2, 20.099"
2121
})
22-
public void absoluteTest(double real, double imag, double result) {
22+
public void absoluteTest(double real, double imag, double abs) {
2323

2424
Complex complex = new Complex(real, imag);
25-
assertEquals(complex.abs(), result, 0.001);
25+
assertEquals(complex.abs(), abs, 0.001);
2626
}
2727

2828
}

0 commit comments

Comments
 (0)