File tree Expand file tree Collapse file tree
tema1_2_ejer7/src/test/java/es/codeurjc/test/complex Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package es .codeurjc .test .complex ;
22
3- import static org .junit .jupiter .api .Assertions .assertEquals ;
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+ import static org .assertj .core .api .Assertions .offset ;
45
56import java .util .Arrays ;
67import java .util .Collection ;
@@ -13,7 +14,7 @@ public class ComplexAbsTest {
1314 @ ParameterizedTest (name = "{index}: ({0}).abs() == {1}" )
1415 @ MethodSource ("values" )
1516 public void absoluteTest (Complex complex , double result ) {
16- assertEquals (complex .abs (), result , 0.001 );
17+ assertThat (complex .abs ()). isCloseTo ( result , offset ( 0.001 ) );
1718 }
1819
1920 public static Collection <Object []> values () {
Original file line number Diff line number Diff line change 11package es .codeurjc .test .complex ;
22
33import static org .assertj .core .api .Assertions .assertThat ;
4+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
45
56import org .junit .jupiter .api .BeforeEach ;
67import org .junit .jupiter .api .Test ;
@@ -31,4 +32,14 @@ public void GivenComplex1_1_whenAddToZero_thenComplex1_1IsObtained() {
3132
3233 assertThat ((new Complex (1 , 1 )).add (zero )).isEqualTo (new Complex (1 , 1 ));
3334 }
35+
36+ @ Test
37+ public void GivenComplex0_0_whenReciprocal_thenExceptionIsThrown () {
38+
39+ Complex zero = new Complex (0 ,0 );
40+
41+ assertThatThrownBy (() -> zero .reciprocal ())
42+ .isInstanceOf (ArithmeticException .class )
43+ .hasMessage ("division by zero" );
44+ }
3445}
You can’t perform that action at this time.
0 commit comments