Merge branch 'master' of codefirst.iut.uca.fr:antoine.perederii/IUT

master^2
Antoine PEREDERII 1 year ago
commit 7a20b0ef89

@ -0,0 +1,131 @@
-- ? Q4). Combien y a til de documents ?
--* 150346
-- ? Q5). Quelle est la taille de la base de données ?
--* DOCUMENTS 150.3k
-- ? Q6). Afficher un unique document contenu dans cette collection. Que représente ce document ? De
-- ? Quelles données dispose-ton ?
--* un lieu , magasins
--* l'addresse la localisation, ...
-- ? Q7). Utiliser linterface de Compass pour parcourir quelques documents. Que remarquez-vous ?
-- Ont-ils tous la même structure ?
--* oui à peu près
-- ? Q8). Analyser la collection grâce à Compass. Cliquer plusieurs fois sur le bouton (en
-- nayant rien renseigné dans la barre Filter). Que remarquez-vous ? Pourquoi ?
--* il y a des champs avec un seul document parfois
-- ? Q9) Lister les noms des commerces répertoriés dans la ville de Tampa.
-- db.yelp.find({"city": "Tampa"},["name"])
-- ? Q10). Lister les 10 premières adresses qui sont soit en Floride (FL) ou soit dans le Nevada (NV).
-- Proposez deux façons décrire cette requête (en utilisant deux opérateurs différents).
--! db.yelp.find({"state": {"FA", "NV"}}},["name"]).limit(10)
db.yelp.find({$or: [{"state": "FL"}, {state: "NV"}]},["name"]).limit(10)
-- ? Q11). Lister les adresses de la ville dEdmonton ayant une note dau moins 4 étoiles. Proposez deux
-- façons décrire cette requête (lune avec un opérateur explicite, lautre avec la version implicite).
db.yelp.find({$and:[{"city": "Edmonton"},{"stars": {$gte:4}}]},["address"])
db.yelp.find({"city": "Edmonton", "stars": {$gte:4}},["address"])
-- ? Q12). Lister les adresses ayant une note dau plus une étoile avec plus de 400 commentaires
-- (review_count).
db.yelp.find({"stars": {$lte: 1}, review_count: {$gte: 400}},["address"])
[
{
_id: ObjectId('63972dd1158ef602a68b7c9b'),
address: '639 B Gravios Bluffs Blvd'
},
{
_id: ObjectId('63972dd2158ef602a68bdb68'),
address: '3750 Priority Way South Dr, Ste 200'
}
]
-- ? Q13). Lister les noms des entreprises et villes des plombiers (Plumbing) dArizona (AZ).
db.yelp.find({"state": "AZ", categories: "Plumbing"},["name", "city"])
-- ? Q14). Lister les noms et adresses des restaurants de Philadelphie (Philadelphia) qui possèdent une
-- terrasse (OutdoorSeating).
db.yelp.find({"categories": "Restaurants", "city" : "Philadelphia", "attributes.OutdoorSeating": "true"},["name", "address"])
-- ? Q15). Lister tous les restaurants japonais ayant obtenu une note supérieure à quatre étoiles.
db.yelp.find({"categories": "Restaurants", "categories" : "Japanese", "stars": {$gte: 4}})
-- ? Q16). Lister tous les restaurants japonais ou mexicains du Missouri (MO).
db.yelp.find({$or: [{"categories": ["Restaurants", "Japanese"], state: "MO"}, {"categories": ["Restaurants", "Mexican"], state: "MO"}]})
-- ? Q17). Lister toutes les adresses ayant un nombre davis inférieur ou égal à leur nombre détoiles.
db.yelp.find({$expr: {$lte: ["$review_count", "$stars"]}}, ["address"])
-- ? Q18). Lister tous les restaurants qui proposent à la fois la livraison et à emporter ou ni lun ni
-- lautre.
-- Proposer une requête qui compare les valeurs de deux champs afin de répondre à cette question.
db.yelp.find({$or: [{"attributes.RestaurantsTakeOut": true, "attributes.RestaurantsDelivery": true}, {"attributes.RestaurantsTakeOut": false, "attributes.RestaurantsDelivery": false}]})
-- ? Q19). Lister les pharmacies (drugstores) de la Nouvelle-Orléans dont on connaît les horaires dou-
-- verture.
--! db.yelp.find({"categories": "drugstores", state: "NO", hours: {$ne: null}})
-- ? Q20). Lister les parcs des villes de Bristol, Hulmeville, Langhorne, Newtown et Pendell en Pensyl-
-- vannie (PA).
-- ? Q21). Lister les églises de Floride qui ne sont pas dans les plus grandes villes (Miami, Orlando,
-- Tampa et Jacksonville) par ordre alphabétique.
-- ? Q22). Lister les noms des adresses référencées sur Virginia Street ("Virginia St") à Reno.
-- ? Q23). Lister les noms et adresses magasins du Tennessee (TN) dont le nom contient le mot "Tree"
-- ou le mot "Earth", les adresses ayant eu le plus de commentaires en premier.
-- ? Q24). Le restaurant Twin Peaks dIndianapolis change de propriétaire. Il faut donc mettre à jour
-- certaines informations. Enlevez la catégorie "Bars".
-- ? Q25). Supprimez également les catégories "Sports Bars", "American (New)" et "American (
-- Traditionnal)".
-- ? Q26). Le restaurant propose désormais de la cuisine française. Ajoutez la catégorie "French".
-- ? Q27). Ajoutez également les catégories "Creperies" et "Seafood". Vous devrez nutiliser quune
-- seule instruction.
-- ? Q28). Vérifiez que vos modifications ont bien été prises en compte

File diff suppressed because it is too large Load Diff

