diff --git a/TP2/src/main/java/arraydoubleendedqueue/ArrayDoubleEndedQueue.java b/TP2/src/main/java/arraydoubleendedqueue/ArrayDoubleEndedQueue.java new file mode 100644 index 0000000000000000000000000000000000000000..51d0686ae6148e6715751ea818a060a3cb7f82ab --- /dev/null +++ b/TP2/src/main/java/arraydoubleendedqueue/ArrayDoubleEndedQueue.java @@ -0,0 +1,45 @@ +package arraydoubleendedqueue; + +import deque.DoubleEndedQueue; + +public class ArrayDoubleEndedQueue<E> implements DoubleEndedQueue { + @Override + public void addFirst(Object o) { + + } + + @Override + public void addLast(Object o) { + + } + + @Override + public Object removeFirst() { + return null; + } + + @Override + public Object removeLast() { + return null; + } + + @Override + public Object getFirst() { + return null; + } + + @Override + public Object getLast() { + return null; + } + + @Override + public int size() { + return 0; + } + + @Override + public boolean contains(Object o) { + return false; + } +} diff --git a/TP2/src/main/java/complex/Complex.java b/TP2/src/main/java/complex/Complex.java index b9d0f220fe2cc2bcd114dbab4a0af141ef1990d9..913bc8fd1190f51adcca48b0648c304480cd56a2 100644 --- a/TP2/src/main/java/complex/Complex.java +++ b/TP2/src/main/java/complex/Complex.java @@ -7,9 +7,6 @@ public class Complex { private static final float EPSILON = 0.000001F; - public Complex() { - } - public Complex(float a, float b) { this.realPart = a; this.imaginaryPart = b; @@ -41,8 +38,8 @@ public class Complex { } public Complex product(Complex c) { - return new Complex(); - //return new Complex(this.realPart * c.getRealPart() - this.imaginaryPart * c.getImaginaryPart(), this.realPart * c.getImaginaryPart() + this.imaginaryPart * c.getRealPart()); + //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 +55,6 @@ public class Complex { public static void infinite() { - //while (true); + while (true); } } diff --git a/TP2/src/test/java/arraydoubleendedqueue/ArrayDoubleEndedQueueTest.java b/TP2/src/test/java/arraydoubleendedqueue/ArrayDoubleEndedQueueTest.java new file mode 100644 index 0000000000000000000000000000000000000000..12a0b047a06e94638110e964540d2cefb57549cf --- /dev/null +++ b/TP2/src/test/java/arraydoubleendedqueue/ArrayDoubleEndedQueueTest.java @@ -0,0 +1,74 @@ +package arraydoubleendedqueue; +import org.junit.jupiter.api.*; + +import org.junit.jupiter.api.Test; + +import java.util.Deque; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ArrayDoubleEndedQueueTest { + static Deque<Integer> ArrayDoubleEndedQueue; + @BeforeAll + static void setUpBeforeClass() throws Exception { + System.out.println("Before all"); + } + + @AfterAll + static void tearDownAfterClass() throws Exception { + System.out.println("After all"); + } + + @BeforeEach + void setUp() throws Exception { + } + + @AfterEach + void tearDown() throws Exception { + System.out.println("After each"); + } + + @Test + void testAddFirst() { + ArrayDoubleEndedQueue.addFirst(1); + ArrayDoubleEndedQueue.addFirst(2); + ArrayDoubleEndedQueue.addFirst(3); + ArrayDoubleEndedQueue.addFirst(4); + assertThat(ArrayDoubleEndedQueue.getFirst()).isEqualTo(1); + } + + @Test + void testAddLast() { + ArrayDoubleEndedQueue.addLast(1); + ArrayDoubleEndedQueue.addLast(2); + ArrayDoubleEndedQueue.addLast(3); + ArrayDoubleEndedQueue.addLast(4); + assertThat(ArrayDoubleEndedQueue.getLast()).isEqualTo(4); + } + + @Test + void testRemoveFirst() { + + } + + @Test + void testRemoveLast() { + } + + @Test + void testGetFirst() { + } + + @Test + void testGetLast() { + } + + @Test + void testSize() { + } + + @Test + void testContains() { + } + +} \ No newline at end of file diff --git a/TP2/src/test/java/complex/ComplexTest.java b/TP2/src/test/java/complex/ComplexTest.java index febe61ed7460a2915060c20baa2c0e49290db39c..ccf16318d6d903b82b2ca99e5e47a957edc3bab5 100644 --- a/TP2/src/test/java/complex/ComplexTest.java +++ b/TP2/src/test/java/complex/ComplexTest.java @@ -2,6 +2,7 @@ package complex; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; +import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; import static org.junit.jupiter.api.Assertions.fail; import org.junit.jupiter.api.AfterAll; @@ -19,48 +20,48 @@ 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.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"); float expected = 2.0F; - Complex z = new Complex(1.0F, 2.0f); // à supprimer si on mutualise avec BeforeAll + //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)); @@ -71,7 +72,7 @@ class ComplexTest { void testGetterReal() { float expected = 1.0F; - Complex z = new Complex(1.0F, 2.0f); // à supprimer si on mutualise avec BeforeAll + //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)); @@ -82,7 +83,7 @@ class ComplexTest { void testSetterImaginary() { float expected = 3.0F; - Complex z = new Complex(); // à supprimer si on mutualise avec BeforeAll + //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)); @@ -94,7 +95,7 @@ class ComplexTest { void testSetterReal() { float expected = 3.0F; - Complex z = new Complex(); // à supprimer si on mutualise avec BeforeAll + //Complex z = new Complex(); // à supprimer si on mutualise avec BeforeAll z.setRealPart(expected); assertThat(z.getRealPart()).as("problem on setter real") @@ -103,25 +104,34 @@ 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") + //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(); + Complex complexx = new Complex(0.0000000001F, 0.0F); + assertThat(complexx.isZero()).as("problem with isZero on Zero Complex number") + .isTrue(); + Complex complexxx = new Complex(0.0F, 0.0000000001F); + assertThat(complexxx.isZero()).as("problem with isZero on Zero Complex number") .isTrue(); - /*assertThat(!z.isZero()).as("problem with isZero on Zero Complex number") // à décommenter si on mutualise avec BeforeAll - .isTrue();*/ + Complex zeroo = new Complex(0.0F, 0.0F); // à décommenter si on mutualise avec BeforeAll + assertThat(zeroo.isZero()).as("problem with isZero on Zero Complex number") // à décommenter si on mutualise avec BeforeAll + .isTrue(); + //assertThat(zeroo.isZero()).as("problem with isZero on Zero Complex number").isTrue(); // à décommenter 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 + //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 + //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; @@ -132,8 +142,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 + //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); @@ -145,8 +155,8 @@ class ComplexTest { @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 + // 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; @@ -167,32 +177,30 @@ class ComplexTest { /** * A décommenter si on mutualise avec BeforeAll */ - /*Complex z3 = z1.product(z2); + 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 + + //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 } //@Disabled - @Test + /*@Test final void testTimeoutInfinite() { - Complex.infinite(); - fail("NYI"); - // assertTimeoutPreemptively(java.time.Duration.ofMillis(100), Complex::infinite); - } + 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(); @@ -221,5 +229,10 @@ class ComplexTest { } } - */ + @Test + void testToString(){ + assertThat(z.toString()).isEqualTo("1.0+i2.0");// Couvre les instructions de la méthode toString + } + + }