"depot M213"

This commit is contained in:
JunkJumper
2020-05-03 14:24:13 +02:00
parent 1408744dbb
commit e5983242c6
136 changed files with 161184 additions and 0 deletions

BIN
TD2/TD2.pdf Executable file

Binary file not shown.

View File

@ -0,0 +1,71 @@
package ensembleEntierBorne;
public class EnsembleEntierBorne {
private final int MAXIMUM;
private boolean tab[];
public EnsembleEntierBorne(int max)
{
MAXIMUM = max;
tab = new boolean[max+1];
}
public void add(int elt)
{
this.tab[elt] = true;
}
public void remove(int elt)
{
this.tab[elt] = false;
}
public boolean doesContains(int elt)
{
if (this.tab[elt] == true) {
return true;
} else {
return false;
}
}
/*EnsembleEntierBorne intersect(EnsembleEntierBorne ens)
{
}*/
public int getMAXIMUM() {
return MAXIMUM;
}
public boolean[] getTab() {
return tab;
}
public void setTab(boolean tab[]) {
this.tab = tab;
}
@Override
public String toString() {
String retour = "{";
for (int i = 0; i < this.MAXIMUM; i++)
{
if (this.tab[i] == true)
{
retour += i+", ";
}
}
retour += "}";
return retour;
}
}

View File

@ -0,0 +1,46 @@
package ensembleEntierBorne;
public class TestEnsembleEntierBorne {
public static void main(String[] args) {
EnsembleEntierBorne e1 = new EnsembleEntierBorne(20);
EnsembleEntierBorne e2 = new EnsembleEntierBorne(11);
EnsembleEntierBorne e3 = new EnsembleEntierBorne(5);
e1.add(3);
e1.add(5);
e1.add(9);
e1.add(14);
e1.add(18);
e1.add(18);
System.out.println(e1.toString());
e1.remove(3);
e1.remove(18);
System.out.println(e1.toString());
System.out.println();
System.out.println();
System.out.println();
e2.add(1);
e2.add(2);
e2.add(3);
e2.add(4);
e2.add(5);
e2.add(6);
e2.add(7);
e2.add(8);
e3.add(5);
e3.add(0);
e3.add(3);
System.out.println("e1 = " + e1.toString());
System.out.println("e2 = " + e2.toString());
System.out.println("e3 = " + e3.toString());
}
}

93
TD2/src/test/TestTriplet.java Executable file
View File

@ -0,0 +1,93 @@
package test;
import tripletEntier.TripletEntier;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class TestTriplet {
private TripletEntier t1 = new TripletEntier(4, 3, 3);
private TripletEntier t2 = new TripletEntier(4, 4, 2);
private TripletEntier t3 = new TripletEntier(4, 5, 1);
private TripletEntier t4 = new TripletEntier(3, 5, 2);
private TripletEntier t5 = new TripletEntier(1, 2, 3);
@BeforeEach
public void avantTest() {
System.out.println("----------Debut Test-------------");
}
@AfterEach
public void apresTest() {
System.out.println("-----------Fin Test-------------");
}
@Test
void testSomme() {
assertEquals(10, t1.somme());
assertEquals(10, t2.somme());
assertEquals(10, t3.somme());
assertEquals(10, t4.somme());
assertEquals(6, t5.somme());
System.out.println("Test Somme Passe correctement !");
}
@Test
void testMoyenne() {
assertEquals(2., t5.moyenne(), 0.00000001);
assertEquals(3.33333333, t4.moyenne(), 0.00000001);
assertEquals(3.33333333, t3.moyenne(), 0.00000001);
assertEquals(3.33333333, t2.moyenne(), 0.00000001);
assertEquals(3.33333333, t1.moyenne(), 0.00000001);
System.out.println("Test des sommes Passe correctement !");
}
@Test
void testConcatenantion() {
assertEquals("433", t1.concatenation());
assertEquals("442", t2.concatenation());
assertEquals("451", t3.concatenation());
assertEquals("352", t4.concatenation());
assertEquals("123", t5.concatenation());
System.out.println("Test des concatenations Passe correctement !");
}
@Test
void testToSting() {
assertEquals("[a=4, b=3, c=3]", t1.toString());
assertEquals("[a=4, b=4, c=2]", t2.toString());
assertEquals("[a=4, b=5, c=1]", t3.toString());
assertEquals("[a=3, b=5, c=2]", t4.toString());
assertEquals("[a=1, b=2, c=3]", t5.toString());
System.out.println("Test du toString Passe correctement !");
}
@Test
void testEquals() {
assertEquals(true, t1.equals(t1));
assertEquals(true, t2.equals(t2));
assertEquals(true, t3.equals(t3));
assertEquals(true, t4.equals(t4));
assertEquals(true, t5.equals(t5));
assertEquals(false, t1.equals(t2));
assertEquals(false, t2.equals(t3));
assertEquals(false, t3.equals(t1));
assertEquals(false, t4.equals(t5));
assertEquals(false, t5.equals(t1));
System.out.println("Test des equals Passe correctement !");
}
}

View File

@ -0,0 +1,41 @@
package tripletEntier;
public class TestTripletEntier
{
public static void main(String[] args)
{
TripletEntier t1 = new TripletEntier(2, 2, 3);
System.out.println("Somme "+t1+" = "+t1.somme());
System.out.println(t1.somme() == 7);
System.out.println();
TripletEntier t2 = new TripletEntier(1, 2, 3);
System.out.println(t2);
/*String resConcat = t2.concatenation();
/*System.out.println(resConcat);
System.out.println(resConcat == "123");
System.out.println(resConcat.equals("123"));
System.out.println("Moyenne "+t2+" = "+t2.moyenne());
System.out.println();*/
System.out.println(new TripletEntier(1, 2, 4).moyenne());
System.out.println();
TripletEntier t3 = new TripletEntier(1, 2, 2);
System.out.println("Moyenne "+t3+" = "+t3.moyenne());
System.out.println(t3.moyenne() == (5.0/3.0));
System.out.println(t3.moyenne() == 1.666667);
System.out.println();
/*t1.ajoutElement(5, 2);
System.out.println(t1);
t1.ajoutElement(5, 5);
t1.ajout1erElement(10);
System.out.println(t1);*/
}
}

View File

@ -0,0 +1,87 @@
package tripletEntier;
public class TripletEntier
{
private int un;
private int deux;
private int trois;
public TripletEntier()
{
un = 0;
deux = 0;
trois = 0;
}
public TripletEntier(int a, int b, int c)
{
un = a;
deux = b;
trois = c;
}
//getter
public int getA() {
return un;
}
public int getB() {
return deux;
}
public int getC() {
return trois;
}
//setter
public void setA(int a) {
this.un = a;
}
public void setB(int b) {
this.deux = b;
}
public void setC(int c) {
this.trois = c;
}
/*
¸,ø¤º°`°º¤ø,¸¸,ø¤º°°º¤ø,¸¸,ø¤º°`°º¤ø,¸
Exercices demandés
¸,ø¤º°`°º¤ø,¸¸,ø¤º°°º¤ø,¸¸,ø¤º°`°º¤ø,¸
*/
public int somme()
{
int ret=this.un+this.deux+this.trois;
return ret;
}
public String concatenation()
{
return ""+this.un+this.deux+this.trois;
}
public double moyenne()
{
return ((double) somme() / 3);
}
@Override
public String toString()
{
return "[a=" + un + ", b=" + deux + ", c=" + trois + "]";
}
public boolean equals(Object o)
{
TripletEntier t = (TripletEntier) o;
return (this.un == t.un) && (this.deux == t.deux) && (this.trois == t.trois);
}
}