@ -0,0 +1,332 @@
################################
### TP NOTE ###
### étudiants : ###
### Damien Nortier (PM4) ###
### Antoine Perederi (PM4) ###
################################
import sqlite3
import numpy.random as npr
#### Ouvrir la connection ou creer la base
connection = sqlite3.connect("donnees.db")
#### Creer un curseur
curseur = connection.cursor()
#### Creer la table : executer une seule fois
try:
curseur.execute("CREATE TABLE utilisateurs (name TEXT, password TEXT)")
except:
print()
# Exercice 1
def AjouterUtilisateur(curseur):
login = str(input("login : "))
curseur.execute("SELECT count(*) FROM utilisateurs WHERE name = \"" + str(login) + "\"")
nb = (curseur.fetchall())[0][0]
if nb != 0 :
print("utilisateur déjà existant")
else :
mdp = str(input("mot de passe : "))
curseur.execute("INSERT INTO utilisateurs VALUES(\"{}\",\"{}\")".format(login, mdp))
def TestAjouterUtilisateur(curseur) :
nb = int(input("nb insertions : "))
for i in range(nb):
AjouterUtilisateur(curseur)
# TestAjouterUtilisateur(curseur)
def AfficherBdd(curseur):
curseur.execute("SELECT * FROM utilisateurs")
utilisateurs = curseur.fetchall()
if(utilisateurs):
for utilisateur in utilisateurs:
print(utilisateur)
else:
print("Aucun users dans la db")
def TestAfficherBdd(curseur) :
for i in range (5) :
AjouterUtilisateur(curseur)
AfficherBdd(curseur)
# TestAfficherBdd(curseur)
def Verification(curseur):
login = input("login :")
password = input("password :")
curseur.execute("SELECT * FROM utilisateurs WHERE name=? and password=?", (login, password))
if curseur.fetchone():
print("Authentification ok")
else :
print("login ou MdP incorrect")
# Exercice 2
import hashlib
def AjouterUtilisateurHash(curseur):
login = input("login :")
curseur.execute("SELECT * FROM utilisateurs WHERE name=?", (login, ))
if curseur.fetchone():
print("login deja existant")
return # pour quitter la fct
password = input("password :")
password2 = input("password Verification :")
if password != password2:
print("MdP differents")
return # pour quitter la fct
passwordHash = hashlib.sha256(password.encode()).hexdigest()
curseur.execute("INSERT INTO utilisateurs VALUES (?, ?)", (login, passwordHash))
connection.commit()
print("User insert with succes")
def VerificationHash(curseur):
login = input("login :")
password = input("password :")
passwordHash = hashlib.sha256(password.encode()).hexdigest()
curseur.execute("SELECT * FROM utilisateurs WHERE name=? and password=?", (login, passwordHash))
if curseur.fetchone():
print("Authentification ok")
else :
print("login ou MdP incorrect")
# AjouterUtilisateurHash(curseur)
# VerificationHash(curseur)
# Exercice 3
difMdP = "LaDbDeDamienEtAntoine"
def AjouterUtilisateurHashSel(curseur, sel):
login = input("login :")
curseur.execute("SELECT * FROM utilisateurs WHERE name=?", (login, ))
if curseur.fetchone():
print("login deja existant")
return # pour quitter la fct
password = input("password :")
password2 = input("password Verification :")
if password != password2:
print("MdP differents")
return # pour quitter la fct
passwordSel = password + sel
passwordHash = hashlib.sha256(passwordSel.encode()).hexdigest()
curseur.execute("INSERT INTO utilisateurs VALUES (?, ?)", (login, passwordHash))
connection.commit()
print("User insert with succes")
def VerificationHashSel(curseur, sel):
login = input("login :")
password = input("password :")
passwordHash = hashlib.sha256(password.encode() + sel.encode()).hexdigest()
curseur.execute("SELECT * FROM utilisateurs WHERE name=? and password=?", (login, passwordHash))
if curseur.fetchone():
print("Authentification ok")
else :
print("login ou MdP incorrecte")
# AjouterUtilisateurHashSel(curseur, difMdP)
# AfficherBdd(curseur)
# VerificationHashSel(curseur, difMdP)
# Exercice 4
def AjouterUtilisateurHashSelRandom(curseur) :
try:
curseur.execute("CREATE TABLE hash (name TEXT, sel NUMERIC)")
except:
a = 0 # juste pour pas laisser ça vide
sel = npr.randint(1, 10)
login = input("login :")
curseur.execute("SELECT * FROM utilisateurs WHERE name=?", (login, ))
if curseur.fetchone():
print("login deja existant")
return # pour quitter la fct
password = input("password :")
password2 = input("password Verification :")
if password != password2:
print("MdP differents")
return # pour quitter la fct
passwordSel = password + str(sel)
passwordHash = hashlib.sha256(passwordSel.encode()).hexdigest()
curseur.execute("INSERT INTO utilisateurs VALUES (?, ?)", (login, passwordHash))
curseur.execute("INSERT INTO hash VALUES (?, ?)", (login, str(sel)))
connection.commit()
print("User insert with success")
def AfficherBddPourTestSelRandom(curseur):
print("\t\tutilisateurs")
curseur.execute("SELECT * FROM utilisateurs")
utilisateurs = curseur.fetchall()
if(utilisateurs):
for utilisateur in utilisateurs:
print(utilisateur)
else:
print("Aucun users dans la db")
print("\thash")
curseur.execute("SELECT * FROM hash")
hashs = curseur.fetchall()
if(hashs):
for sel in hashs:
print(sel)
else:
print("Aucun hash dans la db")
def TestAjouterUtilisateurHashSelRandom(curseur) :
for i in range (5) :
AjouterUtilisateurHashSelRandom(curseur)
AfficherBddPourTestSelRandom(curseur)
# TestAjouterUtilisateurHashSelRandom(curseur)
# Exercice 5
import bcrypt
def AjouterUtilisateurBcrypt(curseur):
login = input("login :")
curseur.execute("SELECT * FROM utilisateurs WHERE name=?", (login, ))
if curseur.fetchone():
print("login deja existant")
return # pour quitter la fct
password = input("password :")
password2 = input("password Verification :")
if password != password2:
print("MdP differents")
return # pour quitter la fct
passwordHash = bcrypt.hashpw(password.encode(), bcrypt.gensalt())
curseur.execute("INSERT INTO utilisateurs VALUES (?, ?)", (login, passwordHash.decode()))
connection.commit()
print("User insert with succes")
def VerificationBcrypt(curseur):
login = input("login :")
password = input("password :")
curseur.execute("SELECT password FROM utilisateurs WHERE name=?", (login,))
bdPassword = curseur.fetchone()
if bdPassword:
hashS = bdPassword[0]
if bcrypt.checkpw(password.encode(), hashS.encode()):
print("login ok")
else:
print("login ou MdP incorrect")
else:
print("login ou MdP incorrect")
# AjouterUtilisateurBcrypt(curseur)
# AfficherBdd(curseur)
# VerificationBcrypt(curseur)
# Exercice 6
from Crypto.Cipher import AES
# from Crypto.random import get_random_bytes
from Crypto.Util.Padding import pad, unpad
CLE_AES = b'DAMIEN ANTOINEPE'
# curseur.execute("CREATE TABLE utilisateursExo6 (name TEXT, passwordHash TEXT, nonce TEXT)")
def chiffrementAES(message):
res = AES.new(CLE_AES, AES.MODE_CTR)
nonce = cipher.nonce
ciphertext = ciph.encrypt(pad(message.encode(), AES.block_size))
return ciphertext, nonce
def dechiffrementAES(ciphertext, nonce):
res = AES.new(CLE_AES, AES.MODE_CTR, nonce=nonce)
decrypted = unpad(cipher.decrypt(ciphertext), AES.block_size)
return decrypted.decode()
def AjouterUtilisateurAES(curseur):
login = input("login :")
curseur.execute("SELECT * FROM utilisateurs WHERE name=?", (login, ))
if curseur.fetchone():
print("login deja existant")
return # pour quitter la fct
password = input("password :")
password2 = input("password Verification :")
if password != password2:
print("MdP differents")
return # pour quitter la fct
passwordHash = bcrypt.hashpw(password.encode(), bcrypt.gensalt())
encryptedHash, nonce = chiffrementAES(passwordHash.decode())
curseur.execute("INSERT INTO utilisateursExo6 VALUES (?, ?, ?)", (login, encryptedHash, nonce.hex()))
connection.commit()
print("User insert with succes")
def VerificationAES(curseur):
login = input("login :")
password = input("password :")
curseur.execute("SELECT passwordHash, nonce FROM utilisateursExo6 WHERE name=?", (login,))
bdPassword = curseur.fetchone()
if bdPassword:
hashS = bdPassword[0]
nonceDb = bdPassword[1]
decryptedHash = dechiffrementAES(hashS, nonceDb)
if bcrypt.checkpw(password.encode(), decryptedHash.encode()):
print("login ok")
else:
print("login ou MdP incorrect")
else:
print("login ou MdP incorrect")
AjouterUtilisateurAES(curseur)
AfficherBdd(curseur)
VerificationAES(curseur)
# Exercice 7
import random
import string
# 1
def generateurMdP(N, n, p):
MdP = []
for i in range(N):
mpd = ''.join(random.choice(alph) for j in range(n))
MdP.append(mdp)
return MdP

