diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..7a9e042ad0e8b53c0a7774e384e238f70761c94a --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bin/ +.vscode/ +doc/ +**/*.class diff --git a/lib/AgendaTest.java b/lib/AgendaTest.java new file mode 100755 index 0000000000000000000000000000000000000000..e23d4ccc57b175bab70b40d94c42251e61b9133d --- /dev/null +++ b/lib/AgendaTest.java @@ -0,0 +1,56 @@ +package tpQU.tp02; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.time.LocalDate; +import java.util.ArrayList; + +public class AgendaTest { + public Event evt1; + public Event evt2; + public Event evt3; + public Event evt4; + public Agenda ag = new Agenda(); + public Agenda ag2 = new Agenda(); + + @BeforeEach + public void avantTest() { + ag.clear(); + LocalDate d1 = LocalDate.of(2018, 1, 5); + LocalDate d2 = LocalDate.of(2018, 2, 10); + LocalDate d3 = LocalDate.of(2018, 3, 15); + LocalDate d4 = LocalDate.of(2018, 4, 20); + evt1 = new Event("evt1", null, d1, d2); + evt2 = new Event("evt2", null, d2, d3); + evt3 = new Event("evt3", null, d3, d4); + evt4 = new Event("evt4", null, d2, d4); + } + + @Test + public void testConflicting() { + assertTrue(ag.conflicting(evt1)); + ag.addEvent(evt1); + assertTrue(ag.conflicting(evt3)); + ag.addEvent(evt3); + assertFalse(ag.conflicting(evt4)); + } + @Test + public void testRemoveOverlapping() { + ag.addEvent(evt1); + ArrayList<Event> tmp = new ArrayList<Event>(); + ag.removeOverlapping(evt1); + assertEquals(ag.events, tmp); + ag.addEvent(evt1);ag.addEvent(evt2);tmp.add(evt1); tmp.add(evt2); + ag.removeOverlapping(evt1); + ag.addEvent(evt3); tmp.clear(); + ag.removeOverlapping(evt4); + assertEquals(ag.events,tmp); + ag.addEvent(evt1);ag.addEvent(evt2);ag.addEvent(evt3); tmp.clear(); tmp.add(evt1); + ag.removeOverlapping(evt4); + assertEquals(ag.events,tmp); + } +} diff --git a/lib/EventTest.java b/lib/EventTest.java new file mode 100644 index 0000000000000000000000000000000000000000..a4b7221e7e998ee24242a3d107f9e565d07d10fc --- /dev/null +++ b/lib/EventTest.java @@ -0,0 +1,96 @@ +package tpQU.tp02; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.time.LocalDate; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import tpOO.tp03.Task; + +public class EventTest { + public Event evt1; + public Event evt2; + public Event evt3; + public Event evt4; + public Event evt5; + public Event evt6; + public Task t1; + public Task t2; + + @BeforeEach + public void avantTest() { + LocalDate d1 = LocalDate.of(2022, 1, 5); + LocalDate d2 = LocalDate.of(2022, 2, 10); + LocalDate d3 = LocalDate.of(2022, 3, 15); + LocalDate d4 = LocalDate.of(2022, 4, 20); + String place1 = "nowhere"; + String place2 = "everywhere"; + evt1 = new Event("evt1", place1, d1, d2); + evt2 = new Event("evt2", place1, d2, d3); + evt3 = new Event("evt3", place1, d3, d4); + evt4 = new Event("evt4", place1, d2, d4); + evt5 = new Event("evt5", place2, d1, d2); + evt6 = new Event("evt1", place1, d1, d2); + t1 = new Task("task1", 2); + t2 = new Task("task2", 1); + } + + @Test + void testToString() { + assertEquals("evt1 - nowhere: \t 2022-01-05 -> 2022-02-10", evt1.toString()); + assertEquals("evt2 - nowhere: \t 2022-02-10 -> 2022-03-15", evt2.toString()); + assertEquals("evt3 - nowhere: \t 2022-03-15 -> 2022-04-20", evt3.toString()); + assertEquals("evt4 - nowhere: \t 2022-02-10 -> 2022-04-20", evt4.toString()); + assertEquals("evt5 - everywhere: \t 2022-01-05 -> 2022-02-10", evt5.toString()); + } + + @Test + void testAddTask() { + assertEquals(0, evt1.getNbTasks()); + assertNull(evt1.getChores()[0]); + evt1.addTask(t1); + assertEquals(1, evt1.getNbTasks()); + assertEquals(t1, evt1.getChores()[0]); + evt1.addTask(t2); + assertEquals(2, evt1.getNbTasks()); + assertEquals(t2, evt1.getChores()[1]); + evt1.addTask(t1); + assertEquals(3, evt1.getNbTasks()); + assertEquals(t1, evt1.getChores()[0]); + assertEquals(t1, evt1.getChores()[2]); + } + + @Test + void testEquals() { + assertTrue(evt1.equals(evt1)); + assertFalse(evt1.equals(evt2)); + assertFalse(evt1.equals(evt3)); + assertFalse(evt1.equals(evt4)); + assertFalse(evt1.equals(evt5)); + assertTrue(evt1.equals(evt6)); + // + assertTrue(evt2.equals(evt2)); + assertFalse(evt2.equals(evt3)); + assertFalse(evt2.equals(evt4)); + assertFalse(evt2.equals(evt5)); + assertFalse(evt2.equals(evt6)); + } + + @Test + void testOverlap() { + assertTrue(evt1.overlap(evt1)); + assertFalse(evt1.overlap(evt2)); + assertFalse(evt1.overlap(evt3)); + assertFalse(evt1.overlap(evt4)); + assertTrue(evt1.overlap(evt5)); + assertTrue(evt1.overlap(evt6)); + assertFalse(evt2.overlap(evt3)); + assertTrue(evt2.overlap(evt4)); + assertTrue(evt3.overlap(evt4)); + } +} diff --git a/lib/junit-platform-console-standalone-1.10.2.jar b/lib/junit-platform-console-standalone-1.10.2.jar new file mode 100644 index 0000000000000000000000000000000000000000..7ca10e60183a168b228fd60a233281dd697b1cea Binary files /dev/null and b/lib/junit-platform-console-standalone-1.10.2.jar differ diff --git a/lib/res02-tpQU.jar b/lib/res02-tpQU.jar new file mode 100644 index 0000000000000000000000000000000000000000..3b18a48ebc9aeff4f8db5af89661078dfc1541ab Binary files /dev/null and b/lib/res02-tpQU.jar differ diff --git a/compil_src/Main.java b/src/tp01/Main.java similarity index 100% rename from compil_src/Main.java rename to src/tp01/Main.java diff --git a/compil_src/controlepkg1/A.java b/src/tp01/controlepkg1/A.java similarity index 100% rename from compil_src/controlepkg1/A.java rename to src/tp01/controlepkg1/A.java diff --git a/compil_src/controlepkg2/B.java b/src/tp01/controlepkg2/B.java similarity index 100% rename from compil_src/controlepkg2/B.java rename to src/tp01/controlepkg2/B.java diff --git a/compil_src/controlepkg2/sspkg/C.java b/src/tp01/controlepkg2/sspkg/C.java similarity index 100% rename from compil_src/controlepkg2/sspkg/C.java rename to src/tp01/controlepkg2/sspkg/C.java diff --git a/compil_src/fifth/B.java b/src/tp01/fifth/B.java similarity index 100% rename from compil_src/fifth/B.java rename to src/tp01/fifth/B.java diff --git a/compil_src/first/A.java b/src/tp01/first/A.java similarity index 100% rename from compil_src/first/A.java rename to src/tp01/first/A.java diff --git a/compil_src/fourth/A.java b/src/tp01/fourth/A.java similarity index 100% rename from compil_src/fourth/A.java rename to src/tp01/fourth/A.java diff --git a/compil_src/second/A.java b/src/tp01/second/A.java similarity index 100% rename from compil_src/second/A.java rename to src/tp01/second/A.java diff --git a/compil_src/second/B.java b/src/tp01/second/B.java similarity index 100% rename from compil_src/second/B.java rename to src/tp01/second/B.java diff --git a/compil_src/third/A.java b/src/tp01/third/A.java similarity index 100% rename from compil_src/third/A.java rename to src/tp01/third/A.java diff --git a/src/tpQU/WarriorCard.java b/src/tpQU/WarriorCard.java new file mode 100644 index 0000000000000000000000000000000000000000..ec96a051ce5e7d1cb32522634186fcaf3fdbaa02 --- /dev/null +++ b/src/tpQU/WarriorCard.java @@ -0,0 +1,73 @@ +package tp02; + +/** + * + * @author Hugo DEBUYSER + */ + +public class WarriorCard { + + /** + *Attributes + */ + private String name; + private int strength; + private int agility; + + /** + *Constructor + */ + public WarriorCard(String name, int strength, int agility){ + this.name = name; + this.strength = strength; + this.agility = agility; + } + + /* + methods + */ + + /** + * Comparer le noms de 2 Cartes + * @param other Prend une autre carte + */ + public boolean equals(WarriorCard other){ + return other.name.equals(this.name); + } + + /** + *Comparer la Strength de 2 Cartes + */ + + public int compareStrength(WarriorCard other){ + if(other.strength == this.strength){ + return 0; + } + if(other.strength>this.strength){ + return -1; + } + return 1; + } + + /** + Comparer la Agility de 2 Cartes + */ + + public int compareAgility(WarriorCard other){ + if(other.agility == this.agility){ + return 0; + } + if(other.agility>this.agility){ + return -1; + } + return 1; + } + + /** + *Renvoie la carte sous un certain format + */ + public String toString(){ + return this.name + "[S=" + this.strength + ",A=" + this.agility + "]"; + } + +} \ No newline at end of file diff --git a/test/tpQU/WarriorCardTest.java b/test/tpQU/WarriorCardTest.java new file mode 100755 index 0000000000000000000000000000000000000000..4a090856ef0a964c84c8bd8c82cf26160c524376 --- /dev/null +++ b/test/tpQU/WarriorCardTest.java @@ -0,0 +1,47 @@ +package tp02; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class WarriorCardTest { + WarriorCard c1; + WarriorCard c2; + WarriorCard c3; + WarriorCard c4; + + @BeforeAll + public static void beforeAllTests() {System.out.println("Start test series");} + @AfterAll + public static void afterAllTests() {System.out.println("End test series");} + @BeforeEach + public void beforeATest() { + c1 = new WarriorCard("w1", 10, 10); + c2 = new WarriorCard("w1", 5, 5); + c3 = new WarriorCard("w2", 20, 20); + c4 = c1; + } + @AfterEach + public void afterATest() {System.out.println("--------- end of a test---------");} + @Test + public void testEquals() { + System.out.println("testEquals"); + assertTrue(c1.equals(c1)); + assertTrue(c1.equals(c2)); + assertFalse(c1.equals(c3)); + assertTrue(c1.equals(c4)); + } + @Test + public void testToString() { + System.out.println("testToString"); + assertEquals("w1[S=10,A=10]", c1.toString()); + assertEquals("w2[S=20,A=20]", c3.toString()); + } + +} \ No newline at end of file