Skip to content
Snippets Groups Projects
Commit 6f1da651 authored by Baptiste Royer's avatar Baptiste Royer
Browse files

Update 29 files

- /src/td07/Animaux.java
- /src/td07/Banc.java
- /src/td07/Fish.java
- /src/td07/Pig.java
- /src/td07/Tigre.java
- /tp08/.vscode/settings.json
- /tp08/lib/hamcrest-core-1.3.jar
- /tp08/lib/junit-4.13.2.jar
- /tp08/lib/junit-platform-console-standalone-1.10.2.jar
- /tp08/res/BreedingGroundTest.java
- /tp08/bin/tp08/Food.class
- /tp08/bin/tp08/Furniture.class
- /tp08/bin/tp08/IProduct.class
- /tp08/bin/tp08/Shelf.class
- /tp08/bin/tp08/Shop.class
- /tp08/bin/tp08/ShopTest.class
- /tp08/bin/tp08/UseComparable.class
- /tp08/src/tp08/Food.java
- /tp08/src/tp08/Furniture.java
- /tp08/src/tp08/IProduct.java
- /tp08/src/tp08/Shelf.java
- /tp08/src/tp08/Shop.java
- /tp08/src/tp08/ShopTest.java
- /tp08/src/tp08/UseComparable.java
- /tp09/src/td07/Animaux.java
- /tp09/src/td07/Banc.java
- /tp09/src/td07/Fish.java
- /tp09/src/td07/Pig.java
- /tp09/src/td07/Tigre.java
parent 4641b4d7
Branches
No related tags found
No related merge requests found
Showing
with 0 additions and 367 deletions
package td07;
public interface Animaux {
public String shout();
public int foodAmount();
public boolean isPet();
}
\ No newline at end of file
package td07;
public class Banc {
}
\ No newline at end of file
package td07;
public class Fish implements Animaux{
private static final int FOOD = 1; //En UML, un final doit être écrit en majuscules.
private String name;
public Fish(String name) { //+Fish(String)
this.name = name;
}
public String shout() { //+shout() : String
return "Blob!";
}
public int foodAmount() {
return this.FOOD; //+foodAmount() : int
}
public boolean isPet() { //+isPet() : boolean
return true;
}
public String toString() { //+toString() : String
return "";
}
public int getFOOD() { //+getFOOD() : int
return this.mealSize;
}
public int getName() { //+getName() : String
return this.weight;
}
}
\ No newline at end of file
package td07;
public class Pig implements Animaux{
private static int mealSize; //En UML, static doit être souligné.
private int weight;
private String name;
public Pig(String name, int weight) { //+Pig(String, int)
this.name = name;
this.weight = weight;
}
public String shout() { //shout() : String
return "Grouik!";
}
public int foodAmount() { //foodAmount() : int
return this.mealSize;
}
public boolean isPet() { //isPet() : boolean
return true;
}
public void rollingInMud() { //rollingInMud() : void
println("Rolls in the mud.");
}
public String toString() { //toString() : String
return "";
}
public int getMealSize() { //getMealSize() : int
return this.mealSize;
}
public int getWeight() { //getWeight() : int
return this.weight;
}
public String getName() { //getName() : String
return this.name;
}
}
\ No newline at end of file
package td07;
public class Tigre implements Animaux{
private static final int MIN_FOOD = 0; //En UML, un final doit être écrit en majuscules.
private static final int MAX_FOOD = 20;
public Tiger() { //+Tigre()
}
public String shout() { //+shout() : String
return "Purr!";
}
public int foodAmount() { //+foodAmount() : int
}
public boolean isPet() { //+isPet() : boolean
return true;
}
public String toString() { //+toString() : String
return "";
}
public int getMIN_FOOD() { //+getMIN_FOOD() : int
return this.mealSize;
}
public int getWeight() { //+getMAX_FOOD() : int
return this.weight;
}
}
\ No newline at end of file
{
"java.debug.settings.onBuildFailureProceed": true
}
\ No newline at end of file
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
package tpOO.tp08;
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 java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class BreedingGroundTest {
public Participant p1,p2,p3,p4,p5,p6,p7,p8,p9,p10;
public BreedingGround v1,v2,v3;
public List<Participant> partList;
public Set<Participant> partSet;
@BeforeEach
public void initTest() {
partList = new ArrayList<Participant>();
partSet = new HashSet<Participant>();
p1 = new Participant("alice");
p2 = new Participant("bruno"); // the cheater registered in v1 and v3
p3 = new Participant("clement");
p4 = new Participant("dominique");
p5 = new Participant("elia");
p6 = new Participant("flore");
p7 = new Participant("gudul");
p8 = new Participant("hercule");
p9 = new Participant("isidor");
p10 = new Participant("jules");
// appariement des participants
p1.matchWith(p2);
p5.matchWith(p6);
p8.matchWith(p9);
v1 = new BreedingGround();
v1.registration(p1);
v1.registration(p2);
v1.registration(p3);
v1.registration(p4);
v2 = new BreedingGround();
v2.registration(p5);
v2.registration(p6);
v3 = new BreedingGround();
v3.registration(p8);
v3.registration(p9);
v3.registration(p10);
v3.registration(p2);
}
@Test
public void testRegistration() {
assertEquals(4, v1.getApplicants().size());
assertTrue(v1.getApplicants().contains(p1) && v1.getApplicants().contains(p2)
&& v1.getApplicants().contains(p3) && v1.getApplicants().contains(p4));
v1.clear();
assertEquals(Collections.emptySet(), v1.getApplicants());
assertTrue(v1.registration(p1));
assertEquals(1, v1.getApplicants().size());
assertTrue(v1.getApplicants().contains(p1));
assertFalse(v1.registration(p1));
}
@Test
public void testLoners() {
assertEquals(0, v2.loners().size());
assertEquals(Collections.emptyList(), v2.loners());
partList = v1.loners();
assertEquals(2, partList.size());
assertTrue(partList.contains(p3) && partList.contains(p4));
}
@Test
public void testLonersCleansing() {
v1.lonersCleansing();
assertEquals(2, v1.getApplicants().size());
assertTrue(v1.getApplicants().contains(p1) && v1.getApplicants().contains(p2));
v2.lonersCleansing();
assertEquals(2, v2.getApplicants().size());
assertTrue(v2.getApplicants().contains(p5) && v2.getApplicants().contains(p6));
}
@Test
public void testCheaters() {
assertEquals(Collections.emptyList(), v1.cheaters(v2));
partList.add(p2);
assertEquals(partList, v1.cheaters(v3));
}
@Test
public void testCheatersBan() {
assertTrue(p1.isMatchedWith(p2));
assertTrue(p2.isMatchedWith(p1));
v1.isolateCheater(p2);
assertFalse(p1.isMatchedWith(p2));
assertFalse(p2.isMatchedWith(p1));
}
@Test
public void testCheatersCleansing() {
partSet = v1.getApplicants();
v1.cheatersCleansing(v2);
assertEquals(partSet, v1.getApplicants());
partSet.clear();
partSet.add(p1); partSet.add(p3); partSet.add(p4);
v1.cheatersCleansing(v3);
assertEquals(partSet, v1.getApplicants());
}
@Test
public void testPossibleMerging() {
assertFalse(v1.possibleMerging(v1));
assertTrue(v1.possibleMerging(v2));
assertFalse(v1.possibleMerging(v3));
}
@Test
public void testMerge() {
partSet = v1.getApplicants();
partSet.addAll(v2.getApplicants());
v1.merging(v2);
assertEquals(partSet, v1.getApplicants());
partSet.clear();
partSet.addAll(v1.getApplicants());
partSet.addAll(v2.getApplicants());
partSet.addAll(v3.getApplicants());
v1.merging(v3);
assertEquals(partSet, v1.getApplicants());
}
@Test
public void testSecuredMerging() {
partSet = v1.getApplicants();
partSet.add(p8); partSet.add(p9); partSet.add(p10);
v1.securedMerging(v3);
assertEquals(partSet, v1.getApplicants());
partSet.addAll(v2.getApplicants());
v1.securedMerging(v2);
assertEquals(partSet, v1.getApplicants());
}
}
package tp08;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
public class Food implements IProduct, Comparable<Food> {
private String label;
private double price;
private LocalDate bestBeforDate;
private static int refIconnue = 0;
public Food(String label, double price, LocalDate bestBeforDate) {
if(label == null) {
this.label = "refUnknown" + refIconnue;
refIconnue++;
} else {
this.label = label;
}
this.price = price;
this.bestBeforDate = bestBeforDate;
}
public Food(String label, double price) {
if(label == null) {
this.label = "refUnknown" + refIconnue;
refIconnue++;
} else {
this.label = label;
}
this.price = price;
this.bestBeforDate = LocalDate.now().plus(10, ChronoUnit.DAYS);
}
public String getLabel() {
return this.label;
}
public double getPrice() {
return this.price;
}
public LocalDate getBestBeforDate() {
return this.bestBeforDate;
}
public boolean isPerishable() {
return true;
}
public boolean isBestBefore(LocalDate date) {
return this.bestBeforDate.isBefore(date);
}
@Override
public int compareTo(Food arg0) {
if(this.isBestBefore(arg0.getBestBeforDate())) {
return 1;
} else {
return -1;
}
}
public String toString() {
return "[" + this.label + "=" + this.price + " -> before " + this.bestBeforDate + "]";
}
}
\ No newline at end of file
package tp08;
public class Furniture implements IProduct {
private String label;
private double price;
private static int refInconnue = 0;
public Furniture(String label, double price) {
if(label == null) {
this.label = "refUnknown" + refInconnue;
refInconnue++;
} else {
this.label = label;
}
this.price = price;
}
public String getLabel() {
return this.label;
}
public double getPrice() {
return this.price;
}
public boolean isPerishable() {
return false;
}
public String toString() {
return "[" + this.label + "=" + this.price + "]";
}
}
\ No newline at end of file
package tp08;
public interface IProduct {
public double getPrice();
public boolean isPerishable();
}
\ 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