Skip to content
Snippets Groups Projects
Commit 772f82ee authored by MEDEDJI Setondji's avatar MEDEDJI Setondji :speech_balloon:
Browse files

Update

parent d3693dd9
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="18" project-jdk-type="JavaSDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/m-1-info-fsi-tp-template-mededji.iml" filepath="$PROJECT_DIR$/.idea/m-1-info-fsi-tp-template-mededji.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
...@@ -41,8 +41,8 @@ public class Complex { ...@@ -41,8 +41,8 @@ public class Complex {
} }
public Complex product(Complex c) { public Complex product(Complex c) {
// TODO: change code
return new Complex(); return new Complex();
//return new Complex(this.realPart * c.getRealPart() - this.imaginaryPart * c.getImaginaryPart(), this.realPart * c.getImaginaryPart() + this.imaginaryPart * c.getRealPart());
} }
public Complex inverse() throws IllegalArgumentException { public Complex inverse() throws IllegalArgumentException {
...@@ -58,6 +58,6 @@ public class Complex { ...@@ -58,6 +58,6 @@ public class Complex {
public static void infinite() public static void infinite()
{ {
// TODO: add code //while (true);
} }
} }
package partial_coverage; package partial_coverage;
public class PartialCoverage { public class PartialCoverage {
public int returnZeroOrOne(int x, int y) { public static int returnZeroOrOne(int x, int y) {
int res = 0; int res = 0;
int z = 2; int z = 2;
x = z * z - z - 1; x = z * z - z - 1;
......
...@@ -19,53 +19,59 @@ import java.sql.SQLOutput; ...@@ -19,53 +19,59 @@ import java.sql.SQLOutput;
*/ */
class ComplexTest { class ComplexTest {
/*
private Complex z; private Complex z;
private Complex z1; private Complex z1;
private Complex z2; private Complex z2;
*/
private static final float EPSILON = 0.000001F; private static final float EPSILON = 0.000001F;
@BeforeAll @BeforeAll
static void setUpBeforeClass() throws Exception { static void setUpBeforeClass() throws Exception {
// TODO: add message // TODO: add message
System.out.println("La méthode setUpBeforeClass est bien exécutée avant les tests "); //System.out.println("La méthode setUpBeforeClass est bien exécutée avant les tests ");
} }
@AfterAll @AfterAll
static void tearDownAfterClass() throws Exception { static void tearDownAfterClass() throws Exception {
// TODO: add message // TODO: add message
System.out.println("La méthode tearDownAfterClass est bien exécutée après les tests"); //System.out.println("La méthode tearDownAfterClass est bien exécutée après les tests");
} }
@BeforeEach @BeforeEach
void setUp() throws Exception { void setUp() throws Exception {
// TODO: add message // TODO: add message
System.out.println("setUp effectué avant chaque test"); System.out.println("setUp effectué avant chaque test");
this.z = new Complex(1.0F, 2.0f); /*
this.z = new Complex(1.0F, 2.0F);
this.z1 = new Complex(1.0F, 2.0F); this.z1 = new Complex(1.0F, 2.0F);
this.z2 = new Complex(3.0F, 4.0F); this.z2 = new Complex(3.0F, 4.0F);
*/
} }
@AfterEach @AfterEach
void tearDown() throws Exception { void tearDown() throws Exception {
// TODO: add messageDisabled // TODO: add messageDisabled
System.out.println("tearDown effectué apres chaque test"); //System.out.println("tearDown effectué apres chaque test");
} }
@Test @Test
void testGetterImaginary() { void testGetterImaginary() {
System.out.println("1er test"); //System.out.println("1er test");
float expected = 2.0F; float expected = 2.0F;
Complex z = new Complex(1.0F, 2.0f); // à supprimer si on mutualise avec BeforeAll
assertThat(z.getImaginaryPart()).as("problem on getter imaginary") assertThat(z.getImaginaryPart()).as("problem on getter imaginary")
.isCloseTo(expected, within(EPSILON)); .isCloseTo(expected, within(EPSILON));
} }
@Test @Test
void testGetterReal() { void testGetterReal() {
float expected = 1.0F; float expected = 1.0F;
Complex z = new Complex(1.0F, 2.0f); // à supprimer si on mutualise avec BeforeAll
assertThat(z.getRealPart()).as("problem on getter real") assertThat(z.getRealPart()).as("problem on getter real")
.isCloseTo(expected, within(EPSILON)); .isCloseTo(expected, within(EPSILON));
...@@ -76,6 +82,7 @@ class ComplexTest { ...@@ -76,6 +82,7 @@ class ComplexTest {
void testSetterImaginary() { void testSetterImaginary() {
float expected = 3.0F; float expected = 3.0F;
Complex z = new Complex(); // à supprimer si on mutualise avec BeforeAll
z.setImaginaryPart(expected); z.setImaginaryPart(expected);
assertThat(z.getImaginaryPart()).as("problem on setter imaginary") assertThat(z.getImaginaryPart()).as("problem on setter imaginary")
.isCloseTo(expected, within(EPSILON)); .isCloseTo(expected, within(EPSILON));
...@@ -87,6 +94,8 @@ class ComplexTest { ...@@ -87,6 +94,8 @@ class ComplexTest {
void testSetterReal() { void testSetterReal() {
float expected = 3.0F; float expected = 3.0F;
Complex z = new Complex(); // à supprimer si on mutualise avec BeforeAll
z.setRealPart(expected); z.setRealPart(expected);
assertThat(z.getRealPart()).as("problem on setter real") assertThat(z.getRealPart()).as("problem on setter real")
.isCloseTo(expected, within(EPSILON)); .isCloseTo(expected, within(EPSILON));
...@@ -94,18 +103,22 @@ class ComplexTest { ...@@ -94,18 +103,22 @@ class ComplexTest {
@Test @Test
void testZeroTrue() { void testZeroTrue() {
Complex z = new Complex(0.0F, 0.0F); // à supprimer si on mutualise avec BeforeAll
assertThat(!z.isZero()).as("problem with isZero on Zero Complex number") assertThat(!z.isZero()).as("problem with isZero on Zero Complex number")
.isTrue(); .isTrue();
} }
@Test @Test
void testZeroFalse() { void testZeroFalse() {
Complex z = new Complex(1.0F, 1.0F); // à supprimer si on mutualise avec BeforeAll
assertThat(z.isZero()).as("problem with isZero on non Zero Complex number") assertThat(z.isZero()).as("problem with isZero on non Zero Complex number")
.isFalse(); .isFalse();
} }
@Test @Test
void testSumReal() { void testSumReal() {
Complex z1 = new Complex(1.0F, 2.0F); // à supprimer si on mutualise avec BeforeAll
Complex z2 = new Complex(3.0F, 4.0F); // à supprimer si on mutualise avec BeforeAll
float expected = 1.0F + 3.0F; float expected = 1.0F + 3.0F;
...@@ -116,6 +129,8 @@ class ComplexTest { ...@@ -116,6 +129,8 @@ class ComplexTest {
@Test @Test
void testSumImaginary() { void testSumImaginary() {
Complex z1 = new Complex(1.0F, 2.0F); // à supprimer si on mutualise avec BeforeAll
Complex z2 = new Complex(3.0F, 4.0F); // à supprimer si on mutualise avec BeforeAll
float expected = 2.0F + 4.0F; float expected = 2.0F + 4.0F;
Complex z = z1.sum(z2); Complex z = z1.sum(z2);
...@@ -124,9 +139,11 @@ class ComplexTest { ...@@ -124,9 +139,11 @@ class ComplexTest {
System.out.println("Dernier test"); System.out.println("Dernier test");
} }
@Disabled
@Test @Test
void testProductReal() { void testProductReal() {
Complex z1 = new Complex(1.0F, 2.0F); // à supprimer si on mutualise avec BeforeAll
Complex z2 = new Complex(3.0F, 4.0F); // à supprimer si on mutualise avec BeforeAll
float expected = 1.0F * 3.0F - 2.0F * 4.0F; float expected = 1.0F * 3.0F - 2.0F * 4.0F;
...@@ -135,16 +152,28 @@ class ComplexTest { ...@@ -135,16 +152,28 @@ class ComplexTest {
.isCloseTo(expected, within(EPSILON)); .isCloseTo(expected, within(EPSILON));
} }
@Disabled
@Test @Test
void testProductImaginary() { void testProductImaginary() {
Complex z1 = new Complex(1.0F, 2.0F); // à supprimer si on mutualise avec BeforeAll
Complex z2 = new Complex(3.0F, 4.0F); // à supprimer si on mutualise avec BeforeAll
float expected = 1.0F * 4.0F + 2.0F * 3.0F; float expected = 1.0F * 4.0F + 2.0F * 3.0F;
z1.product(z2); /**
assertThat(z.getImaginaryPart()).as("problem with imaginary part of Product") * A décommenter si on mutualise avec BeforeAll
*/
/*Complex z3 = z1.product(z2);
assertThat(z3.getImaginaryPart()).as("problem with imaginary part of Product")
.isCloseTo(expected, within(EPSILON)); .isCloseTo(expected, within(EPSILON));
*/
Complex z = z1.product(z2); // à supprimer si on mutualise avec BeforeAll
assertThat(z.getImaginaryPart()).as("problem with imaginary part of Product") // à supprimer si on mutualise avec BeforeAll
.isCloseTo(expected, within(EPSILON)); // à supprimer si on mutualise avec BeforeAll
} }
...@@ -153,17 +182,41 @@ class ComplexTest { ...@@ -153,17 +182,41 @@ class ComplexTest {
final void testTimeoutInfinite() { final void testTimeoutInfinite() {
Complex.infinite(); Complex.infinite();
fail("NYI"); fail("NYI");
// assertTimeoutPreemptively(java.time.Duration.ofMillis(100), Complex::infinite);
} }
/**
* A décommenter si on mutualise avec BeforeAll et pour tester la méthode inverse
*/
/*
@Test @Test
void testIsRealPartOfInverseIsCorrect(){ void testIsRealPartOfInverseIsCorrect(){
Complex inverse = z.inverse();
float realExpected = 1.0F / (1.0F * 1.0F + 2.0F * 2.0F);
assertThat(inverse.getRealPart()).as("problem with real part of inverse")
.isCloseTo(realExpected, within(EPSILON));
} }
@Test @Test
void testIsImaginaryPartOfInverseIsCorrect(){ void testIsImaginaryPartOfInverseIsCorrect(){
Complex inverse = z.inverse();
float imaginaryExpected = -2.0F / (1.0F * 1.0F + 2.0F * 2.0F);
assertThat(inverse.getImaginaryPart()).as("problem with imaginary part of inverse")
.isCloseTo(imaginaryExpected, within(EPSILON));
} }
@Test
void testInverseExeception(){
try{
Complex zero = new Complex(0.0F, 0.0F);
zero.inverse();
fail("Should throw an exception");
}catch (IllegalArgumentException e){
assertThat(e).hasMessage(null);
}
}
*/
} }
...@@ -20,6 +20,7 @@ public class PalindromeTest { ...@@ -20,6 +20,7 @@ public class PalindromeTest {
void testEvenLengthTrue() { void testEvenLengthTrue() {
assertThat(Palindrome.isPalindrome("abba")).isTrue(); assertThat(Palindrome.isPalindrome("abba")).isTrue();
} }
@Test @Test
void testOddLengthTrue() { void testOddLengthTrue() {
assertThat(Palindrome.isPalindrome("aba")).isTrue(); assertThat(Palindrome.isPalindrome("aba")).isTrue();
......
package partialcoverage;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static partial_coverage.PartialCoverage.returnZeroOrOne;
public class PartialCoverageTest {
@Test
void testXEgalZero(){
assertThat(returnZeroOrOne(0, 2)).isEqualTo(0);
assertThat(returnZeroOrOne(7, 5)).isEqualTo(0);
assertThat(returnZeroOrOne(1, 2)).isEqualTo(0);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment