6 Commits
dt ... inesV2

Author SHA1 Message Date
ines.benalia
8fa260fd23 test de la classe commande cas 4 2024-09-19 11:56:51 +02:00
ines.benalia
9977862a27 test de la classe commande cas 4 2024-09-19 11:01:21 +02:00
ines.benalia
85ab2c6bec test de la classe commande 2024-09-19 10:44:15 +02:00
sio
45a93f086a mise à jour pour Commande et testCommande 2024-09-19 10:11:37 +02:00
sio
0680043384 test cas1 2024-09-12 11:33:20 +02:00
sio
b02b4b8bcf test cas1 2024-09-12 11:25:21 +02:00
6 changed files with 292 additions and 278 deletions

View File

@@ -1,99 +1,98 @@
annotation.processing.enabled=true annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false annotation.processing.enabled.in.editor=false
annotation.processing.processor.options= annotation.processing.processor.options=
annotation.processing.processors.list= annotation.processing.processors.list=
annotation.processing.run.all.processors=true annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.dir}/classes build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned: # This directory is removed when the project is cleaned:
build.dir=build build.dir=build
build.generated.dir=${build.dir}/generated build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here: # Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport: # Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket #debug.transport=dt_socket
debug.classpath=\ debug.classpath=\
${run.classpath} ${run.classpath}
debug.modulepath=\ debug.modulepath=\
${run.modulepath} ${run.modulepath}
debug.test.classpath=\ debug.test.classpath=\
${run.test.classpath} ${run.test.classpath}
debug.test.modulepath=\ debug.test.modulepath=\
${run.test.modulepath} ${run.test.modulepath}
# Files in build.classes.dir which should be excluded from distribution jar # Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes= dist.archive.excludes=
# This directory is removed when the project is cleaned: # This directory is removed when the project is cleaned:
dist.dir=dist dist.dir=dist
dist.jar=${dist.dir}/MusicAndCo.jar dist.jar=${dist.dir}/MusicAndCo.jar
dist.javadoc.dir=${dist.dir}/javadoc dist.javadoc.dir=${dist.dir}/javadoc
dist.jlink.dir=${dist.dir}/jlink dist.jlink.dir=${dist.dir}/jlink
dist.jlink.output=${dist.jlink.dir}/MusicAndCo dist.jlink.output=${dist.jlink.dir}/MusicAndCo
excludes= excludes=
includes=** includes=**
jar.compress=false jar.compress=false
javac.classpath= javac.classpath=
# Space-separated list of extra javac options # Space-separated list of extra javac options
javac.compilerargs=\ --enable-preview --enable-preview javac.compilerargs=\ --enable-preview --enable-preview
javac.deprecation=false javac.deprecation=false
javac.external.vm=true javac.external.vm=true
javac.modulepath= javac.modulepath=
javac.processormodulepath= javac.processormodulepath=
javac.processorpath=\ javac.processorpath=\
${javac.classpath} ${javac.classpath}
javac.source=21 javac.source=21
javac.target=21 javac.target=21
javac.test.classpath=\ javac.test.classpath=\
${javac.classpath}:\ ${javac.classpath}:\
${build.classes.dir}:\ ${build.classes.dir}:\
${libs.testng.classpath}:\ ${libs.junit_5.classpath}:\
${libs.junit_5.classpath}:\ ${libs.junit_4.classpath}:\
${libs.junit_4.classpath}:\ ${libs.hamcrest.classpath}
${libs.hamcrest.classpath} javac.test.modulepath=\
javac.test.modulepath=\ ${javac.modulepath}
${javac.modulepath} javac.test.processorpath=\
javac.test.processorpath=\ ${javac.test.classpath}
${javac.test.classpath} javadoc.additionalparam=
javadoc.additionalparam= javadoc.author=false
javadoc.author=false javadoc.encoding=${source.encoding}
javadoc.encoding=${source.encoding} javadoc.html5=false
javadoc.html5=false javadoc.noindex=false
javadoc.noindex=false javadoc.nonavbar=false
javadoc.nonavbar=false javadoc.notree=false
javadoc.notree=false javadoc.private=false
javadoc.private=false javadoc.splitindex=true
javadoc.splitindex=true javadoc.use=true
javadoc.use=true javadoc.version=false
javadoc.version=false javadoc.windowtitle=
javadoc.windowtitle= # The jlink additional root modules to resolve
# The jlink additional root modules to resolve jlink.additionalmodules=
jlink.additionalmodules= # The jlink additional command line parameters
# The jlink additional command line parameters jlink.additionalparam=
jlink.additionalparam= jlink.launcher=true
jlink.launcher=true jlink.launcher.name=MusicAndCo
jlink.launcher.name=MusicAndCo main.class=Test
main.class=Test manifest.file=manifest.mf
manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF
meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false
mkdist.disabled=false platform.active=default_platform
platform.active=default_platform run.classpath=\
run.classpath=\ ${javac.classpath}:\
${javac.classpath}:\ ${build.classes.dir}
${build.classes.dir} # Space-separated list of JVM arguments used when running the project.
# Space-separated list of JVM arguments used when running the project. # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. # To set system properties for unit tests define test-sys-prop.name=value:
# To set system properties for unit tests define test-sys-prop.name=value: run.jvmargs=\ --enable-preview
run.jvmargs=\ --enable-preview run.modulepath=\
run.modulepath=\ ${javac.modulepath}
${javac.modulepath} run.test.classpath=\
run.test.classpath=\ ${javac.test.classpath}:\
${javac.test.classpath}:\ ${build.test.classes.dir}
${build.test.classes.dir} run.test.modulepath=\
run.test.modulepath=\ ${javac.test.modulepath}
${javac.test.modulepath} source.encoding=UTF-8
source.encoding=UTF-8 src.dir=src
src.dir=src test.src.dir=test
test.src.dir=test

