parent
19d0d8ff40
commit
53efbf3c4e
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,26 @@
|
|||||||
|
#CC : le compilateur à utiliser
|
||||||
|
CC=g++
|
||||||
|
|
||||||
|
#CFLAGS : les options de compilation
|
||||||
|
CFLAGS= -std=c++17 -Wall
|
||||||
|
|
||||||
|
# les fichiers sources : tous les fichiers présents dans src/
|
||||||
|
SRC=$(wildcard src/*.cpp)
|
||||||
|
|
||||||
|
# les fichiers objets (.o)
|
||||||
|
OBJ=$(patsubst src/%.cpp,obj/%.o,$(SRC))
|
||||||
|
|
||||||
|
|
||||||
|
#edition des liens : génération de l'exécutable à partir des .o
|
||||||
|
bin/exe: $(OBJ)
|
||||||
|
$(CC) $(OBJ) -o $@
|
||||||
|
|
||||||
|
# génération des .o à partir des .cpp et .hpp crrespondants :
|
||||||
|
obj/%.o: src/%.cpp
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
#nettoyage : destruction des .o et de l'exécutable
|
||||||
|
clean:
|
||||||
|
rm obj/*.o bin/exe
|
||||||
|
|
||||||
|
|
Binary file not shown.
@ -0,0 +1,30 @@
|
|||||||
|
#include "ingredient.hpp"
|
||||||
|
#include "quantite.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace appli {
|
||||||
|
|
||||||
|
Ingredient::Ingredient(const string &aliment, const Quantite &quantite)
|
||||||
|
: aliment{aliment}, quantite{quantite}
|
||||||
|
{}
|
||||||
|
|
||||||
|
string Ingredient::getAliment() const {
|
||||||
|
return aliment;
|
||||||
|
}
|
||||||
|
|
||||||
|
Quantite Ingredient::getQuantite() const {
|
||||||
|
return quantite;
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream &operator<<(ostream &os, const Ingredient &i) {
|
||||||
|
os << i.getQuantite() << " " << i.getAliment() << endl;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const Ingredient &i1, const Ingredient &i2) {
|
||||||
|
return(i1.getAliment() == i2.getAliment());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef INGREDIENT_HPP
|
||||||
|
#define INGREDIENT_HPP
|
||||||
|
|
||||||
|
#include "quantite.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
|
namespace appli {
|
||||||
|
|
||||||
|
class Ingredient {
|
||||||
|
std::string aliment;
|
||||||
|
Quantite quantite;
|
||||||
|
public:
|
||||||
|
Ingredient(const std::string &aliment, const Quantite &quantite);
|
||||||
|
std::string getAliment() const;
|
||||||
|
Quantite getQuantite() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &os, const Ingredient &i);
|
||||||
|
bool operator==(const Ingredient &i1, const Ingredient &i2);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
template <>
|
||||||
|
struct hash<appli::Ingredient> {
|
||||||
|
size_t operator()(const appli::Ingredient &i) const {
|
||||||
|
return hash<string>()(i.getAliment());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //INGREDIENT_HPP
|
@ -0,0 +1,136 @@
|
|||||||
|
#include<iostream>
|
||||||
|
// #include<map>
|
||||||
|
#include<unordered_set>
|
||||||
|
#include"unite.hpp"
|
||||||
|
#include"quantite.hpp"
|
||||||
|
#include"ingredient.hpp"
|
||||||
|
#include"recette.hpp"
|
||||||
|
// #include"recetteAffichage.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void testUnite(){
|
||||||
|
cout << "------------------------------" << endl;
|
||||||
|
cout << " testUnite() " << endl;
|
||||||
|
cout << "------------------------------" << endl;
|
||||||
|
|
||||||
|
cout << "Résultat attendu => résultat" << endl;
|
||||||
|
cout << "kg => " << appli::Unite::KG << endl;
|
||||||
|
cout << "g => " << appli::Unite::G << endl;
|
||||||
|
cout << "mL => " << appli::Unite::ML << endl;
|
||||||
|
cout << "cL => " << appli::Unite::CL << endl;
|
||||||
|
cout << "dL => " << appli::Unite::DL << endl;
|
||||||
|
cout << "L => " << appli::Unite::L << endl;
|
||||||
|
cout << " => " << appli::Unite::UNITE << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testQuantite(){
|
||||||
|
cout << "------------------------------" << endl;
|
||||||
|
cout << " testQuantite() " << endl;
|
||||||
|
cout << "------------------------------" << endl;
|
||||||
|
|
||||||
|
cout << "Résultat attendu => résultat" << endl;
|
||||||
|
cout << "1.0 => " << appli::Quantite{} << endl;
|
||||||
|
cout << "2.5 => " << appli::Quantite{2.5} << endl;
|
||||||
|
cout << "1.5L => " << appli::Quantite{1.5, appli::Unite::L} << endl;
|
||||||
|
|
||||||
|
// Partie 3:
|
||||||
|
// cout << "15L => " << appli::Quantite{15, appli::Unite::L}.normaliser() << endl;
|
||||||
|
// cout << "1.5L => " << appli::Quantite{15, appli::Unite::DL}.normaliser() << endl;
|
||||||
|
// cout << "0.15L => " << appli::Quantite{15, appli::Unite::CL}.normaliser() << endl;
|
||||||
|
// cout << "0.015L => " << appli::Quantite{15, appli::Unite::ML}.normaliser() << endl;
|
||||||
|
// cout << "15L => " << appli::Quantite{15, appli::Unite::L}.normaliser() << endl;
|
||||||
|
// cout << "0.8kg => " << appli::Quantite{0.8, appli::Unite::KG}.normaliser() << endl;
|
||||||
|
// cout << "0.5kg => " << appli::Quantite{500, appli::Unite::G}.normaliser() << endl;
|
||||||
|
// cout << "2 => " << appli::Quantite{2, appli::Unite::UNITE}.normaliser() << endl;
|
||||||
|
|
||||||
|
// cout << "1.5kg => " << appli::Quantite{1, appli::Unite::KG}+appli::Quantite{500, appli::Unite::G} << endl;
|
||||||
|
// cout << "0.75L => " << appli::Quantite{5, appli::Unite::DL}+appli::Quantite{250, appli::Unite::ML} << endl;
|
||||||
|
// cout << "Détection d'erreur ?" << endl;
|
||||||
|
// cout << appli::Quantite{5, appli::Unite::DL}+appli::Quantite{250, appli::Unite::G} << endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void testIngredient(){
|
||||||
|
cout << "------------------------------" << endl;
|
||||||
|
cout << " testIngredient() " << endl;
|
||||||
|
cout << "------------------------------" << endl;
|
||||||
|
|
||||||
|
appli::Ingredient i1{"poireaux", appli::Quantite{2.0, appli::Unite::UNITE}};
|
||||||
|
appli::Ingredient i2{"pommes de terre", appli::Quantite{300, appli::Unite::G}};
|
||||||
|
appli::Ingredient i3{"eau", appli::Quantite{50, appli::Unite::CL}};
|
||||||
|
|
||||||
|
cout << "Résultat attendu => résultat" << endl;
|
||||||
|
cout << "2 poireaux => " << i1 << endl;
|
||||||
|
cout << "300g pommes de terre => " << i2 << endl;
|
||||||
|
cout << "50cL eau => " << i3 << endl;
|
||||||
|
|
||||||
|
// à compléter
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void testRecette(){
|
||||||
|
cout << "------------------------------" << endl;
|
||||||
|
cout << " testRecette() " << endl;
|
||||||
|
cout << "------------------------------" << endl;
|
||||||
|
|
||||||
|
appli::Recette r{"Soupe de poireaux", "Faire cuire les légumes puis mixer."};
|
||||||
|
|
||||||
|
// unordered_set<appli::Ingredient> ing;
|
||||||
|
// ing.insert(appli::Ingredient{"poireaux", appli::Quantite{2, appli::Unite::UNITE}});
|
||||||
|
// ing.insert(appli::Ingredient{"pommes de terre", appli::Quantite{300, appli::Unite::G}});
|
||||||
|
// ing.insert(appli::Ingredient{"eau", appli::Quantite{50, appli::Unite::CL}});
|
||||||
|
|
||||||
|
// cout << "Résultat attendu" << endl << "=>" << endl << "résultat" << endl << endl;
|
||||||
|
// cout << "Soupe de poireaux\n\t300g pommes de terre\n\t50cL eau\n\t2 poireaux" << endl << "=>" << endl;
|
||||||
|
// afficherNomEtIngredients(r, ing);
|
||||||
|
|
||||||
|
// cout << endl;
|
||||||
|
// cout << "Soupe de poireaux\n\t300g pommes de terre\n\t50cL eau\n\t2 poireaux\ndescription :\nFaire cuire les légumes puis mixer." << endl << "=>" << endl;
|
||||||
|
// afficherTout(r, ing);
|
||||||
|
|
||||||
|
// appli::Recette r2{"Crêpes", "Faire fondre le beurre. Mélanger la farine, le sel et le sucre. Y ajouter les oeufs puis le lait et enfin le beurre fondu. Faire cuire à la poêle quelques minutes de chaque côté."};
|
||||||
|
|
||||||
|
// unordered_set<appli::Ingredient> ing2;
|
||||||
|
// ing2.insert(appli::Ingredient{"farine", appli::Quantite{250, appli::Unite::G}});
|
||||||
|
// ing2.insert(appli::Ingredient{"lait", appli::Quantite{0.5, appli::Unite::L}});
|
||||||
|
// ing2.insert(appli::Ingredient{"sucre", appli::Quantite{30, appli::Unite::G}});
|
||||||
|
// ing2.insert(appli::Ingredient{"oeufs", appli::Quantite{4, appli::Unite::UNITE}});
|
||||||
|
// ing2.insert(appli::Ingredient{"sel", appli::Quantite{3, appli::Unite::G}});
|
||||||
|
// ing2.insert(appli::Ingredient{"beurre", appli::Quantite{50, appli::Unite::G}});
|
||||||
|
|
||||||
|
// map<appli::Recette, unordered_set<appli::Ingredient>> recettes;
|
||||||
|
// recettes.insert(pair{r,ing});
|
||||||
|
// recettes.insert(pair{r2,ing2});
|
||||||
|
|
||||||
|
// cout << endl;
|
||||||
|
// cout << "Crêpes\n\t50g beurre\n\t3g sel\n\t4 oeufs\n\t30g sucre\n\t0.5L lait\n\t250g farine\ndescription :\nFaire fondre le beurre. Mélanger la farine, le sel et le sucre. Y ajouter les oeufs puis le lait et enfin le beurre fondu. Faire cuire à la poêle quelques minutes de chaque côté.\nSoupe de poireaux\n\t300g pommes de terre\n\t50cL eau\n\t2 poireaux\ndescription :\nFaire cuire les légumes puis mixer." << endl << "=>" << endl;
|
||||||
|
// afficherTout(recettes);
|
||||||
|
|
||||||
|
|
||||||
|
// cout << endl;
|
||||||
|
// cout << "Crêpes\nSoupe de poireaux" << endl << "=>" << endl;
|
||||||
|
// afficherNoms(recettes);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void testLivreRecettes(){
|
||||||
|
cout << "------------------------------" << endl;
|
||||||
|
cout << " testLivreRecettes() " << endl;
|
||||||
|
cout << "------------------------------" << endl;
|
||||||
|
|
||||||
|
//à compléter
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
// testUnite();
|
||||||
|
// testQuantite();
|
||||||
|
// testIngredient();
|
||||||
|
testRecette();
|
||||||
|
// testLivreRecettes();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
#include "quantite.hpp"
|
||||||
|
#include "unite.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace appli {
|
||||||
|
|
||||||
|
Quantite::Quantite(double nombre, const Unite &unite)
|
||||||
|
: nombre{nombre}, unite{unite}
|
||||||
|
{}
|
||||||
|
|
||||||
|
double Quantite::getNombre() const {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
Unite Quantite::getUnite() const {
|
||||||
|
return unite;
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream &operator<<(ostream &os, const Quantite &q) {
|
||||||
|
os << q.getNombre() << q.getUnite();
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef QUANTITE_HPP
|
||||||
|
#define QUANTITE_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "unite.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace appli {
|
||||||
|
|
||||||
|
class Quantite {
|
||||||
|
double nombre;
|
||||||
|
Unite unite;
|
||||||
|
public:
|
||||||
|
Quantite(double nombre=1, const Unite &unite=Unite::UNITE);
|
||||||
|
double getNombre() const;
|
||||||
|
Unite getUnite() const;
|
||||||
|
Quantite normalier();
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &os, const Quantite &q);
|
||||||
|
// double operator+(const double &n1, const )
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // QUANTITE_HPP
|
@ -0,0 +1,24 @@
|
|||||||
|
#include "recette.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace appli {
|
||||||
|
|
||||||
|
Recette::Recette(const string &nom, const string &description)
|
||||||
|
: nom{nom}, description{description}
|
||||||
|
{}
|
||||||
|
|
||||||
|
string Recette::getNom() const {
|
||||||
|
return nom;
|
||||||
|
}
|
||||||
|
|
||||||
|
string Recette::getDescription() const {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream &operator<<(ostream &os, const Recette &r) {
|
||||||
|
os << r.getNom() << " " << r.getDescription();
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef RECETTE_HPP
|
||||||
|
#define RECETTE_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "ingredient.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace appli {
|
||||||
|
|
||||||
|
class Recette {
|
||||||
|
std::string nom;
|
||||||
|
std::string description;
|
||||||
|
public:
|
||||||
|
Recette(const std::string &nom, const std::string &description);
|
||||||
|
std::string getNom() const;
|
||||||
|
std::string getDescription() const;
|
||||||
|
};
|
||||||
|
// "operateur prends deux qqt, si q1 == q2 en unité alors on peut construire un nouvelle quantite avec l'unité de q1 ou q2
|
||||||
|
// on regarde ce que retourne q1 et q2 normalisé pas d'ajout de kg et litre et donc mettre un message d'erreur en cerr et on return q1"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif //RECETTE_HPP
|
@ -0,0 +1,25 @@
|
|||||||
|
#include "unite.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
namespace appli {
|
||||||
|
ostream &operator<<(ostream &os, const Unite &u) {
|
||||||
|
switch(u) {
|
||||||
|
case Unite::KG : os << "kg";
|
||||||
|
break;
|
||||||
|
case Unite::G : os << "g";
|
||||||
|
break;
|
||||||
|
case Unite::L : os << "L";
|
||||||
|
break;
|
||||||
|
case Unite::DL : os << "dL";
|
||||||
|
break;
|
||||||
|
case Unite::CL : os << "cL";
|
||||||
|
break;
|
||||||
|
case Unite::ML : os << "mL";
|
||||||
|
break;
|
||||||
|
case Unite::UNITE : os << "";
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef UNITE_HPP
|
||||||
|
#define UNITE_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace appli {
|
||||||
|
enum class Unite{KG, G, L, DL, CL, ML, UNITE};
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &os, const Unite &u);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // UNITE_HPP
|
Binary file not shown.
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef AUREVOIR_HPP
|
||||||
|
#define AUREVOIR_HPP
|
||||||
|
|
||||||
|
class urevoir {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef BONJOUR_HPP
|
||||||
|
#define BONJOUR_HPP
|
||||||
|
|
||||||
|
class onjour {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef NICE_HPP
|
||||||
|
#define NICE_HPP
|
||||||
|
|
||||||
|
class ice {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef AUREVOIR_HPP
|
||||||
|
#define AUREVOIR_HPP
|
||||||
|
|
||||||
|
class urevoir {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef BONJOUR_HPP
|
||||||
|
#define BONJOUR_HPP
|
||||||
|
|
||||||
|
class onjour {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
#ifndef AUREVOIR_HPP
|
||||||
|
#define AUREVOIR_HPP
|
||||||
|
|
||||||
|
class -n A
|
||||||
|
urevoir {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
#ifndef BONJOUR_HPP
|
||||||
|
#define BONJOUR_HPP
|
||||||
|
|
||||||
|
class -n B
|
||||||
|
onjour {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
#ifndef BONJOUR_HPP
|
||||||
|
#define BONJOUR_HPP
|
||||||
|
|
||||||
|
class -n B
|
||||||
|
-n onjour {
|
||||||
|
|
||||||
|
}
|
@ -1,8 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="DiscordProjectSettings">
|
|
||||||
<option name="show" value="ASK" />
|
|
||||||
<option name="description" value="" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,18 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
||||||
<component name="MakefileSettings">
|
|
||||||
<option name="linkedExternalProjectsSettings">
|
|
||||||
<MakefileProjectSettings>
|
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
|
||||||
<option name="modules">
|
|
||||||
<set>
|
|
||||||
<option value="$PROJECT_DIR$" />
|
|
||||||
</set>
|
|
||||||
</option>
|
|
||||||
<option name="version" value="2" />
|
|
||||||
</MakefileProjectSettings>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
<component name="MakefileWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
|
||||||
</project>
|
|
@ -1,67 +0,0 @@
|
|||||||
{
|
|
||||||
"files.associations": {
|
|
||||||
"__bit_reference": "cpp",
|
|
||||||
"__config": "cpp",
|
|
||||||
"__debug": "cpp",
|
|
||||||
"__errc": "cpp",
|
|
||||||
"__functional_base": "cpp",
|
|
||||||
"__hash_table": "cpp",
|
|
||||||
"__locale": "cpp",
|
|
||||||
"__mutex_base": "cpp",
|
|
||||||
"__node_handle": "cpp",
|
|
||||||
"__nullptr": "cpp",
|
|
||||||
"__split_buffer": "cpp",
|
|
||||||
"__string": "cpp",
|
|
||||||
"__threading_support": "cpp",
|
|
||||||
"__tuple": "cpp",
|
|
||||||
"algorithm": "cpp",
|
|
||||||
"array": "cpp",
|
|
||||||
"atomic": "cpp",
|
|
||||||
"bit": "cpp",
|
|
||||||
"bitset": "cpp",
|
|
||||||
"cctype": "cpp",
|
|
||||||
"chrono": "cpp",
|
|
||||||
"clocale": "cpp",
|
|
||||||
"cmath": "cpp",
|
|
||||||
"complex": "cpp",
|
|
||||||
"cstdarg": "cpp",
|
|
||||||
"cstddef": "cpp",
|
|
||||||
"cstdint": "cpp",
|
|
||||||
"cstdio": "cpp",
|
|
||||||
"cstdlib": "cpp",
|
|
||||||
"cstring": "cpp",
|
|
||||||
"ctime": "cpp",
|
|
||||||
"cwchar": "cpp",
|
|
||||||
"cwctype": "cpp",
|
|
||||||
"exception": "cpp",
|
|
||||||
"functional": "cpp",
|
|
||||||
"initializer_list": "cpp",
|
|
||||||
"iomanip": "cpp",
|
|
||||||
"ios": "cpp",
|
|
||||||
"iosfwd": "cpp",
|
|
||||||
"iostream": "cpp",
|
|
||||||
"istream": "cpp",
|
|
||||||
"iterator": "cpp",
|
|
||||||
"limits": "cpp",
|
|
||||||
"list": "cpp",
|
|
||||||
"locale": "cpp",
|
|
||||||
"memory": "cpp",
|
|
||||||
"mutex": "cpp",
|
|
||||||
"new": "cpp",
|
|
||||||
"optional": "cpp",
|
|
||||||
"ostream": "cpp",
|
|
||||||
"ratio": "cpp",
|
|
||||||
"sstream": "cpp",
|
|
||||||
"stdexcept": "cpp",
|
|
||||||
"streambuf": "cpp",
|
|
||||||
"string": "cpp",
|
|
||||||
"string_view": "cpp",
|
|
||||||
"system_error": "cpp",
|
|
||||||
"tuple": "cpp",
|
|
||||||
"type_traits": "cpp",
|
|
||||||
"typeinfo": "cpp",
|
|
||||||
"unordered_map": "cpp",
|
|
||||||
"utility": "cpp",
|
|
||||||
"vector": "cpp"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
cc=g++ -std=c++17 -g -Wall -Werror -pedantic
|
|
||||||
|
|
||||||
all: tp
|
|
||||||
|
|
||||||
obj/Wagon.o: src/Wagon.cpp src/Wagon.h src/Passager.h
|
|
||||||
$(cc) -c src/Wagon.cpp -o obj/Wagon.o
|
|
||||||
obj/Passager.o: src/Passager.cpp src/Passager.h
|
|
||||||
$(cc) -c src/Passager.cpp -o obj/Passager.o
|
|
||||||
obj/main.o: src/main.cpp src/Train.h src/Wagon.h src/Passager.h \
|
|
||||||
src/TrainExceptions.h
|
|
||||||
$(cc) -c src/main.cpp -o obj/main.o
|
|
||||||
obj/Train.o: src/Train.cpp src/Train.h src/Wagon.h src/Passager.h \
|
|
||||||
src/TrainExceptions.h
|
|
||||||
$(cc) -c src/Train.cpp -o obj/Train.o
|
|
||||||
|
|
||||||
tp: obj/Wagon.o obj/Passager.o obj/main.o obj/Train.o
|
|
||||||
$(cc) obj/Wagon.o obj/Passager.o obj/main.o obj/Train.o -o tp
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -Rf obj/* tp
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,17 +0,0 @@
|
|||||||
#include "Passager.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
Passager::Passager(std::string nom, std::string prenom)
|
|
||||||
: nom{std::move(nom)}, prenom{std::move(prenom)} {}
|
|
||||||
|
|
||||||
/*Passager& Passager::operator=(const Passager& o) {
|
|
||||||
if (o == *this) return *this;
|
|
||||||
nom = o.bom;
|
|
||||||
prenom = o.nom;
|
|
||||||
return *this;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Passager& passager) {
|
|
||||||
return os << passager.nom << " " << passager.prenom;
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class Passager {
|
|
||||||
private:
|
|
||||||
std::string nom;
|
|
||||||
std::string prenom;
|
|
||||||
public:
|
|
||||||
friend std::ostream& operator<<(std::ostream& os, const Passager& passagers);
|
|
||||||
Passager() = default;
|
|
||||||
Passager(std::string nom, std::string prenom);
|
|
||||||
Passager& operator=(const Passager& o) = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Passager& passager);
|
|
||||||
|
|
@ -1,137 +0,0 @@
|
|||||||
#include "Train.h"
|
|
||||||
|
|
||||||
#include "TrainExceptions.h"
|
|
||||||
|
|
||||||
// Si des passagers peuvent être à deux endroits à la fois, il va potentiellement falloir le faire descendre deux fois du train.
|
|
||||||
#define UBIQUITE
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
Train::Train(int nbWagons)
|
|
||||||
: lesWagons{} {
|
|
||||||
for (int i = 1; i <= nbWagons; ++i) {
|
|
||||||
lesWagons.emplace_back(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Train::Train(std::initializer_list<int> listeNumerosWagons)
|
|
||||||
: lesWagons{} {
|
|
||||||
//lesWagons.reserve(listeNumerosWagons.size());
|
|
||||||
for (int numWagon : listeNumerosWagons) {
|
|
||||||
//lesWagons.push_back(new Wagon{numWagon});
|
|
||||||
lesWagons.emplace_back(numWagon);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Train::demarrer() {
|
|
||||||
roule = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Train::arreter() {
|
|
||||||
roule = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Train::isRoule() const {
|
|
||||||
return roule;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Train::monterDansLeTrain(int numeroWagon, const Passager& passager) {
|
|
||||||
if (roule) {
|
|
||||||
throw RouleException{};
|
|
||||||
}
|
|
||||||
// -> map
|
|
||||||
for (Wagon& wagon : lesWagons) {
|
|
||||||
if (wagon.getNumero() == numeroWagon) {
|
|
||||||
if (!wagon.ajouter(passager)) {
|
|
||||||
throw WagonPleinException{};
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw WagonInexistantException{};
|
|
||||||
}
|
|
||||||
|
|
||||||
void Train::descendreDuTrain(const Passager& passager) {
|
|
||||||
if (roule) {
|
|
||||||
throw RouleException{};
|
|
||||||
}
|
|
||||||
#ifdef UBIQUITE
|
|
||||||
bool descendu = false;
|
|
||||||
for (Wagon& wagon : lesWagons) {
|
|
||||||
descendu |= wagon.enlever(passager);
|
|
||||||
}
|
|
||||||
if (!descendu) {
|
|
||||||
throw PassagerException{};
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
for (Wagon& wagon : lesWagons) {
|
|
||||||
if (wagon.enlever(passager)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw PassagerException{};
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void Train::deplacerAuWagonSuivant(const Passager& passager) {
|
|
||||||
if (roule) {
|
|
||||||
throw RouleException{};
|
|
||||||
}
|
|
||||||
vector<Wagon>::iterator it = lesWagons.begin();
|
|
||||||
while (it != lesWagons.end() && !it->enlever(passager)) {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
if (it == lesWagons.end()) {
|
|
||||||
throw PassagerException{};
|
|
||||||
}
|
|
||||||
++it;
|
|
||||||
if (it == lesWagons.end()) {
|
|
||||||
throw BoutDuTrainException{};
|
|
||||||
}
|
|
||||||
if (it->estPlein()) {
|
|
||||||
throw WagonPleinException{};
|
|
||||||
}
|
|
||||||
it->ajouter(passager);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Train::deplacerAuWagonPrecedent(const Passager& passager) {
|
|
||||||
if (roule) {
|
|
||||||
throw RouleException{};
|
|
||||||
}
|
|
||||||
vector<Wagon>::reverse_iterator it = lesWagons.rbegin();
|
|
||||||
while (it != lesWagons.rend() && !it->enlever(passager)) {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
if (it == lesWagons.rend()) {
|
|
||||||
throw PassagerException{};
|
|
||||||
}
|
|
||||||
++it;
|
|
||||||
if (it == lesWagons.rend()) {
|
|
||||||
throw BoutDuTrainException{};
|
|
||||||
}
|
|
||||||
if (it->estPlein()) {
|
|
||||||
throw WagonPleinException{};
|
|
||||||
}
|
|
||||||
it->ajouter(passager);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Train::monterDansLeTrainAPartirDe(int numeroWagon, const Passager& passager) {
|
|
||||||
if (roule) {
|
|
||||||
throw RouleException{};
|
|
||||||
}
|
|
||||||
vector<Wagon>::iterator it = lesWagons.begin();
|
|
||||||
while (it != lesWagons.end() && it->getNumero() != numeroWagon) {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
if (it == lesWagons.end()) {
|
|
||||||
throw WagonInexistantException{};
|
|
||||||
}
|
|
||||||
while (it != lesWagons.end() && it->estPlein()) {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
if (it == lesWagons.end()) {
|
|
||||||
throw BoutDuTrainException{};
|
|
||||||
}
|
|
||||||
it->ajouter(passager);
|
|
||||||
return it->getNumero();
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
#include <initializer_list>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "Wagon.h"
|
|
||||||
|
|
||||||
class Train {
|
|
||||||
private:
|
|
||||||
std::vector<Wagon> lesWagons;
|
|
||||||
bool roule{};
|
|
||||||
public:
|
|
||||||
explicit Train(int nbWagons);
|
|
||||||
Train(std::initializer_list<int> listeNumerosWagons);
|
|
||||||
void demarrer();
|
|
||||||
void arreter();
|
|
||||||
bool isRoule() const;
|
|
||||||
void monterDansLeTrain(int numeroWagon, const Passager& passager);
|
|
||||||
int monterDansLeTrainAPartirDe(int numeroWagon, const Passager& passager);
|
|
||||||
void descendreDuTrain(const Passager& passager);
|
|
||||||
void deplacerAuWagonPrecedent(const Passager& passager);
|
|
||||||
void deplacerAuWagonSuivant(const Passager& passager);
|
|
||||||
};
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
|||||||
#ifndef TRAIN_EXCEPTIONS_HPP
|
|
||||||
#define TRAIN_EXCEPTIONS_HPP
|
|
||||||
|
|
||||||
class RouleException {};
|
|
||||||
class WagonInexistantException {};
|
|
||||||
class WagonPleinException {};
|
|
||||||
class PassagerException {};
|
|
||||||
class BoutDuTrainException {};
|
|
||||||
|
|
||||||
#endif // TRAIN_EXCEPTIONS_HPP
|
|
@ -1,48 +0,0 @@
|
|||||||
#include "Wagon.h"
|
|
||||||
|
|
||||||
Wagon::Wagon(int numero) : numero{numero}, lesPassagers{} {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int Wagon::getNumero() const {
|
|
||||||
return numero;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Wagon::estPlein() const {
|
|
||||||
return lesPassagers.size() >= capacite;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Wagon::ajouter(const Passager& passager) {
|
|
||||||
if (lesPassagers.size() >= capacite) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
lesPassagers.push_front(&passager);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Wagon::enlever(const Passager& passager) {
|
|
||||||
std::list<const Passager*>::size_type previous = lesPassagers.size();
|
|
||||||
lesPassagers.remove(&passager);
|
|
||||||
return previous != lesPassagers.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
int Wagon::debarquer(int nbPassager) {
|
|
||||||
int c = nbPassager;
|
|
||||||
while (!lesPassagers.empty() && c > 0) {
|
|
||||||
lesPassagers.pop_back();
|
|
||||||
--c;
|
|
||||||
}
|
|
||||||
return nbPassager - c;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Wagon& wagon) {
|
|
||||||
if (wagon.lesPassagers.empty()) {
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
std::list<const Passager*>::const_iterator it = wagon.lesPassagers.cbegin();
|
|
||||||
os << **it;
|
|
||||||
while (++it != wagon.lesPassagers.cend()) {
|
|
||||||
os << ", " << **it;
|
|
||||||
}
|
|
||||||
return os;
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
#include <list>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "Passager.h"
|
|
||||||
|
|
||||||
class Wagon {
|
|
||||||
private:
|
|
||||||
constexpr static int capacite = 20;
|
|
||||||
int numero;
|
|
||||||
std::list<const Passager*> lesPassagers;
|
|
||||||
public:
|
|
||||||
friend std::ostream& operator<<(std::ostream& os, const Wagon& wagon);
|
|
||||||
explicit Wagon(int numero);
|
|
||||||
int getNumero() const;
|
|
||||||
bool estPlein() const;
|
|
||||||
bool ajouter(const Passager& passager);
|
|
||||||
bool enlever(const Passager& passager);
|
|
||||||
int debarquer(int nbPassager);
|
|
||||||
};
|
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Wagon& wagon);
|
|
@ -1,355 +0,0 @@
|
|||||||
#include "Train.h"
|
|
||||||
#include "TrainExceptions.h"
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using Gens = std::array<Passager, 20>;
|
|
||||||
|
|
||||||
void testsWagon() {
|
|
||||||
Passager pierre("Dupont", "Pierre");
|
|
||||||
Passager paul("Durand", "Paul");
|
|
||||||
|
|
||||||
cout << "Vérif si wagon gère correctement son numero... ";
|
|
||||||
Wagon wagon{42};
|
|
||||||
cout << (wagon.getNumero() == 42 ? "OK\n" : "ERREUR\n");
|
|
||||||
|
|
||||||
cout << "Vérif si possible de faire monter 20 personnes dans un wagon... ";
|
|
||||||
Gens gens;
|
|
||||||
for (Gens::size_type i{0}; i < gens.size(); ++i)
|
|
||||||
gens[i] = Passager{"Personne " + to_string(i + 1), "Autogénérée"};
|
|
||||||
|
|
||||||
bool ajoutOK{true};
|
|
||||||
for (const Passager &personne : gens) {
|
|
||||||
ajoutOK = ajoutOK && wagon.ajouter(personne);
|
|
||||||
}
|
|
||||||
cout << (ajoutOK ? "OK\n" : "ERREUR\n");
|
|
||||||
//cout << wagon << "\n";
|
|
||||||
|
|
||||||
cout << "Vérif si impossible de faire monter 1 personne dans un wagon "
|
|
||||||
"plein... ";
|
|
||||||
cout << (wagon.ajouter(pierre) ? "ERREUR\n" : "OK\n");
|
|
||||||
|
|
||||||
cout << "Vérif si possible de faire debarquer 14 personnes sur 20... ";
|
|
||||||
cout << (wagon.debarquer(14) == 14 ? "OK\n" : "ERREUR\n");
|
|
||||||
// cout << wagon;
|
|
||||||
|
|
||||||
cout << "Vérif si possible de faire debarquer les 6 passagers restants... ";
|
|
||||||
cout << (wagon.debarquer(20) == 6 ? "OK\n" : "ERREUR\n");
|
|
||||||
// cout << wagon;
|
|
||||||
|
|
||||||
cout << "Vérif si possible de faire debarquer 1 passager donné... ";
|
|
||||||
wagon.ajouter(pierre);
|
|
||||||
cout << (wagon.enlever(pierre) ? "OK\n" : "ERREUR\n");
|
|
||||||
|
|
||||||
cout << "Vérif si impossible de faire debarquer 1 passager pas dans le "
|
|
||||||
"wagon... ";
|
|
||||||
cout << (wagon.enlever(paul) ? "ERREUR\n" : "OK\n");
|
|
||||||
|
|
||||||
cout << "Vérif si impossible de faire debarquer 1 passager d'un wagon "
|
|
||||||
"vide... ";
|
|
||||||
cout << (wagon.enlever(pierre) ? "ERREUR\n" : "OK\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void testMonterDansTrain() {
|
|
||||||
Passager pierre{"Dupont", "Pierre"};
|
|
||||||
Train train(3);
|
|
||||||
|
|
||||||
cout << "Vérif si impossible de monter dans un train qui roule... ";
|
|
||||||
train.demarrer();
|
|
||||||
try {
|
|
||||||
train.monterDansLeTrain(1, pierre);
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
} catch (const RouleException &) {
|
|
||||||
cout << " OK\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Vérif si impossible de monter si numéro de wagon non existant... ";
|
|
||||||
train.arreter();
|
|
||||||
try {
|
|
||||||
train.monterDansLeTrain(4, pierre);
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
} catch (const WagonInexistantException &) {
|
|
||||||
cout << "OK\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Vérif si possible de faire monter 20 personnes dans un wagon "
|
|
||||||
"existant, non complet et train arrêté... ";
|
|
||||||
Gens gens;
|
|
||||||
for (Gens::size_type i{0}; i < gens.size(); ++i)
|
|
||||||
gens[i] = Passager{"Personne " + to_string(i + 1), "Autogénérée"};
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (const Passager &personne : gens) {
|
|
||||||
train.monterDansLeTrain(1, personne);
|
|
||||||
}
|
|
||||||
cout << "OK\n";
|
|
||||||
} catch (...) {
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Vérif si impossible de monter dans le wagon si déjà complet... ";
|
|
||||||
try {
|
|
||||||
train.monterDansLeTrain(1, pierre);
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
} catch (const WagonPleinException &) {
|
|
||||||
cout << "OK\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void testDescendreDuTrain() {
|
|
||||||
Passager pierre("Dupont", "Pierre");
|
|
||||||
Passager paul("Durand", "Paul");
|
|
||||||
Train train(3);
|
|
||||||
|
|
||||||
// cout << "Pierre monte dans le wagon 1\n";
|
|
||||||
train.monterDansLeTrain(1, pierre);
|
|
||||||
|
|
||||||
cout << "Vérif si impossible de descendre du train qui roule... ";
|
|
||||||
train.demarrer();
|
|
||||||
try {
|
|
||||||
train.descendreDuTrain(pierre);
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
} catch (const RouleException &) {
|
|
||||||
cout << " OK\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// cout << "Paul n'est pas dans le train\n";
|
|
||||||
cout << "Vérif si impossible de descendre du train sans s'y trouver... ";
|
|
||||||
train.arreter();
|
|
||||||
try {
|
|
||||||
train.descendreDuTrain(paul);
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
} catch (const PassagerException &) {
|
|
||||||
cout << "OK\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Vérif si possible de descendre du wagon existant et train "
|
|
||||||
"arrêté... ";
|
|
||||||
try {
|
|
||||||
train.descendreDuTrain(pierre);
|
|
||||||
cout << " OK\n";
|
|
||||||
} catch (...) {
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void testDeplacerAuWagonSuivant() {
|
|
||||||
Passager alice("Dups", "Alice");
|
|
||||||
Passager pierre("Dupont", "Pierre");
|
|
||||||
Passager paul("Durand", "Paul");
|
|
||||||
Passager marie("Dumont", "Marie");
|
|
||||||
Train train(3);
|
|
||||||
|
|
||||||
// cout << "Pierre monte dans le premier wagon (1)\n";
|
|
||||||
train.monterDansLeTrain(1, pierre);
|
|
||||||
// cout << "Paul monte dans le wagon 2\n";
|
|
||||||
train.monterDansLeTrain(2, paul);
|
|
||||||
// cout << "Marie monte dans le dernier wagon (3)\n";
|
|
||||||
train.monterDansLeTrain(3, marie);
|
|
||||||
// cout << "Alice n'est pas dans le train\n";
|
|
||||||
|
|
||||||
cout << "Vérif si impossible de déplacer un passager qui n'est pas dans le "
|
|
||||||
"train... ";
|
|
||||||
try {
|
|
||||||
train.deplacerAuWagonSuivant(alice);
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
} catch (const PassagerException &) {
|
|
||||||
cout << " OK\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Vérif si impossible de passer au wagon suivant car déjà dans le "
|
|
||||||
"dernier wagon... ";
|
|
||||||
try {
|
|
||||||
train.deplacerAuWagonSuivant(marie);
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
} catch (const BoutDuTrainException &) {
|
|
||||||
cout << " OK\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
Gens gens;
|
|
||||||
for (Gens::size_type i{0}; i < gens.size() - 1; ++i)
|
|
||||||
gens[i] = Passager{"Personne " + to_string(i + 1), "Autogénérée"};
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (const Passager &personne : gens)
|
|
||||||
train.monterDansLeTrain(3, personne);
|
|
||||||
} catch (...) {
|
|
||||||
cout << "ERREUR le wagon 3 devrait pouvoir contenir 20 passagers !\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Vérif si impossible de passer au wagon suivant car wagon déjà "
|
|
||||||
"complet... ";
|
|
||||||
try {
|
|
||||||
train.deplacerAuWagonSuivant(paul);
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
} catch (const WagonPleinException &) {
|
|
||||||
cout << "OK\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Vérif si possible de passer au wagon suivant (bonnes "
|
|
||||||
"conditions)... ";
|
|
||||||
try {
|
|
||||||
train.deplacerAuWagonSuivant(pierre);
|
|
||||||
cout << "OK\n";
|
|
||||||
} catch (...) {
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void testDeplacerAuWagonPrecedent() {
|
|
||||||
Passager alice("Dups", "Alice");
|
|
||||||
Passager pierre("Dupont", "Pierre");
|
|
||||||
Passager paul("Durand", "Paul");
|
|
||||||
Passager marie("Dumont", "Marie");
|
|
||||||
Train train(3);
|
|
||||||
|
|
||||||
// cout << "Pierre monte dans le premier wagon (1)\n";
|
|
||||||
train.monterDansLeTrain(1, pierre);
|
|
||||||
// cout << "Paul monte dans le wagon 2\n";
|
|
||||||
train.monterDansLeTrain(2, paul);
|
|
||||||
// cout << "Marie monte dans le dernier wagon (3)\n";
|
|
||||||
train.monterDansLeTrain(3, marie);
|
|
||||||
// cout << "Alice n'est pas dans le train\n";
|
|
||||||
|
|
||||||
cout << "Vérif si impossible de déplacer au wagon précédent un passager "
|
|
||||||
"qui n'est pas dans le train... ";
|
|
||||||
try {
|
|
||||||
train.deplacerAuWagonPrecedent(alice);
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
} catch (const PassagerException &) {
|
|
||||||
cout << " OK\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Vérif si impossible de passer au wagon précédent car déjà dans le "
|
|
||||||
"premier wagon... ";
|
|
||||||
try {
|
|
||||||
train.deplacerAuWagonPrecedent(pierre);
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
} catch (const BoutDuTrainException &) {
|
|
||||||
cout << " OK\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
Gens gens;
|
|
||||||
for (Gens::size_type i{0}; i < gens.size() - 1; ++i)
|
|
||||||
gens[i] = Passager{"Personne " + to_string(i + 1), "Autogénérée"};
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (const Passager &personne : gens)
|
|
||||||
train.monterDansLeTrain(1, personne);
|
|
||||||
} catch (...) {
|
|
||||||
cout << "ERREUR le wagon 1 devrait pouvoir contenir 20 passagers !\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Vérif si impossible de passer au wagon précédent car wagon déjà "
|
|
||||||
"complet... ";
|
|
||||||
try {
|
|
||||||
train.deplacerAuWagonPrecedent(paul);
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
} catch (const WagonPleinException &) {
|
|
||||||
cout << "OK\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Vérif si possible de passer au wagon précédent (bonnes "
|
|
||||||
"conditions)... ";
|
|
||||||
try {
|
|
||||||
train.deplacerAuWagonPrecedent(marie);
|
|
||||||
cout << "OK\n";
|
|
||||||
} catch (...) {
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void testMonterDansLeTrainAPartirDe() {
|
|
||||||
Passager pierre("Dupont", "Pierre");
|
|
||||||
Train train(3);
|
|
||||||
|
|
||||||
cout << "Vérif si impossible de monter à partir d'un numero de wagon non "
|
|
||||||
"existant... ";
|
|
||||||
try {
|
|
||||||
train.monterDansLeTrainAPartirDe(4, pierre);
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
} catch (const WagonInexistantException &) {
|
|
||||||
cout << "OK\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
train.demarrer();
|
|
||||||
cout << "Vérif si impossible de monter dans un train qui roule... ";
|
|
||||||
try {
|
|
||||||
train.monterDansLeTrainAPartirDe(1, pierre);
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
} catch (const RouleException &) {
|
|
||||||
cout << "OK\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
train.arreter();
|
|
||||||
Gens gens;
|
|
||||||
for (Gens::size_type i{0}; i < gens.size() - 1; ++i)
|
|
||||||
gens[i] = Passager{"Personne " + to_string(i + 1), "Autogénérée"};
|
|
||||||
|
|
||||||
// On remplit tous les wagons (on triche un peu)
|
|
||||||
// Magie de l'informatique, on donne le don d'ubiquité aux gens
|
|
||||||
try {
|
|
||||||
for (const Passager &personne : gens) {
|
|
||||||
train.monterDansLeTrain(1, personne);
|
|
||||||
train.monterDansLeTrain(2, personne);
|
|
||||||
train.monterDansLeTrain(3, personne);
|
|
||||||
}
|
|
||||||
} catch (...) {
|
|
||||||
cout << "ERREUR on devrait pouvoir remplir le train !\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Vérif si impossible de monter dans un train complet... ";
|
|
||||||
try {
|
|
||||||
train.monterDansLeTrainAPartirDe(1, pierre);
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
} catch (const BoutDuTrainException &) {
|
|
||||||
cout << "OK\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (const Passager &personne : gens) {
|
|
||||||
train.descendreDuTrain(personne);
|
|
||||||
}
|
|
||||||
} catch (...) {
|
|
||||||
cout << "ERREUR on devrait pouvoir vider le premier wagon !\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Vérif si on peut monter dans un train où il y a de la place... ";
|
|
||||||
try {
|
|
||||||
int pos = train.monterDansLeTrainAPartirDe(2, pierre);
|
|
||||||
cout << "OK, " << pierre << " est monté dans le wagon " << pos << "\n";
|
|
||||||
} catch (...) {
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Vérif si le passager peut descendre... ";
|
|
||||||
try {
|
|
||||||
train.descendreDuTrain(pierre);
|
|
||||||
cout << "OK\n";
|
|
||||||
} catch (...) {
|
|
||||||
cout << "ERREUR\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
cout << "---------- TESTS WAGONS ------------\n";
|
|
||||||
testsWagon();
|
|
||||||
|
|
||||||
cout << "---------- TEST MONTER DANS LE TRAIN ------------\n";
|
|
||||||
testMonterDansTrain();
|
|
||||||
|
|
||||||
cout << "---------- TEST DESCENDRE DU TRAIN ------------\n";
|
|
||||||
testDescendreDuTrain();
|
|
||||||
|
|
||||||
cout << "---------- TEST DEPLACER AU WAGON SUIVANT ------------\n";
|
|
||||||
testDeplacerAuWagonSuivant();
|
|
||||||
|
|
||||||
cout << "---------- TEST DEPLACER AU WAGON PRECEDENT ------------\n";
|
|
||||||
testDeplacerAuWagonPrecedent();
|
|
||||||
|
|
||||||
cout << "---------- TEST MONTER DANS LE TRAIN A PARTIR DE "
|
|
||||||
"------------\n";
|
|
||||||
testMonterDansLeTrainAPartirDe();
|
|
||||||
}
|
|
Binary file not shown.
Loading…
Reference in new issue