From 772f82ee8c2930197aa6cedfdd198a6bd09e2bd8 Mon Sep 17 00:00:00 2001
From: Setondji <setondji.mededji@etu.univ-amu.fr>
Date: Wed, 10 Jan 2024 22:58:55 +0100
Subject: [PATCH] Update

---
 .idea/m-1-info-fsi-tp-template-mededji.iml    |  9 +++
 .idea/misc.xml                                |  4 +
 .idea/modules.xml                             |  8 ++
 .idea/vcs.xml                                 |  6 ++
 TP2/src/main/java/complex/Complex.java        |  4 +-
 .../partial_coverage/PartialCoverage.java     |  2 +-
 TP2/src/test/java/complex/ComplexTest.java    | 79 ++++++++++++++++---
 .../test/java/palindrome/PalindromeTest.java  |  1 +
 .../partialcoverage/PartialCoverageTest.java  | 15 ++++
 9 files changed, 112 insertions(+), 16 deletions(-)
 create mode 100644 .idea/m-1-info-fsi-tp-template-mededji.iml
 create mode 100644 .idea/misc.xml
 create mode 100644 .idea/modules.xml
 create mode 100644 .idea/vcs.xml
 create mode 100644 TP2/src/test/java/partialcoverage/PartialCoverageTest.java

diff --git a/.idea/m-1-info-fsi-tp-template-mededji.iml b/.idea/m-1-info-fsi-tp-template-mededji.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/.idea/m-1-info-fsi-tp-template-mededji.iml
@@ -0,0 +1,9 @@
+<?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
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..80dd871
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+<?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
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..37a3a5f
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+<?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
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+<?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
diff --git a/TP2/src/main/java/complex/Complex.java b/TP2/src/main/java/complex/Complex.java
index 39c9e97..b9d0f22 100644
--- a/TP2/src/main/java/complex/Complex.java
+++ b/TP2/src/main/java/complex/Complex.java
@@ -41,8 +41,8 @@ public class Complex {
     }
 
     public Complex product(Complex c) {
-        // TODO: change code
         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 {
@@ -58,6 +58,6 @@ public class Complex {
 
     public static void infinite()
     {
-        // TODO: add code
+        //while (true);
     }
 }
diff --git a/TP2/src/main/java/partial_coverage/PartialCoverage.java b/TP2/src/main/java/partial_coverage/PartialCoverage.java
index 050dee6..118bc76 100644
--- a/TP2/src/main/java/partial_coverage/PartialCoverage.java
+++ b/TP2/src/main/java/partial_coverage/PartialCoverage.java
@@ -1,7 +1,7 @@
 package partial_coverage;
 public class PartialCoverage {
 
-  public int returnZeroOrOne(int x, int y) {
+  public static int returnZeroOrOne(int x, int y) {
     int res = 0;
     int z = 2;
     x = z * z - z - 1;
diff --git a/TP2/src/test/java/complex/ComplexTest.java b/TP2/src/test/java/complex/ComplexTest.java
index 22aaecb..2b82ba6 100644
--- a/TP2/src/test/java/complex/ComplexTest.java
+++ b/TP2/src/test/java/complex/ComplexTest.java
@@ -19,53 +19,59 @@ import java.sql.SQLOutput;
  */
 
 class ComplexTest {
+  /*
   private Complex z;
   private Complex z1;
   private Complex z2;
+  */
   private static final float EPSILON = 0.000001F;
 
+
   @BeforeAll
   static void setUpBeforeClass() throws Exception {
     // 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
   static void tearDownAfterClass() throws Exception {
     // 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
   void setUp() throws Exception {
     // TODO: add message
     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.z2 = new Complex(3.0F, 4.0F);
+    */
   }
 
   @AfterEach
   void tearDown() throws Exception {
     // TODO: add messageDisabled
-    System.out.println("tearDown effectué apres chaque test");
+    //System.out.println("tearDown effectué apres chaque test");
   }
 
   @Test
   void testGetterImaginary() {
-    System.out.println("1er test");
+    //System.out.println("1er test");
     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")
             .isCloseTo(expected, within(EPSILON));
 
-
   }
 
   @Test
   void testGetterReal() {
 
     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")
             .isCloseTo(expected, within(EPSILON));
@@ -76,6 +82,7 @@ class ComplexTest {
   void testSetterImaginary() {
 
     float expected = 3.0F;
+    Complex z = new Complex(); // à supprimer si on mutualise avec BeforeAll
     z.setImaginaryPart(expected);
     assertThat(z.getImaginaryPart()).as("problem on setter imaginary")
             .isCloseTo(expected, within(EPSILON));
@@ -87,6 +94,8 @@ class ComplexTest {
   void testSetterReal() {
 
     float expected = 3.0F;
+    Complex z = new Complex(); // à supprimer si on mutualise avec BeforeAll
+
     z.setRealPart(expected);
     assertThat(z.getRealPart()).as("problem on setter real")
             .isCloseTo(expected, within(EPSILON));
@@ -94,18 +103,22 @@ class ComplexTest {
 
   @Test
   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")
             .isTrue();
   }
 
   @Test
   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")
             .isFalse();
   }
 
   @Test
   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;
 
@@ -116,6 +129,8 @@ class ComplexTest {
 
   @Test
   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;
     Complex z = z1.sum(z2);
@@ -124,9 +139,11 @@ class ComplexTest {
     System.out.println("Dernier test");
   }
 
-  @Disabled
+
   @Test
   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;
 
@@ -135,16 +152,28 @@ class ComplexTest {
             .isCloseTo(expected, within(EPSILON));
 
   }
-  @Disabled
+
   @Test
   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;
 
-    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));
 
+     */
+    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 {
   final void testTimeoutInfinite() {
     Complex.infinite();
     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
   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
   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);
+    }
+  }
+
+    */
 }
diff --git a/TP2/src/test/java/palindrome/PalindromeTest.java b/TP2/src/test/java/palindrome/PalindromeTest.java
index b239966..bfe860c 100644
--- a/TP2/src/test/java/palindrome/PalindromeTest.java
+++ b/TP2/src/test/java/palindrome/PalindromeTest.java
@@ -20,6 +20,7 @@ public class PalindromeTest {
   void testEvenLengthTrue() {
     assertThat(Palindrome.isPalindrome("abba")).isTrue();
   }
+
   @Test
   void testOddLengthTrue() {
     assertThat(Palindrome.isPalindrome("aba")).isTrue();
diff --git a/TP2/src/test/java/partialcoverage/PartialCoverageTest.java b/TP2/src/test/java/partialcoverage/PartialCoverageTest.java
new file mode 100644
index 0000000..51fb526
--- /dev/null
+++ b/TP2/src/test/java/partialcoverage/PartialCoverageTest.java
@@ -0,0 +1,15 @@
+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);
+
+    }
+}
-- 
GitLab