View File

@@ -19,10 +19,16 @@ public class Test {
*/ */
public static void main(String[] args) { public static void main(String[] args) {
Entreprise lEntreprise=new Entreprise("MusicAndCo"); Entreprise lEntreprise=new Entreprise("MusicAndCo");
Instrument instr1=new Instrument(1,"Piano",10, 8300f);
Instrument instr2=new Instrument(2,"Violon",9, 105f);
Instrument instr3=new Instrument(3,"Guitare",8, 575f);
Commande laCommande = new Commande(1,1,"12/09/2024"); Commande laCommande = new Commande(1,1,"12/09/2024");
lEntreprise.ajouterCommande(laCommande); lEntreprise.ajouterCommande(laCommande);
//ajouter 3 piano droit et 2 violon alto dans la commande //Test Cas0-Ajouter à la commande une ligne de 2 instr1
System.out.println("Résultat de l'ajout de 2 instr1 à la commande :" + laCommande.ajouter(instr1, 2) );
System.out.println("Nouveau stock de instr1 : "+instr1.getQteStock());
System.out.println("Quantité de la ligne de commande de instr1 :"+laCommande.getLesLignes().get(instr1));
} }
} }

View File

@@ -1,123 +1,145 @@
/* /*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/ */
package métiers; package métiers;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** /**
* *
* @author ilona * @author ilona
*/ */
public class Commande { public class Commande {
private int noCom, noVendeur; private int noCom, noVendeur;
private String dateCom; private String dateCom;
private final HashMap<Instrument, Integer> lesLignes = new HashMap<>(); private final HashMap<Instrument, Integer> lesLignes = new HashMap<>();
public Commande(int noCom, int noVendeur, String dateCom) { public Commande(int noCom, int noVendeur, String dateCom) {
this.noCom = noCom; this.noCom = noCom;
this.noVendeur = noVendeur; this.noVendeur = noVendeur;
this.dateCom = dateCom; this.dateCom = dateCom;
} }
/** /**
* Ajoute une quantité donnée d'un instrument à la commande * Ajoute une quantité donnée d'un instrument à la commande
* @param unInstrument instrument à ajouter * @param unInstrument instrument à ajouter
* @param qte quantité à ajouter * @param qte quantité à ajouter
* @return true si l'ajout est bon * @return true si l'ajout est bon
*/ */
public boolean ajouter(Instrument unInstrument, int qte){ public boolean ajouter(Instrument unInstrument, int qte){
//il faut gérer l'ajout d'un instrument existant dans la commande, ce sera une mise à jour de la ligne
//il faut empêcher l'ajout d'une ligne avec une quantité à 0 //il faut empêcher l'ajout d'une ligne avec une quantité à 0
//bien s'assurer que le stock est suffisant //bien s'assurer que le stock est suffisant
boolean ajoutOK; boolean ajoutOK=false;
int qteDisponible = unInstrument.getQteStock(); //ajout d'un instrument existant dans la commande, ce sera une mise à jour de la ligne
if (qteDisponible<qte){ if (lesLignes.containsKey(unInstrument))//l'instrument existe
ajoutOK = false; {
}else { //récupération de la quantité en stock
ajoutOK = true; int oldQte=unInstrument.getQteStock();
lesLignes.put(unInstrument,qte); //réaffectation dans le stock de la quantité commandée
unInstrument.setQteStock(qteDisponible-qte); int qteStock=oldQte+ this.getLesLignes().get(unInstrument);
} unInstrument.setQteStock(qteStock);
return ajoutOK; //suppression ligne commande
} lesLignes.remove(unInstrument);
/** //nouvel ajout
* Supprimer un instrument de la commande this.ajouter(unInstrument,qte);
* @param unInstrument instrument à supprimer
* @return true si la suppression est effectuée }
*/ else //nouvel instrument
public boolean supprimer(Instrument unInstrument){ {
//lesLignes.remove(unInstrument); //on s'assure qu'il y a assez de stock pour la commande
boolean suppOK;
if (lesLignes.containsKey(unInstrument) == true){ int qteDisponible = unInstrument.getQteStock();
suppOK = true; if (qteDisponible<qte){
lesLignes.remove(unInstrument); ajoutOK = false;
} else { }else {
suppOK = false; ajoutOK = true;
} lesLignes.put(unInstrument,qte);
return suppOK; //màj qté stock pour déduire la qté commandée
} unInstrument.setQteStock(qteDisponible-qte);
}
///////////////////////////////////////////////////////////////////////////////// }
public int getNoCom() {
return noCom; return ajoutOK;
} }
/**
public int getNoVendeur() { * Supprimer un instrument de la commande
return noVendeur; * @param unInstrument instrument à supprimer
} * @return true si la suppression est effectuée
*/
public String getDateCom() { public boolean supprimer(Instrument unInstrument){
return dateCom; //lesLignes.remove(unInstrument);
} boolean suppOK;
if (lesLignes.containsKey(unInstrument) == true){
public HashMap<Instrument, Integer> getLesLignes() { suppOK = true;
return lesLignes; lesLignes.remove(unInstrument);
} } else {
suppOK = false;
}
public void setNoCom(int noCom) { return suppOK;
this.noCom = noCom; }
}
/////////////////////////////////////////////////////////////////////////////////
public void setNoVendeur(int noVendeur) {
this.noVendeur = noVendeur; public int getNoCom() {
} return noCom;
}
public void setDateCom(String dateCom) {
this.dateCom = dateCom; public int getNoVendeur() {
} return noVendeur;
}
@Override
public boolean equals(Object obj) { public String getDateCom() {
if (this == obj) { return dateCom;
return true; }
}
if (obj == null) { public HashMap<Instrument, Integer> getLesLignes() {
return false; return lesLignes;
} }
if (getClass() != obj.getClass()) {
return false;
} public void setNoCom(int noCom) {
final Commande other = (Commande) obj; this.noCom = noCom;
if (this.noCom != other.noCom) { }
return false;
} public void setNoVendeur(int noVendeur) {
if (this.noVendeur != other.noVendeur) { this.noVendeur = noVendeur;
return false; }
}
return Objects.equals(this.dateCom, other.dateCom); public void setDateCom(String dateCom) {
} this.dateCom = dateCom;
}
} @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Commande other = (Commande) obj;
if (this.noCom != other.noCom) {
return false;
}
if (this.noVendeur != other.noVendeur) {
return false;
}
return Objects.equals(this.dateCom, other.dateCom);
}
}

View File

@@ -5,8 +5,6 @@
package métiers; package métiers;
import java.util.ArrayList; import java.util.ArrayList;
import métiers.Commande;
import métiers.Instrument;
/** /**
* *
@@ -15,17 +13,10 @@ import métiers.Instrument;
public class Entreprise { public class Entreprise {
private String raisonSociale; private String raisonSociale;
private ArrayList<Commande> lesCommandes = new ArrayList<>(); private ArrayList<Commande> lesCommandes = new ArrayList<>();
private ArrayList<Instrument> lesInstruments = new ArrayList<>();
public Entreprise(String raisonSociale) { public Entreprise(String raisonSociale) {
this.raisonSociale = raisonSociale; this.raisonSociale = raisonSociale;
ArrayList<Instrument> lesInstruments = new ArrayList<>();
Instrument instr1=new Instrument(23,"Piano droit",3, 8300f);
Instrument instr2=new Instrument(54,"Violon Alto",5, 105f);
Instrument instr3=new Instrument(67,"Guitare Classique",8, 575f);
lesInstruments.add(instr3);
lesInstruments.add(instr2);
lesInstruments.add(instr1);
} }
public String getRaisonSociale() { public String getRaisonSociale() {
@@ -47,9 +38,6 @@ public class Entreprise {
} }
public void supprimerCommande(Commande uneCommande){ public void supprimerCommande(Commande uneCommande){
//parcours pour supprimer les instruments de la commande
//suppression de la commande
lesCommandes.remove(uneCommande); lesCommandes.remove(uneCommande);
} }

View File

@@ -29,8 +29,10 @@ public class CommandeTest {
public void testAjouter() { public void testAjouter() {
Instrument instr1=new Instrument(1,"Piano",10, 8300f); Instrument instr1=new Instrument(1,"Piano",10, 8300f);
Instrument instr2=new Instrument(2,"Violon",9, 105f); Instrument instr2=new Instrument(2,"Violon",9, 105f);
Instrument instr3=new Instrument(3,"piano",8, 105f);
Commande laCommande = new Commande(1,1,"12/09/2024"); Commande laCommande = new Commande(1,1,"12/09/2024");
System.out.println("ajouter"); System.out.println("ajouter");
//cas 0
boolean ajoutRes= laCommande.ajouter(instr1, 2); boolean ajoutRes= laCommande.ajouter(instr1, 2);
boolean ajoutAttendu = true; boolean ajoutAttendu = true;
System.out.println("cas0 : cas normal, ajout une ligne de commande"); System.out.println("cas0 : cas normal, ajout une ligne de commande");
@@ -42,45 +44,69 @@ public class CommandeTest {
int qteAttendu=2; int qteAttendu=2;
assertEquals("Test0 quantite",qteRes, qteAttendu); assertEquals("Test0 quantite",qteRes, qteAttendu);
//cas 1
System.out.println("Cas1 : ajout autre ligne de commande"); System.out.println("Cas1 : ajout autre ligne de commande");
laCommande.ajouter(instr2, 6); laCommande.ajouter(instr2, 6);
int tailleR=laCommande.getLesLignes().size(); int tailleR=laCommande.getLesLignes().size();
int tailleAttendue=2; int tailleAttendue=2;
assertEquals("Test1 taille",tailleAttendue,tailleR); assertEquals("Test1 taille",tailleAttendue,tailleR);
//Cas2
System.out.println("Cas2 : màj quantité commandée d'une ligne existante"); System.out.println("Cas2 : màj quantité commandée d'une ligne existante");
laCommande.ajouter(instr2, 5); laCommande.ajouter(instr2, 5);
stockRes=instr2.getQteStock(); stockRes=instr2.getQteStock();
stockAttendu=4; stockAttendu=4;
assertEquals("test2 stock",stockAttendu,stockRes ); assertEquals("test2 stock",stockAttendu,stockRes );
/*qteRes=laCommande.getLesLignes().get(instr2); qteRes=laCommande.getLesLignes().get(instr2);
qteAttendu=5; qteAttendu=5;
assertEquals("Test2 quantite", qteAttendu,qteRes);*/ assertEquals("Test2 quantite", qteAttendu,qteRes);
/*INES*/ /*INES*/
System.out.println("Cas3 : ajout nouvelle ligne avec quantité > stock"); System.out.println("Cas3 : ajout nouvelle ligne avec quantité > stock");
boolean test= laCommande.ajouter(instr3, 12);
stockRes=instr3.getQteStock();
stockAttendu=8;
boolean testResultExpected=false;
assertEquals("test3 stock",stockAttendu,stockRes );
assertEquals("La méthode ajouter retourne false",testResultExpected,test );
System.out.println("Nombre de ligne dans le dictionnaire: "+laCommande.getLesLignes().size());
System.out.println("Résultat de la méthode ajouter: " + test);
/*MAISSANE*/ /*MAISSANE*/
System.out.println("Cas4 : ajout nouvelle ligne avec quantité 0"); System.out.println("Cas4 : ajout nouvelle ligne avec quantité 0");
/*MORGANN*/ /*MORGANN*/
System.out.println("Cas5 : mise à 0 quantité commandée d'une ligne existante"); System.out.println("Cas5 : mise à 0 quantité commandée d'une ligne existante");
/*INES*/ /*ILONA*/
System.out.println("Cas6 : màj d'une ligne existante avec qté>stock"); System.out.println("Cas6 : màj d'une ligne existante avec qté>stock");
} }
/**
* Test of supprimer method, of class Commande.
@Test @Test
public void testSupprimer() { public void testSupprimer() {
System.out.println("supprimer"); //instanciation
Instrument unInstrument = null;
Commande instance = null; Instrument instr1=new Instrument(1,"Piano",10, 8300f);
boolean expResult = false; Instrument instr2=new Instrument(2,"Violon",9, 105f);
boolean result = instance.supprimer(unInstrument); Commande laCommande = new Commande(1,1,"12/09/2024");
assertEquals("test supprimer",expResult, result); laCommande.ajouter(instr1, 2);
// TODO review the generated test code and remove the default call to fail. boolean expectedResult=false;
fail("The test case is a prototype."); boolean expectedResult2=true;
}*/
// test
boolean test= laCommande.supprimer(instr2);
boolean test2= laCommande.supprimer(instr1);
assertEquals("suppression impossible",expectedResult,test);
assertEquals("suppression possible ",test2,expectedResult2 );
System.out.println("Nombre de ligne dans le dictionnaire: "+laCommande.getLesLignes().size());
}
} }

View File

@@ -1,27 +0,0 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="MusicAndCo">
<!--
see examples at http://testng.org/doc/documentation-main.html#testng-xml
<suite-files>
<suite-file path="./junit-suite.xml" />
</suite-files>
<test name="TimeOut">
<classes>
<class name="test.timeout.TimeOutTest" />
<class name="test.timeout.TimeOutFromXmlTest"/>
<class name="test.timeout.TimeOutThreadLocalSampleTest"/>
</classes>
</test>
-->
<test name="métiers suite">
<packages>
<package name="métiers"/>
</packages>
</test>
</suite>