@ -32,4 +32,9 @@ public class Lampe {
public int getNiveau() {
return niveau;
}
public boolean estAllumee() {
// TODO Auto-generated method stub
return niveau == 0 ? false : true;
}
}

@ -5,8 +5,8 @@ package model;
// Voici l'invocateur
//
public class Telecommande {
Commande[] commandesMarche;
Commande[] commandesArret;
public Commande[] commandesMarche;
public Commande[] commandesArret;
public Commande commandeAnnulation;
public Telecommande() {

@ -0,0 +1,68 @@
package test;
import org.junit.Test;
import model.Commande;
import model.CommandeAllumerJacuzzi;
import model.CommandeAllumerLampe;
import model.CommandeAllumerStereo;
import model.CommandeAllumerTV;
import model.CommandeEteindreJacuzzi;
import model.CommandeEteindreLampe;
import model.CommandeEteindreStereo;
import model.CommandeEteindreTV;
import model.Jacuzzi;
import model.Lampe;
import model.MacroCommande;
import model.Stereo;
import model.TV;
import static org.junit.Assert.*;
public class ChargeurTelecommandeTest {
@Test
public void testMacroAllumage() {
// Création des équipements
Lampe lampe = new Lampe("Séjour");
TV tv = new TV("Séjour");
Stereo stereo = new Stereo("Séjour");
Jacuzzi jacuzzi = new Jacuzzi();
// Création des commandes pour allumer les équipements
CommandeAllumerLampe lampeAllumee = new CommandeAllumerLampe(lampe);
CommandeAllumerStereo stereoAllumee = new CommandeAllumerStereo(stereo);
CommandeAllumerTV tvAllumee = new CommandeAllumerTV(tv);
CommandeAllumerJacuzzi jacuzziAllume = new CommandeAllumerJacuzzi(jacuzzi);
// Création de la macro commande d'allumage
Commande[] allumageGroupe = {lampeAllumee, stereoAllumee, tvAllumee, jacuzziAllume};
MacroCommande macroAllumageGroupe = new MacroCommande(allumageGroupe);
// Vérification que la macro commande d'allumage fonctionne correctement
assertNotNull(macroAllumageGroupe);
macroAllumageGroupe.executer();
}
@Test
public void testMacroExtinction() {
// Création des équipements
Lampe lampe = new Lampe("Séjour");
TV tv = new TV("Séjour");
Stereo stereo = new Stereo("Séjour");
Jacuzzi jacuzzi = new Jacuzzi();
// Création des commandes pour éteindre les équipements
CommandeEteindreLampe lampeEteinte = new CommandeEteindreLampe(lampe);
CommandeEteindreStereo stereoEteinte = new CommandeEteindreStereo(stereo);
CommandeEteindreTV tvEteinte = new CommandeEteindreTV(tv);
CommandeEteindreJacuzzi jacuzziEteint = new CommandeEteindreJacuzzi(jacuzzi);
// Création de la macro commande d'extinction
Commande[] extinctionGroupe = {lampeEteinte, stereoEteinte, tvEteinte, jacuzziEteint};
MacroCommande macroExtinctionGroupe = new MacroCommande(extinctionGroupe);
// Vérification que la macro commande d'extinction fonctionne correctement
assertNotNull(macroExtinctionGroupe);
}
}

@ -1,43 +1,214 @@
package test;
import static org.junit.Assert.assertEquals;
//package test;
//
//import static org.junit.Assert.assertEquals;
//
//import org.junit.Test;
//
//import model.Commande;
//import model.PasDeCommande;
//import model.Telecommande;
//import static org.junit.Assert.*;
//
//public class TelecommandeTest {
//
// @Test
// public void testTelecommande() {
// Telecommande telecommande = new Telecommande();
// Commande marcheCommande = new PasDeCommande();
// Commande arretCommande = new PasDeCommande();
//
// telecommande.setCommande(0, marcheCommande, arretCommande);
// telecommande.boutonMarchePresse(0);
//
// assertEquals(marcheCommande, telecommande.commandeAnnulation);
// }
//
//// @Test
//// public void testToString() {
//// // Arrange
//// Telecommande telecommande = new Telecommande();
//// Commande marcheCommande = new PasDeCommande();
//// Commande arretCommande = new PasDeCommande();
//// telecommande.setCommande(0, marcheCommande, arretCommande);
////
//// // Act
//// String result = telecommande.toString();
////
//// // Assert
//// String expected = "\n------ Télécommande -------\n" +
//// "[empt 0] PasDeCommande PasDeCommande\n" +
//// "[annulation] PasDeCommande\n";
//// assertEquals(expected, result);
//// }
//}
import org.junit.Test;
import model.Commande;
import model.CommandeAllumerLampe;
import model.CommandeEteindreLampe;
import model.Lampe;
import model.PasDeCommande;
import model.Telecommande;
import static org.junit.Assert.*;
public class TelecommandeTest {
@Test
public void testTelecommande() {
public void testSetCommande() {
Telecommande telecommande = new Telecommande();
Lampe lampe = new Lampe("Test");
Commande commandeMarche = new CommandeAllumerLampe(lampe);
Commande commandeArret = new CommandeEteindreLampe(lampe);
telecommande.setCommande(0, commandeMarche, commandeArret);
assertSame(commandeMarche, telecommande.commandesMarche[0]);
assertSame(commandeArret, telecommande.commandesArret[0]);
}
@Test
public void testBoutonMarchePresse() {
Telecommande telecommande = new Telecommande();
Commande marcheCommande = new PasDeCommande();
Commande arretCommande = new PasDeCommande();
Lampe lampe = new Lampe("Test");
Commande commandeMarche = new CommandeAllumerLampe(lampe);
telecommande.setCommande(0, commandeMarche, null);
telecommande.setCommande(0, marcheCommande, arretCommande);
telecommande.boutonMarchePresse(0);
assertEquals(marcheCommande, telecommande.commandeAnnulation);
assertTrue(lampe.estAllumee());
assertSame(commandeMarche, telecommande.commandeAnnulation);
}
// @Test
// public void testToString() {
// // Arrange
// Telecommande telecommande = new Telecommande();
// Commande marcheCommande = new PasDeCommande();
// Commande arretCommande = new PasDeCommande();
// telecommande.setCommande(0, marcheCommande, arretCommande);
//
// // Act
// String result = telecommande.toString();
//
// // Assert
// String expected = "\n------ Télécommande -------\n" +
// "[empt 0] PasDeCommande PasDeCommande\n" +
// "[annulation] PasDeCommande\n";
// assertEquals(expected, result);
// }
@Test
public void testBoutonArretPresse() {
Telecommande telecommande = new Telecommande();
Lampe lampe = new Lampe("Test");
Commande commandeArret = new CommandeEteindreLampe(lampe);
telecommande.setCommande(0, null, commandeArret);
telecommande.boutonArretPresse(0);
assertFalse(lampe.estAllumee());
assertSame(commandeArret, telecommande.commandeAnnulation);
}
@Test
public void testBoutonAnnulPresse() {
Telecommande telecommande = new Telecommande();
Lampe lampe = new Lampe("Test");
Commande commandeMarche = new CommandeAllumerLampe(lampe);
telecommande.setCommande(0, commandeMarche, null);
telecommande.boutonMarchePresse(0);
assertTrue(lampe.estAllumee());
telecommande.boutonAnnulPresse();
assertFalse(lampe.estAllumee());
}
@Test
public void testToString() {
Telecommande telecommande = new Telecommande();
String expected = "\n------ Télécommande -------\n";
for (int i = 0; i < 7; i++) {
expected += "[empt " + i + "] model.PasDeCommande model.PasDeCommande\n";
}
expected += "[annulation] model.PasDeCommande\n";
assertEquals(expected, telecommande.toString());
}
@Test
public void testConstruction() {
Telecommande telecommande = new Telecommande();
assertNotNull(telecommande.commandesMarche);
assertNotNull(telecommande.commandesArret);
assertNotNull(telecommande.commandeAnnulation);
assertEquals(7, telecommande.commandesMarche.length);
assertEquals(7, telecommande.commandesArret.length);
for (int i = 0; i < 7; i++) {
assertTrue(telecommande.commandesMarche[i] instanceof PasDeCommande);
assertTrue(telecommande.commandesArret[i] instanceof PasDeCommande);
}
assertTrue(telecommande.commandeAnnulation instanceof PasDeCommande);
}
@Test
public void testSetCommande1() {
Telecommande telecommande = new Telecommande();
Commande commandeMarche = new CommandeAllumerLampe(new Lampe("Test"));
Commande commandeArret = new CommandeEteindreLampe(new Lampe("Test"));
telecommande.setCommande(0, commandeMarche, commandeArret);
assertSame(commandeMarche, telecommande.commandesMarche[0]);
assertSame(commandeArret, telecommande.commandesArret[0]);
}
@Test
public void testBoutonMarchePresse1() {
Telecommande telecommande = new Telecommande();
Lampe lampe = new Lampe("Test");
Commande commandeMarche = new CommandeAllumerLampe(lampe);
telecommande.setCommande(0, commandeMarche, null);
telecommande.boutonMarchePresse(0);
assertTrue(lampe.estAllumee());
assertSame(commandeMarche, telecommande.commandeAnnulation);
}
@Test
public void testBoutonArretPresse1() {
Telecommande telecommande = new Telecommande();
Lampe lampe = new Lampe("Test");
Commande commandeArret = new CommandeEteindreLampe(lampe);
telecommande.setCommande(0, null, commandeArret);
telecommande.boutonArretPresse(0);
assertFalse(lampe.estAllumee());
assertSame(commandeArret, telecommande.commandeAnnulation);
}
@Test
public void testBoutonAnnulPresse1() {
Telecommande telecommande = new Telecommande();
Lampe lampe = new Lampe("Test");
Commande commandeMarche = new CommandeAllumerLampe(lampe);
telecommande.setCommande(0, commandeMarche, null);
telecommande.boutonMarchePresse(0);
assertTrue(lampe.estAllumee());
telecommande.boutonAnnulPresse();
assertFalse(lampe.estAllumee());
}
@Test
public void testToString1() {
Telecommande telecommande = new Telecommande();
String expected = "\n------ Télécommande -------\n";
for (int i = 0; i < 7; i++) {
expected += "[empt " + i + "] model.PasDeCommande model.PasDeCommande\n";
}
expected += "[annulation] model.PasDeCommande\n";
assertEquals(expected, telecommande.toString());
}
}

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="corr_telecommande_groupe/models"/>
<classpathentry kind="src" path="corr_telecommande_groupe/tests"/>
<classpathentry kind="output" path="out/production/ex_patron_macrocommande"/>
</classpath>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ex_patron_macrocommande</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,37 @@
// package tetepremiere.commande.groupe;
public class ChargeurTelecommande {
public static void main(String[] args) {
Telecommande remoteControl = new Telecommande();
Lampe lampe = new Lampe("Séjour");
TV tv = new TV("Séjour");
Stereo stereo = new Stereo("Séjour");
Jacuzzi jacuzzi = new Jacuzzi();
CommandeAllumerLampe lampeAllumee = new CommandeAllumerLampe(lampe);
CommandeAllumerStereo stereoAllumee = new CommandeAllumerStereo(stereo);
CommandeAllumerTV tvAllumee = new CommandeAllumerTV(tv);
CommandeAllumerJacuzzi jacuzziAllume = new CommandeAllumerJacuzzi(jacuzzi);
CommandeEteindreLampe lampeEteinte = new CommandeEteindreLampe(lampe);
CommandeEteindreStereo stereoEteinte = new CommandeEteindreStereo(stereo);
CommandeEteindreTV tvEteinte = new CommandeEteindreTV(tv);
CommandeEteindreJacuzzi jacuzziEteint = new CommandeEteindreJacuzzi(jacuzzi);
Commande[] allumageGroupe = { lampeAllumee, stereoAllumee, tvAllumee, jacuzziAllume};
Commande[] extinctionGroupe = { lampeEteinte, stereoEteinte, tvEteinte, jacuzziEteint};
MacroCommande macroAllumageGroupe = new MacroCommande(allumageGroupe);
MacroCommande macroExtinctionGroupe = new MacroCommande(extinctionGroupe);
remoteControl.setCommande(0, macroAllumageGroupe, macroExtinctionGroupe);
System.out.println(remoteControl);
System.out.println("---Exécution de Macro Marche ---");
remoteControl.boutonMarchePresse(0);
System.out.println("--- Exécution de Macro Arret ---");
remoteControl.boutonArretPresse(0);
}
}

@ -0,0 +1,6 @@
// package tetepremiere.commande.groupe;
public interface Commande {
public void executer();
public void annuler();
}

@ -0,0 +1,17 @@
// package tetepremiere.commande.groupe;
public class CommandeAllumerJacuzzi implements Commande {
Jacuzzi jacuzzi;
public CommandeAllumerJacuzzi(Jacuzzi jacuzzi) {
this.jacuzzi = jacuzzi;
}
public void executer() {
jacuzzi.allumer();
jacuzzi.setTemperature(40);
jacuzzi.bouillonner();
}
public void annuler() {
jacuzzi.eteindre();
}
}

@ -0,0 +1,17 @@
// package tetepremiere.commande.groupe;
public class CommandeAllumerLampe implements Commande {
Lampe lampe;
public CommandeAllumerLampe(Lampe lampe) {
this.lampe = lampe;
}
public void executer() {
lampe.marche();
}
public void annuler() {
lampe.arret();
}
}

@ -0,0 +1,15 @@
// package tetepremiere.commande.groupe;
public class CommandeAllumerLampeSejour implements Commande {
Lampe lampe;
public CommandeAllumerLampeSejour(Lampe lampe) {
this.lampe = lampe;
}
public void executer() {
lampe.arret();
}
public void annuler() {
lampe.marche();
}
}

@ -0,0 +1,17 @@
// package tetepremiere.commande.groupe;
public class CommandeAllumerStereo implements Commande {
Stereo stereo;
public CommandeAllumerStereo(Stereo stereo) {
this.stereo = stereo;
}
public void executer() {
stereo.marche();
}
public void annuler() {
stereo.arret();
}
}

@ -0,0 +1,19 @@
// package tetepremiere.commande.groupe;
public class CommandeAllumerStereoAvecCD implements Commande {
Stereo stereo;
public CommandeAllumerStereoAvecCD(Stereo stereo) {
this.stereo = stereo;
}
public void executer() {
stereo.marche();
stereo.setCD();
stereo.setVolume(11);
}
public void annuler() {
stereo.arret();
}
}

@ -0,0 +1,18 @@
// package tetepremiere.commande.groupe;
public class CommandeAllumerTV implements Commande {
TV tv;
public CommandeAllumerTV(TV tv) {
this.tv= tv;
}
public void executer() {
tv.marche();
tv.selectionnerCanal();
}
public void annuler() {
tv.arret();
}
}

@ -0,0 +1,17 @@
// package tetepremiere.commande.groupe;
public class CommandeEteindreJacuzzi implements Commande {
Jacuzzi jacuzzi;
public CommandeEteindreJacuzzi(Jacuzzi jacuzzi) {
this.jacuzzi = jacuzzi;
}
public void executer() {
jacuzzi.setTemperature(36);
jacuzzi.eteindre();
}
public void annuler() {
jacuzzi.allumer();
}
}

@ -0,0 +1,17 @@
// package tetepremiere.commande.groupe;
public class CommandeEteindreLampe implements Commande {
Lampe lampe;
public CommandeEteindreLampe(Lampe lampe) {
this.lampe = lampe;
}
public void executer() {
lampe.arret();
}
public void annuler() {
lampe.marche();
}
}

@ -0,0 +1,15 @@
// package tetepremiere.commande.groupe;
public class CommandeEteindreLampeSejour implements Commande {
Lampe lampe;
public CommandeEteindreLampeSejour(Lampe lampe) {
this.lampe = lampe;
}
public void executer() {
lampe.marche();
}
public void annuler() {
lampe.arret();
}
}

@ -0,0 +1,17 @@
// package tetepremiere.commande.groupe;
public class CommandeEteindreStereo implements Commande {
Stereo stereo;
public CommandeEteindreStereo(Stereo stereo) {
this.stereo = stereo;
}
public void executer() {
stereo.arret();
}
public void annuler() {
stereo.marche();
}
}

@ -0,0 +1,17 @@
// package tetepremiere.commande.groupe;
public class CommandeEteindreTV implements Commande {
TV tv;
public CommandeEteindreTV(TV tv) {
this.tv= tv;
}
public void executer() {
tv.arret();
}
public void annuler() {
tv.marche();
}
}

@ -0,0 +1,22 @@
// package tetepremiere.commande.groupe;
public class CommandeEteindreVentilateur implements Commande {
Ventilateur ventilateur;
int derniereVitesse;
public CommandeEteindreVentilateur(Ventilateur ventilateur) {
this.ventilateur = ventilateur;
}
public void executer() {
derniereVitesse = ventilateur.getVitesse();
ventilateur.arreter();
}
public void annuler() {
switch (derniereVitesse) {
case Ventilateur.RAPIDE: ventilateur.rapide(); break;
case Ventilateur.MOYEN: ventilateur.moyen(); break;
case Ventilateur.LENT: ventilateur.lent(); break;
default: ventilateur.arreter(); break;
}
}
}

@ -0,0 +1,22 @@
// package tetepremiere.commande.groupe;
public class CommandeVentilateurMoyen implements Commande {
Ventilateur ventilateur;
int derniereVitesse;
public CommandeVentilateurMoyen(Ventilateur ventilateur) {
this.ventilateur = ventilateur;
}
public void executer() {
derniereVitesse = ventilateur.getVitesse();
ventilateur.moyen();
}
public void annuler() {
switch (derniereVitesse) {
case Ventilateur.RAPIDE: ventilateur.rapide(); break;
case Ventilateur.MOYEN: ventilateur.moyen(); break;
case Ventilateur.LENT: ventilateur.lent(); break;
default: ventilateur.arreter(); break;
}
}
}

@ -0,0 +1,22 @@
// package tetepremiere.commande.groupe;
public class CommandeVentilateurRapide implements Commande {
Ventilateur ventilateur;
int derniereVitesse;
public CommandeVentilateurRapide(Ventilateur ventilateur) {
this.ventilateur = ventilateur;
}
public void executer() {
derniereVitesse = ventilateur.getVitesse();
ventilateur.rapide();
}
public void annuler() {
switch (derniereVitesse) {
case Ventilateur.RAPIDE: ventilateur.rapide(); break;
case Ventilateur.MOYEN: ventilateur.moyen(); break;
case Ventilateur.LENT: ventilateur.lent(); break;
default: ventilateur.arreter(); break;
}
}
}

@ -0,0 +1,49 @@
public class Jacuzzi {
boolean allume;
int temperature;
public Jacuzzi() {
}
public void allumer() {
allume = true;
}
public void eteindre() {
allume = false;
}
public void bouillonner() {
if (allume) {
System.out.println("Le jaccuzi bouillonne !");
} else {
throw new IllegalStateException("Impossible de bouillonner lorsque le jacuzzi est éteint.");
}
}
public void marche() {
if (allume) {
System.out.println("Le jaccuzi est en marche");
} else {
throw new IllegalStateException("Impossible de démarrer le jacuzzi lorsque celui-ci est éteint.");
}
}
public void arret() {
if (allume) {
System.out.println("Le jaccuzi est arrêté");
} else {
throw new IllegalStateException("Impossible d'arrêter le jacuzzi car il est déjà éteint.");
}
}
public void setTemperature(int temperature) {
if (temperature > this.temperature) {
System.out.println("Le jacuzzi chauffe à " + temperature + "°");
} else {
System.out.println("Le jacuzzi refroidit à " + temperature + "°");
}
this.temperature = temperature;
}
}

@ -0,0 +1,34 @@
// package tetepremiere.commande.groupe;
public class Lampe {
String localisation;
int niveau;
public Lampe(String localisation) {
this.localisation = localisation;
}
public void marche() {
niveau = 100;
System.out.println(localisation+": lumière allumée");
}
public void arret() {
niveau = 0;
System.out.println(localisation+": lumière éteinte");
}
public void attenuer(int niveau) {
this.niveau = niveau;
if (niveau == 0) {
arret();
}
else {
System.out.println("Le niveau de la lampe est positionné sur " + niveau + "%");
}
}
public int getNiveau() {
return niveau;
}
}

@ -0,0 +1,22 @@
// package tetepremiere.commande.groupe;
public class MacroCommande implements Commande {
Commande[] commandes;
public MacroCommande(Commande[] commandes) {
this.commandes = commandes;
}
public void executer() {
for (int i = 0; i < commandes.length; i++) {
commandes[i].executer();
}
}
public void annuler() {
for (int i = 0; i < commandes.length; i++) {
commandes[i].annuler();
}
}
}

@ -0,0 +1,6 @@
// package tetepremiere.commande.groupe;
public class PasDeCommande implements Commande {
public void executer() { }
public void annuler() { }
}

@ -0,0 +1,55 @@
public class Stereo {
String localisation;
boolean allume;
int volume;
public Stereo(String localisation) {
this.localisation = localisation;
}
public void marche() {
this.allume = true;
System.out.println(localisation + ": stéréo allumée");
}
public void arret() {
this.allume = false;
System.out.println(localisation + ": stéréo éteinte");
}
public void setCD() {
if (!allume) {
throw new IllegalStateException("La stéréo est éteinte. Allumez-la d'abord.");
}
System.out.println(localisation + ": stéréo réglée pour l'entrée CD");
}
public void setDVD() {
if (!allume) {
throw new IllegalStateException("La stéréo est éteinte. Allumez-la d'abord.");
}
System.out.println(localisation + ": stéréo réglée pour l'entrée DVD");
}
public void setRadio() {
if (!allume) {
throw new IllegalStateException("La stéréo est éteinte. Allumez-la d'abord.");
}
System.out.println(localisation + ": stéréo réglée pour la radio");
}
public void setVolume(int volume) {
if (!allume) {
throw new IllegalStateException("La stéréo est éteinte. Allumez-la d'abord.");
}
if (volume < 0 || volume > 11) {
throw new IllegalArgumentException("Le volume doit être compris entre 0 et 11.");
}
this.volume = volume;
System.out.println(localisation + ": le volume stéréo est " + volume);
}
public int getVolume() {
return volume;
}
}

@ -0,0 +1,23 @@
// package tetepremiere.commande.groupe;
public class TV {
String localisation;
int canal;
public TV(String location) {
this.localisation = location;
}
public void marche() {
System.out.println(localisation + ": la télé est allumée");
}
public void arret() {
System.out.println(localisation + ": la télé est éteinte");
}
public void selectionnerCanal() {
this.canal = 3;
System.out.println(localisation + ": le canal est positionné sur VCR");
}
}

@ -0,0 +1,52 @@
// package tetepremiere.commande.groupe;
//
// Voici l'invocateur
//
public class Telecommande {
Commande[] commandesMarche;
Commande[] commandesArret;
Commande commandeAnnulation;
public Telecommande() {
commandesMarche = new Commande[7];
commandesArret = new Commande[7];
Commande pasDeCommande = new PasDeCommande();
for(int i=0;i<7;i++) {
commandesMarche[i] = pasDeCommande;
commandesArret[i] = pasDeCommande;
}
commandeAnnulation = pasDeCommande;
}
public void setCommande(int empt, Commande comMarche, Commande comArret) {
commandesMarche[empt] = comMarche;
commandesArret[empt] = comArret;
}
public void boutonMarchePresse(int empt) {
commandesMarche[empt].executer();
commandeAnnulation = commandesMarche[empt];
}
public void boutonArretPresse(int empt) {
commandesArret[empt].executer();
commandeAnnulation = commandesArret[empt];
}
public void boutonAnnulPresse() {
commandeAnnulation.annuler();
}
public String toString() {
StringBuffer stringBuff = new StringBuffer();
stringBuff.append("\n------ Télécommande -------\n");
for (int i = 0; i < commandesMarche.length; i++) {
stringBuff.append("[empt " + i + "] " + commandesMarche[i].getClass().getName()
+ " " + commandesArret[i].getClass().getName() + "\n");
}
stringBuff.append("[annulation] " + commandeAnnulation.getClass().getName() + "\n");
return stringBuff.toString();
}
}

@ -0,0 +1,42 @@
// package tetepremiere.commande.groupe;
public class Ventilateur {
public static final int RAPIDE = 3;
public static final int MOYEN = 2;
public static final int LENT = 1;
public static final int ARRET = 0;
String localisation;
int vitesse;
public Ventilateur(String localisation) {
this.localisation = localisation;
}
public void rapide() {
// regler le ventilateur sur rapide
vitesse = RAPIDE;
System.out.println(localisation + ": ventilateur sur rapide");
}
public void moyen() {
// regler le ventilateur sur moyen
vitesse = MOYEN;
System.out.println(localisation + ": ventilateur sur moyen");
}
public void lent() {
// regler le ventilateur sur lent
vitesse = LENT;
System.out.println(localisation + ": ventilateur sur lent");
}
public void arreter() {
// arrete le ventilateur
vitesse = 0;
System.out.println(localisation + ": ventilateur arrêté");
}
public int getVitesse() {
return vitesse;
}
}

@ -0,0 +1,149 @@
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class CommandesTest {
@Test
public void testCommandeAllumerJacuzzi() {
Jacuzzi jacuzzi = new Jacuzzi();
Commande commande = new CommandeAllumerJacuzzi(jacuzzi);
commande.executer();
assertTrue(jacuzzi.allume);
assertEquals(40, jacuzzi.temperature);
}
@Test
public void testCommandeEteindreJacuzzi() {
Jacuzzi jacuzzi = new Jacuzzi();
Commande commande = new CommandeEteindreJacuzzi(jacuzzi);
commande.executer();
assertFalse(jacuzzi.allume);
assertEquals(36, jacuzzi.temperature);
}
@Test
public void testCommandeAnnulerJacuzzi() {
Jacuzzi jacuzzi = new Jacuzzi();
Commande commande = new CommandeAllumerJacuzzi(jacuzzi);
commande.executer();
commande.annuler();
assertFalse(jacuzzi.allume);
assertEquals(40, jacuzzi.temperature);
}
@Test
public void testPasDeCommande() {
Commande pasDeCommande = new PasDeCommande();
pasDeCommande.executer();
pasDeCommande.annuler();
}
@Test
public void testMacroCommande() {
Jacuzzi jacuzzi = new Jacuzzi();
Commande commande1 = new CommandeAllumerJacuzzi(jacuzzi);
Commande commande2 = new CommandeEteindreJacuzzi(jacuzzi);
Commande[] commandes = {commande1, commande2};
MacroCommande macroCommande = new MacroCommande(commandes);
macroCommande.executer();
macroCommande.annuler();
}
@Test
public void testCommandeAllumerLampe() {
Lampe lampe = new Lampe("Salon");
Commande commande = new CommandeAllumerLampe(lampe);
commande.executer();
assertEquals(100, lampe.niveau);
}
@Test
public void testCommandeEteindreLampe() {
Lampe lampe = new Lampe("Salon");
Commande commande = new CommandeEteindreLampe(lampe);
commande.executer();
assertEquals(0, lampe.niveau);
}
@Test
public void testCommandeAnnulerLampe() {
Lampe lampe = new Lampe("Salon");
Commande commande = new CommandeAllumerLampe(lampe);
commande.executer();
commande.annuler();
assertEquals(0, lampe.niveau);
}
@Test
public void testCommandeEteindreLampeAnnuler() {
Lampe lampe = new Lampe("Salon");
Commande commande = new CommandeEteindreLampe(lampe);
commande.executer();
commande.annuler();
assertEquals(100, lampe.niveau);
}
@Test
public void testCommandeAllumerLampeSejour() {
Lampe lampe = new Lampe("Séjour");
Commande commande = new CommandeAllumerLampeSejour(lampe);
commande.executer();
assertEquals(0, lampe.niveau);
}
@Test
public void testCommandeEteindreLampeSejour() {
Lampe lampe = new Lampe("Séjour");
Commande commande = new CommandeEteindreLampeSejour(lampe);
commande.executer();
assertEquals(100, lampe.niveau);
}
@Test
public void testCommandeAnnulerLampeSejour() {
Lampe lampe = new Lampe("Séjour");
Commande commande = new CommandeAllumerLampeSejour(lampe);
commande.executer();
commande.annuler();
assertEquals(100, lampe.niveau);
}
@Test
public void testCommandeAnnulerEteindreLampeSejour() {
Lampe lampe = new Lampe("Séjour");
Commande commande = new CommandeEteindreLampeSejour(lampe);
commande.executer();
commande.annuler();
assertEquals(0, lampe.niveau);
}
@Test
public void testCommandeAllumerStereoAvecCD() {
Stereo stereo = new Stereo("Salon");
Commande commande = new CommandeAllumerStereoAvecCD(stereo);
commande.executer();
assertEquals(11, stereo.volume);
}
@Test
public void testCommandeAnnulerStereoAvecCD() {
Stereo stereo = new Stereo("Salon");
Commande commande = new CommandeAllumerStereoAvecCD(stereo);
commande.executer();
commande.annuler();
assertFalse(stereo.allume);
}
@Test
public void testCommandeAllumerTV() {
TV tv = new TV("Salon");
Commande commande = new CommandeAllumerTV(tv);
commande.executer();
assertEquals(3, tv.canal);
}
}

@ -0,0 +1,76 @@
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class JacuzziTest {
@Test
public void testAllumer() {
Jacuzzi jacuzzi = new Jacuzzi();
jacuzzi.allumer();
assertTrue(jacuzzi.allume);
}
@Test
public void testEteindre() {
Jacuzzi jacuzzi = new Jacuzzi();
jacuzzi.allumer();
jacuzzi.eteindre();
assertFalse(jacuzzi.allume);
}
@Test
public void testBouillonnerQuandAllume() {
Jacuzzi jacuzzi = new Jacuzzi();
jacuzzi.allumer();
assertDoesNotThrow(jacuzzi::bouillonner);
}
@Test
public void testBouillonnerQuandPasAllume() {
Jacuzzi jacuzzi = new Jacuzzi();
assertThrows(IllegalStateException.class, jacuzzi::bouillonner);
}
@Test
public void testMarcheQuandAllume() {
Jacuzzi jacuzzi = new Jacuzzi();
jacuzzi.allumer();
assertDoesNotThrow(jacuzzi::marche);
}
@Test
public void testMarcheQuandPasAllume() {
Jacuzzi jacuzzi = new Jacuzzi();
assertThrows(IllegalStateException.class, jacuzzi::marche);
}
@Test
public void testArretQuandAllume() {
Jacuzzi jacuzzi = new Jacuzzi();
jacuzzi.allumer();
assertDoesNotThrow(jacuzzi::arret);
}
@Test
public void testArretQuandPasAllume() {
Jacuzzi jacuzzi = new Jacuzzi();
assertThrows(IllegalStateException.class, jacuzzi::arret);
}
@Test
public void testAugmenterTemp() {
Jacuzzi jacuzzi = new Jacuzzi();
jacuzzi.setTemperature(30);
jacuzzi.setTemperature(35);
assertEquals(35, jacuzzi.temperature);
}
@Test
public void testBaisserTemp() {
Jacuzzi jacuzzi = new Jacuzzi();
jacuzzi.setTemperature(30);
jacuzzi.setTemperature(25);
assertEquals(25, jacuzzi.temperature);
}
}

@ -0,0 +1,48 @@
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class LampeTest {
@Test
public void testMarche() {
Lampe lampe = new Lampe("Salon");
lampe.marche();
assertEquals(100, lampe.getNiveau());
}
@Test
public void testArret() {
Lampe lampe = new Lampe("Salon");
lampe.marche();
lampe.arret();
assertEquals(0, lampe.getNiveau());
}
@Test
public void testAttenuer() {
Lampe lampe = new Lampe("Salon");
lampe.attenuer(50);
assertEquals(50, lampe.getNiveau());
}
@Test
public void testAttenuerToZero() {
Lampe lampe = new Lampe("Salon");
lampe.attenuer(0);
assertEquals(0, lampe.getNiveau());
}
@Test
public void testAttenuerToZeroAfterOn() {
Lampe lampe = new Lampe("Salon");
lampe.marche();
lampe.attenuer(0);
assertEquals(0, lampe.getNiveau());
}
@Test
public void testGetNiveau() {
Lampe lampe = new Lampe("Salon");
assertEquals(0, lampe.getNiveau());
}
}

@ -0,0 +1,76 @@
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class StereoTest {
@Test
public void testSetCDQuandPasAllume() {
Stereo stereo = new Stereo("Salon");
stereo.arret();
assertThrows(IllegalStateException.class, stereo::setCD);
}
@Test
public void testSetDVDQuandPasAllume() {
Stereo stereo = new Stereo("Salon");
stereo.arret();
assertThrows(IllegalStateException.class, stereo::setDVD);
}
@Test
public void testSetRadioQuandPasAllume() {
Stereo stereo = new Stereo("Salon");
stereo.arret();
assertThrows(IllegalStateException.class, stereo::setRadio);
}
@Test
public void testSetCDQuandAllume() {
Stereo stereo = new Stereo("Salon");
stereo.marche();
assertDoesNotThrow(stereo::setCD);
}
@Test
public void testSetDVDQuandAllume() {
Stereo stereo = new Stereo("Salon");
stereo.marche();
assertDoesNotThrow(stereo::setDVD);
}
@Test
public void testSetRadioQuandAllume() {
Stereo stereo = new Stereo("Salon");
stereo.marche();
assertDoesNotThrow(stereo::setRadio);
}
@Test
public void testSetVolumeQuandAllume() {
Stereo stereo = new Stereo("Salon");
stereo.marche();
assertDoesNotThrow(() -> stereo.setVolume(5));
}
@Test
public void testSetVolumeQuandPasAllume() {
Stereo stereo = new Stereo("Salon");
stereo.arret();
assertThrows(IllegalStateException.class, () -> stereo.setVolume(5));
}
@Test
public void testSetVolumeOutOfRange() {
Stereo stereo = new Stereo("Salon");
stereo.marche();
assertThrows(IllegalArgumentException.class, () -> stereo.setVolume(20));
}
@Test
public void testSetVolume() {
Stereo stereo = new Stereo("Salon");
stereo.marche();
stereo.setVolume(8);
assertEquals(8, stereo.getVolume());
}
}

@ -0,0 +1,24 @@
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class TVTest {
@Test
public void testMarche() {
TV tv = new TV("Salon");
assertDoesNotThrow(tv::marche);
}
@Test
public void testArret() {
TV tv = new TV("Salon");
assertDoesNotThrow(tv::arret);
}
@Test
public void testSelectionnerCanal() {
TV tv = new TV("Salon");
tv.selectionnerCanal();
assertEquals(3, tv.canal);
}
}

@ -0,0 +1,100 @@
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class TelecommandeTest {
@Test
public void testSetCommande() {
Telecommande telecommande = new Telecommande();
Commande commandeMarche = new CommandeAllumerJacuzzi(new Jacuzzi());
Commande commandeArret = new CommandeEteindreJacuzzi(new Jacuzzi());
telecommande.setCommande(0, commandeMarche, commandeArret);
assertEquals(commandeMarche, telecommande.commandesMarche[0]);
assertEquals(commandeArret, telecommande.commandesArret[0]);
}
@Test
public void testBoutonMarchePresse() {
Telecommande telecommande = new Telecommande();
Commande commandeMarche = new CommandeAllumerLampe(new Lampe("Salon"));
Commande commandeArret = new CommandeEteindreLampe(new Lampe("Salon"));
telecommande.setCommande(0, commandeMarche, commandeArret);
telecommande.boutonMarchePresse(0);
assertEquals(commandeMarche, telecommande.commandeAnnulation);
}
@Test
public void testBoutonArretPresse() {
Telecommande telecommande = new Telecommande();
Commande commandeMarche = new CommandeAllumerTV(new TV("Salon"));
Commande commandeArret = new CommandeEteindreTV(new TV("Salon"));
telecommande.setCommande(0, commandeMarche, commandeArret);
telecommande.boutonArretPresse(0);
assertEquals(commandeArret, telecommande.commandeAnnulation);
}
@Test
public void testBoutonAnnulPresse() {
Telecommande telecommande = new Telecommande();
Commande commandeMarche = new CommandeAllumerStereo(new Stereo("Salon"));
Commande commandeArret = new CommandeEteindreStereo(new Stereo("Salon"));
telecommande.setCommande(0, commandeMarche, commandeArret);
telecommande.boutonMarchePresse(0);
telecommande.boutonAnnulPresse();
assertEquals(commandeMarche, telecommande.commandeAnnulation);
}
@Test
public void testMacroCommande() {
Telecommande telecommande = new Telecommande();
Commande commande1 = new CommandeEteindreVentilateur(new Ventilateur("Salon"));
Commande commande2 = new CommandeVentilateurMoyen(new Ventilateur("Salon"));
Commande commande3 = new CommandeVentilateurRapide(new Ventilateur("Salon"));
Commande[] commandes = {commande1, commande2, commande3};
MacroCommande macroCommande = new MacroCommande(commandes);
telecommande.setCommande(0, macroCommande, new PasDeCommande());
telecommande.boutonMarchePresse(0);
assertEquals(commande1, ((MacroCommande) telecommande.commandesMarche[0]).commandes[0]);
assertEquals(commande2, ((MacroCommande) telecommande.commandesMarche[0]).commandes[1]);
assertEquals(commande3, ((MacroCommande) telecommande.commandesMarche[0]).commandes[2]);
}
@Test
public void testSetCommandeStereoCD() {
Telecommande telecommande = new Telecommande();
Commande commandeMarche = new CommandeAllumerStereoAvecCD(new Stereo("Salon"));
Commande commandeArret = new CommandeEteindreStereo(new Stereo("Salon"));
telecommande.setCommande(0, commandeMarche, commandeArret);
assertEquals(commandeMarche, telecommande.commandesMarche[0]);
assertEquals(commandeArret, telecommande.commandesArret[0]);
}
@Test
public void testToString() {
Telecommande telecommande = new Telecommande();
Commande commandeMarche = new CommandeAllumerLampeSejour(new Lampe("Salon"));
Commande commandeArret = new CommandeEteindreLampeSejour(new Lampe("Salon"));
telecommande.setCommande(0, commandeMarche, commandeArret);
String expected = "\n------ Télécommande -------\n" +
"[empt 0] CommandeAllumerLampeSejour CommandeEteindreLampeSejour\n" +
"[empt 1] PasDeCommande PasDeCommande\n" +
"[empt 2] PasDeCommande PasDeCommande\n" +
"[empt 3] PasDeCommande PasDeCommande\n" +
"[empt 4] PasDeCommande PasDeCommande\n" +
"[empt 5] PasDeCommande PasDeCommande\n" +
"[empt 6] PasDeCommande PasDeCommande\n" +
"[annulation] PasDeCommande\n";
assertEquals(expected, telecommande.toString());
}
}

@ -0,0 +1,33 @@
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class VentilateurTest {
@Test
public void testRapide() {
Ventilateur ventilateur = new Ventilateur("Salon");
ventilateur.rapide();
assertEquals(Ventilateur.RAPIDE, ventilateur.getVitesse());
}
@Test
public void testMoyen() {
Ventilateur ventilateur = new Ventilateur("Salon");
ventilateur.moyen();
assertEquals(Ventilateur.MOYEN, ventilateur.getVitesse());
}
@Test
public void testLent() {
Ventilateur ventilateur = new Ventilateur("Salon");
ventilateur.lent();
assertEquals(Ventilateur.LENT, ventilateur.getVitesse());
}
@Test
public void testArreter() {
Ventilateur ventilateur = new Ventilateur("Salon");
ventilateur.arreter();
assertEquals(Ventilateur.ARRET, ventilateur.getVitesse());
}
}

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/corr_telecommande_groupe/models" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/corr_telecommande_groupe/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.8.1">
<CLASSES>
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" />
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" />
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" />
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" />
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" />
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
Loading…
Cancel
Save