Skip to content
Snippets Groups Projects
Commit 208e7955 authored by Alexandre's avatar Alexandre
Browse files

ajout des fichiers de qualité dev

parent 8c67f944
No related branches found
No related tags found
No related merge requests found
Showing
with 762 additions and 0 deletions
File added
File added
import controlepkg2.sspkg.C;
import controlepkg1.A;
import controlepkg2.B;
import controlpkg.D;
class Main{
A triste = new A("triste");
B chapeau = new B();
C pointu = new C("pointu", 42);
D grand = new A("grand");
}
package controlepkg1;
public class A {
private String aLabel;
public A(String aLabel) {
this.aLabel = aLabel;
}
@Override
public String toString() {
return "A [aLabel=" + aLabel + "]";
}
}
package controlepkg2;
public class B {
private int aNumber = 42;
@Override
public String toString() {
return "B [aNumber=" + aNumber + "]";
}
}
package controlepkg2.sspkg;
public class C {
private String aLabel;
private int aNumber;
public C(String aLabel, int aNumber) {
this.aLabel = aLabel;
this.aNumber = aNumber;
}
public String getALabel() {return aLabel;}
public void setALabel(String aLabel) {this.aLabel = aLabel;}
public int getANumber() {return aNumber;}
public void setANumber(int aNumber) {this.aNumber = aNumber;}
@Override
public String toString() {
return "C [aLabel=" + aLabel + ", aNumber=" + aNumber + "]";
}
}
File added
package fifth;
import fourth.A;
class B {
public static void main(String[] args) {
System.out.println("class B -- main()");
A a = new A();
System.out.println(a + " again");
}
}
\ No newline at end of file
class A{
String label = "42";
A(){
;
}
A(String label){
this.label = label;
}
public String toString(){
return this.label;
}
public static void main(String[] args){
A a1 = new A();
A a2 = new A("a choisir");
System.out.println(a1);
System.out.println(a2);
}
}
\ No newline at end of file
package fourth;
public class A{
String label = "42";
public A(){
;
}
public A(String label){
this.label = label;
}
public String toString(){
return this.label;
}
// javac second/B.java -d ../bin -cp ../cp
}
\ No newline at end of file
class A{
String label = "42";
A(){
;
}
A(String label){
this.label = label;
}
public String toString(){
return this.label;
}
// javac second/B.java -d ../bin -cp ../cp
}
\ No newline at end of file
class B {
public static void main(String[] args) {
System.out.println("class B -- main()");
A a = new A();
System.out.println(a + " again");
}
}
\ No newline at end of file
package third;
public class A {
public static void main(String[] args) {
System.out.println("Pkg third - Class A - main program"); // java -cp bin third/A.java
}
}
\ No newline at end of file
This diff is collapsed.
package tp02;
/**
* @author Alexandre
* @version 0.01
* @since java21
*/
public class WarriorCard {
private String name;
private int strength = 0;
private int agility = 0;
/**
* @param name
* @param strength
* @param agility
*/
WarriorCard(String name, int strength, int agility){
this.name = name;
this.strength = strength;
this.agility = agility;
}
/**
* @param obj Objet qui est vérifié
* @return true si égale
* Vérifie si l'objet est égale
*/
public boolean equals(Object obj) {
if(this == obj){
return true;
}
if(obj == null){
return false;
}
if(this.getClass() != obj.getClass()){
return false;
}
WarriorCard other = (WarriorCard) obj;
if (this.name == null) {
if (other.name != null){
return false;
}
} else if (!this.name.equals(other.name)){
return false;
}
return true;
}
/**
* @param other une autre carte
* @return différence de strength
*/
public int compareStrength(WarriorCard other){
return this.strength - other.strength;
}
public int compareAgility(WarriorCard other){
return this.agility - other.agility;
}
public String toString(){
return this.name + "[S=" + this.strength + ",A=" + this.agility + "]";
}
}
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);
}
}
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));
}
}
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment