39 Commits

Author SHA1 Message Date
Rochas
88f90f0936 correction bug + ajout de test 2024-12-20 21:23:13 +01:00
Rochas
c62f1e1be1 Read me + 2 nouveaux tests dans la v1 2024-12-20 18:50:45 +01:00
Rochas Thibaut
ead826fd2e Add README.md 2024-12-20 17:12:17 +00:00
Rochas
e44b45c35d remove old test + add new Property in Interior 2024-12-20 18:08:59 +01:00
Rochas
7774db2254 pas grand choses 2024-12-20 14:23:54 +01:00
Rochas
617ee582dc ajout dans isValid de la vérification que les Property sont valid + HtmlRenerator terminé 2024-12-20 14:12:24 +01:00
Minh VU
f2c0645f60 add comments 2024-12-20 13:18:36 +01:00
Rochas
d9d979b1e8 ajout du début de l'implémentation de HtmlGenerator 2024-12-20 11:57:24 +01:00
Rochas
42dce975ad ajout de prix pour les Part 2024-12-20 11:00:53 +01:00
Rochas
6c60549cfe correction de BeforeEach avec Junit5 2024-12-20 00:02:43 +01:00
Rochas
a680ed5cd6 warning en moins 2024-12-19 22:00:36 +01:00
Rochas
e43ecc8cfe BeforeEach partout 2024-12-19 21:59:45 +01:00
Rochas
090a609651 passage de Junit4 à Junit5 (my bad) pour avoir BeforeEach 2024-12-19 21:58:38 +01:00
Rochas
27eedecd8c BIG CHANGEMENT, correction de la configuration, nouveau test) 2024-12-19 21:32:03 +01:00
trochas
69e9f01cdd test bugé 2024-12-04 18:13:51 +01:00
Minh VU
3c7d910ab3 ok 2024-12-04 17:11:13 +01:00
Minh VU
e82c50c90a contruscteur 2024-12-04 17:07:05 +01:00
trochas
6bc6fc678e export en trop supprimé 2024-12-04 18:02:38 +01:00
Minh VU
af60294517 ok 2024-12-04 17:00:31 +01:00
Minh VU
c2d6d245b4 Merge branch 'dev_v2' of https://gitlab2.istic.univ-rennes1.fr/tuvu/cartailor into dev_v2 2024-12-04 16:56:40 +01:00
trochas
93c1fab4de ajustement des prix 2024-12-04 17:49:12 +01:00
trochas
5e27042193 import inutile retiré 2024-12-04 17:47:02 +01:00
trochas
503d24f140 ajustement des prix 2024-12-04 17:46:11 +01:00
trochas
f9c6059067 correction get et set de Property 2024-12-04 17:18:27 +01:00
trochas
e68e2771ed test property color Exteriror 2024-12-04 17:08:47 +01:00
trochas
e1a5373c90 Proterty color Interior + prix pour les Part 2024-12-04 17:04:18 +01:00
Minh VU
6ca58a33f6 getprixtotal pour config 2024-12-04 16:50:28 +01:00
trochas
d9e14bdd9f addProperty dans engine 2024-11-25 17:45:18 +01:00
trochas
76e14bf7e0 test V1 2024-11-25 17:13:03 +01:00
trochas
955fd7006a initialisation des tests 2024-11-25 16:41:28 +01:00
trochas
f62ca87ef3 correction impl des Parts (engine, Exterio ,...) 2024-11-25 15:20:15 +01:00
trochas
e6994a62b9 correction de selectPart, pour remplacer si une Part de la même catégorie est déjà présente 2024-11-20 08:31:05 +01:00
Minh VU
cc920bf6b6 add parts 2024-11-20 07:03:18 +01:00
Minh VU
9188d50741 Merge branch 'dev_v2' of https://gitlab.istic.univ-rennes1.fr/trochas/cartailor into dev_v2 2024-11-13 18:17:29 +01:00
Minh VU
c17f0352c8 fix all bug 2024-11-13 18:15:02 +01:00
Minh VU
4d85b9e036 fix all bug 2024-11-13 18:14:44 +01:00
trochas
61cdc3c766 correction test 2024-11-13 10:50:43 +01:00
Minh VU
91e25fb88d errors 2024-11-11 17:46:42 +01:00
0b33ac703d test v2 2024-10-25 23:35:28 +02:00
29 changed files with 1011 additions and 187 deletions

10
.gitignore vendored Normal file
View File

@@ -0,0 +1,10 @@
# bloop and metals
.bloop
.bsp
.metals
project/metals.sbt
# vs code
.vscode
.idea

31
.idea/workspace.xml generated
View File

@@ -5,15 +5,11 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="12bd6c53-8ba7-454c-a61e-7a76cc3b801b" name="Changes" comment=""> <list default="true" id="12bd6c53-8ba7-454c-a61e-7a76cc3b801b" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/cartailor.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/fr/impl/CategoryImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/impl/CategoryImpl.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/fr/impl/PartImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/impl/PartImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/fr/impl/CompatibilityManagerImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/impl/CompatibilityManagerImpl.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/fr/impl/Parts/Engine.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/impl/Parts/Engine.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/fr/impl/ConfigurationImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/impl/ConfigurationImpl.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/fr/impl/Parts/Interior.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/impl/Parts/Interior.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/fr/impl/ConfiguratorImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/impl/ConfiguratorImpl.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/fr/test/test.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/test/test.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/fr/impl/PartTypeImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/impl/PartTypeImpl.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -46,7 +42,7 @@
"keyToString": { "keyToString": {
"RunOnceActivity.ShowReadmeOnStart": "true", "RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true", "SHARE_PROJECT_CONFIGURATION_FILES": "true",
"git-widget-placeholder": "dev__v1", "git-widget-placeholder": "Merging dev__v2",
"ignore.virus.scanning.warn.message": "true", "ignore.virus.scanning.warn.message": "true",
"kotlin-language-version-configured": "true", "kotlin-language-version-configured": "true",
"last_opened_file_path": "C:/Users/vumin/Desktop/M1/ALO/cartailor", "last_opened_file_path": "C:/Users/vumin/Desktop/M1/ALO/cartailor",
@@ -68,21 +64,6 @@
<recent name="C:\Users\vumin\Desktop\M1\ALO\cartailor" /> <recent name="C:\Users\vumin\Desktop\M1\ALO\cartailor" />
</key> </key>
</component> </component>
<component name="RunManager">
<configuration default="true" type="JetRunConfigurationType">
<module name="cartailor" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration default="true" type="KotlinStandaloneScriptRunConfigurationType">
<module name="cartailor" />
<option name="filePath" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
<component name="SharedIndexes"> <component name="SharedIndexes">
<attachedChunks> <attachedChunks>
<set> <set>
@@ -105,6 +86,8 @@
<workItem from="1729743145740" duration="122000" /> <workItem from="1729743145740" duration="122000" />
<workItem from="1729757559608" duration="166000" /> <workItem from="1729757559608" duration="166000" />
<workItem from="1729764402753" duration="206000" /> <workItem from="1729764402753" duration="206000" />
<workItem from="1731196687641" duration="82000" />
<workItem from="1733327767478" duration="184000" />
</task> </task>
<servers /> <servers />
</component> </component>

View File

@@ -1,5 +0,0 @@
{
"files.watcherExclude": {
"**/target": true
}
}

View File

@@ -1,8 +1,19 @@
V1: V2:
test_V1 : il s'agit des mêmes tests de la V1, les seuls changements sont sur l'initialisation.
test_V2 : Nous testons les nouvelles fonctionnalités de la V2 (Property, prix, HTML).
Property :
On teste si on a bien les propriétés par défaut quand on ne set aucune Propertry.
Si on change la valeur d'une Property avec une valeur présence dans possibleValues de la Property, le changement a bien été pris en compte et que la configuration est toujours validée.
On teste si en mettant une valeur random, elle est bien prise en compte mais que la configuration n'est plus validé.
Prix :
On regarde si, à partir d'une configuration, on a bien accès au prix d'une Part
On vérifie que le prix total de la Configuration valide, est correct, qu'elle soit complète ou non (-1 si non validée)
Qu'une configuration vide a bien un prix de 0
HTML :
On teste avec différentes configurations (complètes ou non, validées ou non) que la génération de l'HTML ne plante pas
Nous testons d'abord le CompatibilityManager. On fait un BeforeEach pour initialiser un CompatibilityManager (celui vu en TD)
On teste si les Incompatibilities et Requirements sont bien récupérables à partir du CompatibilityManager avec les fonctions getIncompatibilities et getRequirements. GetIncompatibilities et getRequirements doivent donner toutes les Part incompatibles ou Require, même si elles n'ont pas été données directement à la Part testée. On doit donc aussi vérifier la contradiction : A a besoin de B mais B est incompatible avec A, alors A est incompatible avec lui-même.
On teste aussi la configuration, en vérifiant si une configuration est complète et si elle est validée (dans notre implémentation V1, une configuration validée est forcément complète, mais pas forcément l'inverse).
nous ne savons pas pourquoi mais dans notre projet les tests avec couverture ne fonctionnent pas, les tets sont bien testé, mais il tourne dans le vide et ne donne jamais le résultat de la couverture... nous ne savons pas pourquoi mais dans notre projet les tests avec couverture ne fonctionnent pas, les tets sont bien testé, mais il tourne dans le vide et ne donne jamais le résultat de la couverture...

Binary file not shown.

13
V2/snippet API V2.txt Normal file
View File

@@ -0,0 +1,13 @@
/*
* Changes to the V1 API
*/
public Set<Part> getSelectedParts();
public Optional<Part> getSelectionForCategory(Category category);
and for Part.java :
public interface Part extends PropertyManager {
default String getName() {
return this.getClass().getTypeName();
};
Category getCategory();
PartType getType();
}

View File

@@ -0,0 +1,60 @@
/*
* Snippet to add a basic implementation of PropertyManager
*/
public class PartImpl implements Part {
private PartType type;
private class Property {
public final Supplier<String> getter;
public final Consumer<String> setter;
public final Set<String> possibleValues;
Property(Supplier<String> getter, Consumer<String> setter, Set<String> possibleValues) {
this.getter = getter;
this.setter = setter;
this.possibleValues = possibleValues;
}
}
private Map<String, Property> properties = new HashMap<>();
protected void addProperty(String name, Supplier<String> getter, Consumer<String> setter,
Set<String> possibleValues) {
properties.put(name, new Property(getter, setter, possibleValues));
}
@Override
public Set<String> getPropertyNames() {
return Collections.unmodifiableSet(properties.keySet());
}
@Override
public Optional<String> getProperty(String propertyName) {
Objects.requireNonNull(propertyName);
if (properties.containsKey(propertyName)) {
return Optional.of(properties.get(propertyName).getter.get());
}
return Optional.empty();
}
@Override
public void setProperty(String propertyName, String propertyValue) {
Objects.requireNonNull(propertyName);
Objects.requireNonNull(propertyValue);
if ((properties.containsKey(propertyName)) && (properties.get(propertyName).setter != null)) {
properties.get(propertyName).setter.accept(propertyValue);
} else {
throw new IllegalArgumentException("bad property name or value: " + propertyName);
}
}
@Override
public Set<String> getAvailablePropertyValues(String propertyName) {
if (properties.containsKey(propertyName)) {
return Collections.unmodifiableSet(properties.get(propertyName).possibleValues);
}
return Collections.emptySet();
}

View File

@@ -0,0 +1,24 @@
/*
* Snippet to add to your PartTypeImpl to support
* the V2 API
*/
public class PartTypeImpl implements PartType {
private String name;
private Class<? extends PartImpl> classRef;
private Category category;
public PartTypeImpl(String name, Class<? extends PartImpl> classRef, Category category) {
this.name = name;
this.classRef = classRef;
this.category = category;
}
public PartImpl newInstance() {
Constructor<? extends PartImpl> constructor;
try {
constructor = classRef.getConstructor();
return constructor.newInstance();
} catch (Exception e) {
Logger.getGlobal().log(Level.SEVERE, "constructor call failed", e);
System.exit(-1);
}
return null;
}

27
cartailor.html Normal file
View File

@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<title>Cartailor</title>
<style>
table{border-collapse: collapse;}
th,td{border: 1px solid rgb(160 160 160);padding: 8px 10px;}</style>
</head>
<body>
<table>
<tr>
<th>Engine</th>
<th>EG210</th>
<th>25000 €</th>
</tr>
<tr>
<th>Transmission</th>
<th>TSF7</th>
<th>15000 €</th>
</tr>
<tr>
<th colspan="2">Total Price : </th>
<th>40000 € </th>
</tr>
</table>
</body>
</html>

View File

@@ -5,10 +5,5 @@ package src.fr.api;
* A public type to organize part types in categories * A public type to organize part types in categories
*/ */
public interface Category { public interface Category {
/*
* return the name of the cathegory
* @return String, name of the cathegory, non null
*/
String getName(); String getName();
} }

View File

@@ -1,18 +1,6 @@
package src.fr.api; package src.fr.api;
import java.util.Set; import java.util.Set;
public interface CompatibilityChecker { public interface CompatibilityChecker {
/*
* return the list of the incompatibles PartType of a PartType
* @param reference : the PartType that we want to see the incompatibilities,non null
* @return the Set list of the incompatibles PartType
*/
Set<PartType> getIncompatibilities(PartType reference); Set<PartType> getIncompatibilities(PartType reference);
/*
* return the list of the requirements PartType of a PartType
* @param reference : the PartType that we want to see the requirements,non null
* @return the Set list of the requirements PartType
*/
Set<PartType> getRequirements(PartType reference); Set<PartType> getRequirements(PartType reference);
} }

View File

@@ -1,34 +1,8 @@
package src.fr.api; package src.fr.api;
import java.util.Set; import java.util.Set;
public interface CompatibilityManager extends CompatibilityChecker { public interface CompatibilityManager extends CompatibilityChecker {
/*
* add a incompatibles PartType to a PartType
* @param reference : the PartType that we wish to add incompatibilities
* @param target : Set list of incompatibilities PartType to add
*/
void addIncompatibilities(PartType reference,Set<PartType> target); void addIncompatibilities(PartType reference,Set<PartType> target);
/*
* remove a PartType of the incompatibilities of a PartType, warning,
* warning : we must also remove the incompatibility from all the other PartTypes which the @param reference in their incompatibility
* @param reference : the PartType that we wish to remove a incompatible PartType
* @param target : PartType to remove of incompatibility
*/
void removeIncompatibility(PartType reference, PartType target); void removeIncompatibility(PartType reference, PartType target);
/*
* add requirements PartType to a PartType
* @param reference : the PartType that we wish to add requirements
* @param target : Set list of requirement PartType to add
*/
void addRequirements(PartType reference, Set<PartType> target); void addRequirements(PartType reference, Set<PartType> target);
/*
* remove a PartType of the incompatibilities of a PartType
* @param reference : the PartType that we wish to remove a requirement PartType
* @param target : PartType to remove of requirement
*/
void removeRequirement(PartType reference, PartType target); void removeRequirement(PartType reference, PartType target);
} }

View File

@@ -1,8 +1,8 @@
package src.fr.api; package src.fr.api;
import java.util.Set; import java.util.Set;
import java.util.Optional;
public interface Configuration { public interface Configuration {
/* /*
* @return true if there is no compatibility issue between PartType else false * @return true if there is no compatibility issue between PartType else false
*/ */
@@ -14,9 +14,16 @@ public interface Configuration {
boolean isComplete(); boolean isComplete();
/* /*
* @return the list of the PartType in the configuration * @return the list of the Part in the configuration
*/ */
Set<PartType> getSelectedParts(); public Set<Part> getSelectedParts();
/*
* @return the Part that we chose earlier which has Category we choose
* it is optional
* @param catgeory : Category that we want to know about the PartType can be null
*/
public Optional<Part> getSelectionForCategory(Category category);
/* /*
* Select a PartType to add to the configuration * Select a PartType to add to the configuration
@@ -24,12 +31,6 @@ public interface Configuration {
*/ */
void selectPart(PartType chosenPart); void selectPart(PartType chosenPart);
/*
* @return the PartType that we chose earlier which has Category we choose
* @param catgeory : Category that we want to know about the PartType can be null
*/
PartType getSelectionForCategory(Category category);
/* /*
* DeSelect PartType has Catgerory catgoryToClear to delete from the configuration * DeSelect PartType has Catgerory catgoryToClear to delete from the configuration
* @param categoryToClear : the PartType has categoryToClear Category * @param categoryToClear : the PartType has categoryToClear Category

8
src/fr/api/Part.java Normal file
View File

@@ -0,0 +1,8 @@
package src.fr.api;
public interface Part extends PropertyManager {
default String getName() {
return this.getClass().getTypeName();
};
Category getCategory();
PartType getType();
}

View File

@@ -0,0 +1,42 @@
package src.fr.api;
import java.util.Set;
import java.util.Optional;
public interface PropertyManager {
/**
* Returns an immutable set of the property names supported by the property manager.
*
* @return
*/
public Set<String> getPropertyNames();
/**
* Returns the immutable set of discrete string values for a given property.
* For properties that have a non explicit set of possible values (eg double converted to strings),
* or for a non existing property name, returns an empty set.
*
* @param propertyName a non-null string reference
* @return an immutable set (see above)
*/
public Set<String> getAvailablePropertyValues(String propertyName);
/**
* Returns the optional value of a property.
* If the object does not support that property then an empty optional is returned.
* @param propertyName the property to read
* @return
*/
public Optional<String> getProperty(String propertyName);
/**
* Sets the value of a given property.
* If there is not such property, or if it not writable, or if the value is invalid
* then an IllegalArgumentException is thrown.
* @param propertyName
* @param propertyValue
* @throws IllegalArgumentException (see above)
*/
void setProperty(String propertyName, String propertyValue);
}

View File

@@ -1,4 +1,5 @@
package src.fr.impl; package src.fr.impl;
import src.fr.api.Category; import src.fr.api.Category;
public class CategoryImpl implements Category { public class CategoryImpl implements Category {

View File

@@ -2,11 +2,12 @@ package src.fr.impl;
import java.util.Set; import java.util.Set;
import src.fr.api.PartType; import src.fr.api.PartType;
import src.fr.api.CompatibilityManager;
import src.fr.api.CompatibilityChecker; import src.fr.api.CompatibilityChecker;
import src.fr.api.CompatibilityManager;
public class CompatibilityCheckerImpl implements CompatibilityChecker { public class CompatibilityCheckerImpl implements CompatibilityChecker {
private CompatibilityManager compatibilityManager; private CompatibilityManager compatibilityManager;
public CompatibilityCheckerImpl( CompatibilityManager compatibilityManager){ public CompatibilityCheckerImpl( CompatibilityManager compatibilityManager){
@@ -22,4 +23,7 @@ public class CompatibilityCheckerImpl implements CompatibilityChecker {
public Set<PartType> getRequirements(PartType reference) { public Set<PartType> getRequirements(PartType reference) {
return this.compatibilityManager.getRequirements(reference); return this.compatibilityManager.getRequirements(reference);
} }
} }

View File

@@ -1,8 +1,8 @@
package src.fr.impl; package src.fr.impl;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Objects; import java.util.Objects;
import src.fr.api.PartType; import src.fr.api.PartType;
@@ -42,7 +42,6 @@ public class CompatibilityManagerImpl implements CompatibilityManager {
//Ajout ref à x //Ajout ref à x
incompa.add(x); incompa.add(x);
System.out.println("Add "+reference.getName() +" incompatible with "+x.getName()); System.out.println("Add "+reference.getName() +" incompatible with "+x.getName());
this.incompatibilities.put(reference, incompa); this.incompatibilities.put(reference, incompa);
// Symétrie // Symétrie
//Ajoute x à ref //Ajoute x à ref
@@ -191,7 +190,7 @@ public class CompatibilityManagerImpl implements CompatibilityManager {
} }
} }
System.out.println("size = " + result.size());
return result; return result;
} }
@@ -200,7 +199,6 @@ public class CompatibilityManagerImpl implements CompatibilityManager {
public Set<PartType> getRequirements(PartType reference) { public Set<PartType> getRequirements(PartType reference) {
Set<PartType> result = new HashSet<>(); Set<PartType> result = new HashSet<>();
Femeture_Transivite(reference, result,new HashSet<>(),reference); Femeture_Transivite(reference, result,new HashSet<>(),reference);
System.out.println("size = " + result.size());
return result; return result;
} }
} }

View File

@@ -4,12 +4,14 @@ import src.fr.api.Category;
import src.fr.api.PartType; import src.fr.api.PartType;
import src.fr.api.CompatibilityManager; import src.fr.api.CompatibilityManager;
import src.fr.api.Configuration; import src.fr.api.Configuration;
import src.fr.api.Part;
import java.util.HashSet; import java.util.HashSet;
import java.util.Optional;
import java.util.Set; import java.util.Set;
public class ConfigurationImpl implements Configuration { public class ConfigurationImpl implements Configuration {
private Set<PartType> selectedParts = new HashSet<PartType> (); private Set<Part> selectedParts = new HashSet<Part> ();
private CompatibilityManager compatibilityManager; private CompatibilityManager compatibilityManager;
private static int NB_CATEGORY = 4; private static int NB_CATEGORY = 4;
@@ -19,27 +21,69 @@ public class ConfigurationImpl implements Configuration {
@Override @Override
public boolean isValid() { public boolean isValid() {
if (this.isComplete()){ boolean test = true;
for(PartType pt: selectedParts){ for(Part pt1: selectedParts){
System.out.println(pt.getName()); for(String pr: pt1.getPropertyNames()){
Optional<String> prOptional = pt1.getProperty(pr);
if(!prOptional.isEmpty()){
test = test && ((PartImpl)pt1).isValidProperty(pr);
}
else test = false;
}
boolean test_Requirement = true;
boolean test_Incompabilities = true;
System.out.println("name : " + pt1.getType().getName());
//Verifier Requirements //Verifier Requirements
for(PartType require : compatibilityManager.getRequirements(pt)){ for(PartType require : compatibilityManager.getRequirements(pt1.getType())){
System.out.println("\t"+require.getName()); test_Requirement = false;
if(!selectedParts.contains(require)) return false; System.out.println("\tRequirement : " + require.getName());
//if(!selectedParts.contains(require)) return false;
//IN V2, instead of verify if it's in selectedParts,
//we will compare its type and selectedParts
//boolean no_error = true;
for(Part pt2 : selectedParts){
System.out.println("\t\tname : " + pt2.getType().getName());
if (pt2.getType().equals(require)){
test_Requirement = true;
//no_error= true;
break;
} }
}
}
if(test_Requirement) System.out.println("\tok");
else System.out.println("\tnot ok");
//Verifier Incompabilities //Verifier Incompabilities
for(PartType incompa : compatibilityManager.getIncompatibilities(pt)){ for(PartType incompa : compatibilityManager.getIncompatibilities(pt1.getType())){
System.out.println("\t"+incompa.getName()); System.out.println("\tIncompatibility : " + incompa.getName());
if(selectedParts.contains(incompa)) return false; for (Part selectPart : selectedParts){
if(selectPart.getType().equals(incompa)){
test_Incompabilities = false;
break;
} }
} }
return true;
}else{
return false;
} }
if(test_Incompabilities) System.out.println("\tok");
else System.out.println("\tnot ok");
System.out.println(test_Requirement + " " + test_Incompabilities);
test = test && test_Requirement && test_Incompabilities;
System.out.println("post final : " + test);
}
System.out.println("final : " + test);
return test;
} }
public int getTotalPrice(){
int prix_final=0;
if(this.isValid()){
for(Part pt: selectedParts){
prix_final+=((PartImpl)pt).getPrice();
}
return prix_final;
}else{
return -1;
}
}
@Override @Override
public boolean isComplete() { public boolean isComplete() {
@@ -50,38 +94,40 @@ public class ConfigurationImpl implements Configuration {
} }
@Override @Override
public Set<PartType> getSelectedParts() { public Set<Part> getSelectedParts() {
return selectedParts; return selectedParts;
} }
@Override @Override
public void selectPart(PartType chosenPart) { public void selectPart(PartType chosenPart) {
Category cat_chosenPart = chosenPart.getCategory(); Category category_chosenPart = chosenPart.getCategory();
//Vérifier s'il y a des pièces dans la même catégorie, si oui return //Vérifier s'il y a des pièces dans la même catégorie, si oui return
for( PartType pt: selectedParts){ for(Part pt: selectedParts){
if(pt.getCategory().equals(cat_chosenPart)){ if(pt.getCategory().equals(category_chosenPart)){
System.out.println("Il y a une pièce dans la même catégorie dans la configuration"); System.out.println("Il y a une pièce dans la même catégorie dans la configuration");
selectedParts.remove(pt); selectedParts.remove(pt);
break; break;
} }
} }
selectedParts.add(chosenPart); PartImpl newPart = ((PartTypeImpl)chosenPart).newInstance();
newPart.setType(chosenPart);
selectedParts.add(newPart);
//System.out.println(chosenPart.getName() + " : size = " + selectedParts.size());
} }
@Override @Override
public PartType getSelectionForCategory(Category category) { public Optional<Part> getSelectionForCategory(Category category) {
for( PartType pt: selectedParts){ for( Part pt: selectedParts){
if(pt.getCategory().equals(category)){ if(pt.getCategory().equals(category)){
return pt; return Optional.of(pt);
} }
} }
return null; return Optional.empty();
} }
@Override @Override
public void unselectPartType(Category categoryToClear) { public void unselectPartType(Category categoryToClear) {
for( PartType pt: selectedParts){ for( Part pt: selectedParts){
if(pt.getCategory().equals(categoryToClear)){ if(pt.getCategory().equals(categoryToClear)){
selectedParts.remove(pt); selectedParts.remove(pt);
} }
@@ -94,4 +140,15 @@ public class ConfigurationImpl implements Configuration {
public void clear() { public void clear() {
this.selectedParts.clear();; this.selectedParts.clear();;
} }
public Part getPart(Category part){
Part engine = null;
for( Part pt: selectedParts){
if(pt.getCategory() == part){
engine = pt;
break;
}
}
return engine;
}
} }

View File

@@ -3,8 +3,8 @@ package src.fr.impl;
import src.fr.api.Category; import src.fr.api.Category;
import src.fr.api.CompatibilityChecker; import src.fr.api.CompatibilityChecker;
import src.fr.api.Configuration; import src.fr.api.Configuration;
import src.fr.api.PartType;
import src.fr.api.Configurator; import src.fr.api.Configurator;
import src.fr.api.PartType;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;

View File

@@ -0,0 +1,69 @@
package src.fr.impl;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Optional;
import src.fr.api.Part;
public class HtmlGenerator {
static final String HEADER = "<!DOCTYPE html><html><head><title>Cartailor</title><style></style></head>\n";
static private String generateStringHTML(ConfigurationImpl config){
String header ="<!DOCTYPE html>\n<html>\n<head>\n<title>Cartailor</title>\n";
header += "<style>\n";
header += "table{border-collapse: collapse;}\n";
header +="th,td{border: 1px solid rgb(160 160 160);padding: 8px 10px;}";
header += "</style>\n";
header += "</head>\n";
String body = "<body>\n";
body += "\t<table>\n";
for(Part pt: config.getSelectedParts()){
body += "\t\t<tr>\n";
body+= "\t\t\t<th>" + pt.getType().getCategory().getName() + "</th>\n";
body+= "\t\t\t<th>" + pt.getType().getName() + "</th>\n";
body+= "\t\t\t<th>" + ((PartImpl)pt).getPrice() + " €</th>\n";
for(String pr: pt.getPropertyNames()){
Optional<String> prOptional = pt.getProperty(pr);
if(!prOptional.isEmpty()){
body+= "\t\t\t<th>" + pr + " : " + prOptional.get() + "</th>\n";
}
}
body += "\t\t</tr>\n";
}
body += "\t\t<tr>\n";
body += "\t\t\t<th colspan=\"2\">Total Price : </th>\n";
body += "\t\t\t<th>" + config.getTotalPrice() + " € </th>\n";
body += "\t\t</tr>\n";
body += "\t</table>\n";
body += "</body>\n";
return header + body + "</html>";
}
static public void generateHTML(ConfigurationImpl config) throws IOException{
if(config.isValid()){
String content = generateStringHTML(config);
String projectRoot = System.getProperty("user.dir");
File file = new File(projectRoot, "cartailor.html");
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
writer.write(content);
}
System.out.println(projectRoot+"\\cartailor.html");
}
}
}

101
src/fr/impl/PartImpl.java Normal file
View File

@@ -0,0 +1,101 @@
package src.fr.impl;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;
import src.fr.api.Part;
import src.fr.api.Category;
import src.fr.api.PartType;
public class PartImpl implements Part {
protected PartType type;
protected int price;
/*public PartImpl(PartType type){
this.type = type;
}*/
private class Property {
public final Supplier<String> getter;
public final Consumer<String> setter;
public final Set<String> possibleValues;
Property(Supplier<String> getter, Consumer<String> setter, Set<String> possibleValues) {
this.getter = getter;
this.setter = setter;
this.possibleValues = possibleValues;
}
}
private Map<String, Property> properties = new HashMap<>();
protected void addProperty(String name, Supplier<String> getter, Consumer<String> setter, Set<String> possibleValues) {
properties.put(name, new Property(getter, setter, possibleValues));
}
@Override
public Set<String> getPropertyNames() {
return Collections.unmodifiableSet(properties.keySet());
}
@Override
public Optional<String> getProperty(String propertyName) {
Objects.requireNonNull(propertyName);
if (properties.containsKey(propertyName)) {
String value = properties.get(propertyName).getter.get();
if(value != null){
return Optional.of(value);
}
}
return Optional.empty();
}
@Override
public void setProperty(String propertyName, String propertyValue) {
Objects.requireNonNull(propertyName);
Objects.requireNonNull(propertyValue);
if ((properties.containsKey(propertyName)) && (properties.get(propertyName).setter != null)) {
properties.get(propertyName).setter.accept(propertyValue);
} else {
throw new IllegalArgumentException("bad property name or value: " + propertyName);
}
}
@Override
public Set<String> getAvailablePropertyValues(String propertyName) {
if (properties.containsKey(propertyName)) {
return Collections.unmodifiableSet(properties.get(propertyName).possibleValues);
}
return Collections.emptySet();
}
public Category getCategory(){
return this.type.getCategory();
}
public PartType getType(){
return this.type;
}
public void setType(PartType type){
this.type = type;
}
public int getPrice(){
return this.price;
}
public boolean isValidProperty(String propertyName){
return this.properties.get(propertyName).possibleValues.contains(this.properties.get(propertyName).getter.get());
}
}

View File

@@ -1,17 +1,35 @@
package src.fr.impl; package src.fr.impl;
import java.lang.reflect.Constructor;
import java.util.logging.Level;
import java.util.logging.Logger;
import src.fr.api.Category; import src.fr.api.Category;
import src.fr.api.PartType; import src.fr.api.PartType;
public class PartTypeImpl implements PartType { public class PartTypeImpl implements PartType {
private String name; private String name;
private Category category; private Category category;
private Class<? extends PartImpl> classRef;
public PartTypeImpl(String name, Category category ) { public PartTypeImpl(String name,Class<? extends PartImpl> classref, Category category ) {
this.name = name; this.name = name;
this.classRef= classref;
this.category = category; this.category = category;
} }
public PartImpl newInstance(){
Constructor<? extends PartImpl> constructor;
try{
constructor = classRef.getConstructor();
return constructor.newInstance();
} catch(Exception e){
Logger.getGlobal().log(Level.SEVERE, "constructor call failed",e);
System.exit(-1);
}
return null;
}
public String getName(){ public String getName(){
return this.name; return this.name;
} }

View File

@@ -0,0 +1,35 @@
package src.fr.impl.Parts;
import java.util.HashMap;
import src.fr.api.PartType;
import src.fr.impl.PartImpl;
public class Engine extends PartImpl {
/*public Engine(String name, CategoryImpl category, int price){
super(new PartTypeImpl(name,Engine.class, category),price);
}*/
private static final HashMap<String,Integer> prices;
static {
prices = new HashMap<>();
prices.put("EG100",19000);
prices.put("EG122",22000);
prices.put("EG210",25000);
prices.put("ED110",18000);
prices.put("ED180",20000);
prices.put("EH120",25000);
}
public Engine(){
}
@Override
public void setType(PartType type){
this.type = type;
if(prices.containsKey(type.getName())){
this.price = prices.get(type.getName());
}
else this.price = 0;
}
}

View File

@@ -0,0 +1,56 @@
package src.fr.impl.Parts;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import src.fr.api.PartType;
import src.fr.impl.PartImpl;
public class Exterior extends PartImpl {
private static final HashMap<String,Integer> prices;
static {
prices = new HashMap<>();
prices.put("XC",0);
prices.put("XM",800);
prices.put("XS",10000);
}
private static final Set<String> colorSet;
static {
colorSet = new HashSet<>();
colorSet.add("white");
colorSet.add("green");
colorSet.add("red");
colorSet.add("blue");
colorSet.add("green");
colorSet.add("gray");
}
private String color;
public Exterior(){
this.addProperty("color", () -> getColor(), c -> setColor(c), colorSet);
this.setProperty("color","white");
}
public String getColor(){
return this.color;
}
public void setColor(String newColor){
this.color = newColor;
}
@Override
public void setType(PartType type){
this.type = type;
if(prices.containsKey(type.getName())){
this.price = prices.get(type.getName());
}
else this.price = 0;
}
}

View File

@@ -0,0 +1,57 @@
package src.fr.impl.Parts;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import src.fr.api.PartType;
import src.fr.impl.PartImpl;
public class Interior extends PartImpl {
private static final HashMap<String,Integer> prices;
static {
prices = new HashMap<>();
prices.put("IN",0);
prices.put("IH",800);
prices.put("IS",2500);
}
private static final Set<String> colorSet;
static {
colorSet = new HashSet<>();
colorSet.add("black");
colorSet.add("white");
colorSet.add("cream");
}
String color;
public Interior(){
this.addProperty("color", () -> getColor(), c -> setColor(c), colorSet);
this.setProperty("color","black");
}
public String getColor(){
return this.color;
}
public void setColor(String newColor){
this.color = newColor;
}
@Override
public void setType(PartType type){
this.type = type;
if(prices.containsKey(type.getName())){
this.price = prices.get(type.getName());
}
else this.price = 0;
}
}

View File

@@ -0,0 +1,35 @@
package src.fr.impl.Parts;
import java.util.HashMap;
import src.fr.api.PartType;
import src.fr.impl.PartImpl;
public class Transmission extends PartImpl {
/*public Transmission(String name, CategoryImpl category, int price){
super(new PartTypeImpl(name,Engine.class, category),price);
}*/
private static final HashMap<String,Integer> prices;
static {
prices = new HashMap<>();
prices.put("TM5",2000);
prices.put("TM6",4000);
prices.put("TA5",7000);
prices.put("TS6",10000);
prices.put("TSF7",15000);
prices.put("TC120",5000);
}
public Transmission(){
}
@Override
public void setType(PartType type){
this.type = type;
if(prices.containsKey(type.getName())){
this.price = prices.get(type.getName());
}
else this.price = 0;
}
}

View File

@@ -3,51 +3,48 @@ package src.fr.test;
import java.util.Set; import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import src.fr.impl.*; import src.fr.impl.*;
import src.fr.impl.Parts.*;
import src.fr.api.*; import src.fr.api.*;
public class test_V1 {
public class test { CategoryImpl engine = new CategoryImpl("Engine");
CategoryImpl transmission = new CategoryImpl("Transmission");
Category Engine = new CategoryImpl("Engine"); CategoryImpl exterior = new CategoryImpl("Exterior");
Category Transmission = new CategoryImpl("Transmission"); CategoryImpl interior = new CategoryImpl("Interior");
Category Exterior= new CategoryImpl("Exterior");
Category Interior= new CategoryImpl("Interior");
//PartType //PartType
PartType EG100= new PartTypeImpl("EG100", Engine); PartType EG100= new PartTypeImpl("EG100",Engine.class, engine);
PartType EG133= new PartTypeImpl("EG133", Engine); PartType EG133= new PartTypeImpl("EG133",Engine.class, engine);
PartType EG210= new PartTypeImpl("EG210", Engine); PartType EG210= new PartTypeImpl("EG210",Engine.class, engine);
PartType ED110= new PartTypeImpl("ED110", Engine); PartType ED110= new PartTypeImpl("ED110",Engine.class, engine);
PartType ED180= new PartTypeImpl("ED180", Engine); PartType ED180= new PartTypeImpl("ED180",Engine.class, engine);
PartType EH120= new PartTypeImpl("EH120", Engine); PartType EH120= new PartTypeImpl("EH120",Engine.class, engine);
PartType TM5= new PartTypeImpl("TM5", Transmission); PartType TM5= new PartTypeImpl("TM5", Transmission.class ,transmission);
PartType TM6= new PartTypeImpl("TM6", Transmission); PartType TM6= new PartTypeImpl("TM6", Transmission.class ,transmission);
PartType TA5= new PartTypeImpl("TA5", Transmission); PartType TA5= new PartTypeImpl("TA5", Transmission.class ,transmission);
PartType TS6= new PartTypeImpl("TS6", Transmission); PartType TS6= new PartTypeImpl("TS6", Transmission.class ,transmission);
PartType TSF7= new PartTypeImpl("TSF7", Transmission); PartType TSF7= new PartTypeImpl("TSF7", Transmission.class ,transmission);
PartType TC120= new PartTypeImpl("TC120", Transmission); PartType TC120= new PartTypeImpl("TC120", Transmission.class ,transmission);
PartType XC= new PartTypeImpl("XC", Exterior); PartType XC= new PartTypeImpl("XC", Exterior.class,exterior);
PartType XM= new PartTypeImpl("XM", Exterior); PartType XM= new PartTypeImpl("XM", Exterior.class,exterior);
PartType XS= new PartTypeImpl("XS", Exterior); PartType XS= new PartTypeImpl("XS", Exterior.class,exterior);
PartType IN= new PartTypeImpl("IN", Interior);
PartType IH= new PartTypeImpl("IH", Interior);
PartType IS= new PartTypeImpl("IS", Interior);
PartType IN= new PartTypeImpl("IN", Interior.class ,interior);
PartType IH= new PartTypeImpl("IH", Interior.class ,interior);
PartType IS= new PartTypeImpl("IS", Interior.class ,interior);
CompatibilityManager cm; CompatibilityManager cm;
@BeforeEach @BeforeEach
public void init(){ public void init(){
@@ -96,6 +93,9 @@ public class test {
cm.addRequirements(IS, ISRequirement); cm.addRequirements(IS, ISRequirement);
} }
//compatibilitiesManager
@Test @Test
public void test_Incompatibilities_Simple_1(){ public void test_Incompatibilities_Simple_1(){
assertTrue(cm.getIncompatibilities(TA5).contains(EG100)); assertTrue(cm.getIncompatibilities(TA5).contains(EG100));
@@ -115,8 +115,6 @@ public class test {
assertTrue(cm.getRequirements(EH120).contains(TC120)); assertTrue(cm.getRequirements(EH120).contains(TC120));
} }
/* /*
* A <-> B * A <-> B
* if A -> B then B -> A * if A -> B then B -> A
@@ -139,7 +137,6 @@ public class test {
assertTrue(cm.getIncompatibilities(XS).contains(TM5)); assertTrue(cm.getIncompatibilities(XS).contains(TM5));
} }
/* /*
* Require Require Require * Require Require Require
* if A -> B && B -> C then A -> C * if A -> B && B -> C then A -> C
@@ -212,31 +209,34 @@ public class test {
@Test @Test
public void test_contradiction(){ public void test_contradiction(){
CompatibilityManager cm2 = new CompatibilityManagerImpl(); CompatibilityManager cm2 = new CompatibilityManagerImpl();
PartType eg= new PartTypeImpl("Eg", Engine); PartType eg= new PartTypeImpl("eg",Engine.class, engine);
PartType tr= new PartTypeImpl("Tr", Transmission); PartType tr= new PartTypeImpl("Tr", Transmission.class, transmission);
Set<PartType> egIncompatibilities = new HashSet<PartType>(); Set<PartType> egIncompatibilities = new HashSet<PartType>();
egIncompatibilities.add(tr); egIncompatibilities.add(tr);
cm2.addIncompatibilities(eg, egIncompatibilities); cm.addIncompatibilities(eg, egIncompatibilities);
Set<PartType> efRequirement = new HashSet<PartType>(); Set<PartType> efRequirement = new HashSet<PartType>();
efRequirement.add(eg); efRequirement.add(eg);
cm2.addRequirements(tr, efRequirement); cm.addRequirements(tr, efRequirement);
assertFalse(cm2.getIncompatibilities(eg).contains(eg)); assertFalse(cm.getIncompatibilities(eg).contains(eg));
assertTrue(cm2.getRequirements(tr).contains(eg)); assertTrue(cm.getRequirements(tr).contains(eg));
assertTrue(cm2.getIncompatibilities(tr).contains(tr)); //tr Require eg, eg Incompatible tr, -> eg Incompatible eg assertTrue(cm.getIncompatibilities(tr).contains(tr)); //tr Require eg, eg Incompatible tr, -> eg Incompatible eg
} }
//Configuration
@Test @Test
public void test_isComplete_empty_config(){ public void test_isComplete_empty_config(){
ConfigurationImpl config1 = new ConfigurationImpl(cm); ConfigurationImpl config1 = new ConfigurationImpl(cm);
assertFalse(config1.isComplete()); assertFalse(config1.isComplete());
} }
@Test @Test
public void test_isComplete(){ public void test_isComplete(){
ConfigurationImpl config1 = new ConfigurationImpl(cm); ConfigurationImpl config1 = new ConfigurationImpl(cm);
@@ -259,22 +259,24 @@ public class test {
} }
@Test @Test
public void test_isNotValide_empty_config(){ public void test_isNotComplete_empty_cm(){
ConfigurationImpl config1 = new ConfigurationImpl(cm); CompatibilityManager cm2 = new CompatibilityManagerImpl();
assertFalse(config1.isValid()); ConfigurationImpl config1 = new ConfigurationImpl(cm2);
}
@Test
public void test_isNotValide_not_complete(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210); config1.selectPart(EG210);
config1.selectPart(TM5); config1.selectPart(TM5);
config1.selectPart(XS); config1.selectPart(XS);
assertFalse(config1.isValid());
assertFalse(config1.isComplete());
} }
@Test @Test
public void test_isValid_empty_cm(){ public void test_isValide_empty_config(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
assertTrue(config1.isValid());
}
@Test
public void test_isValide_empty_cm(){
CompatibilityManager cm2 = new CompatibilityManagerImpl(); CompatibilityManager cm2 = new CompatibilityManagerImpl();
ConfigurationImpl config1 = new ConfigurationImpl(cm2); ConfigurationImpl config1 = new ConfigurationImpl(cm2);
config1.selectPart(EG210); config1.selectPart(EG210);
@@ -286,34 +288,67 @@ public class test {
} }
@Test @Test
public void test_isValid(){ public void test_isValide1(){
ConfigurationImpl config1 = new ConfigurationImpl(cm); ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210); config1.selectPart(EG210);
config1.selectPart(TS6); config1.selectPart(TSF7);
config1.selectPart(XS); config1.selectPart(XS);
config1.selectPart(IS); config1.selectPart(IS);
assertTrue(config1.isValid()); assertTrue(config1.isValid());
} }
@Test @Test
public void test_isNotValid(){ public void test_isValide2(){
ConfigurationImpl config1 = new ConfigurationImpl(cm); ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210); config1.selectPart(EG210);
config1.selectPart(TM5); config1.selectPart(TSF7);
config1.selectPart(XS); config1.selectPart(XS);
config1.selectPart(IH); config1.selectPart(IS);
config1.selectPart(TS6);
assertTrue(config1.isValid());
}
@Test
public void test_isNotValide1(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG100);
config1.selectPart(TSF7);
config1.selectPart(XS);
config1.selectPart(IS);
assertFalse(config1.isValid()); assertFalse(config1.isValid());
} }
@Test
public void test_isNotValide2(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210);
config1.selectPart(TSF7);
config1.selectPart(XS);
config1.selectPart(XS);
assertFalse(config1.isValid());
}
@Test
public void test_isValide_but_not_complete(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210);
config1.selectPart(TSF7);
assertTrue(config1.isValid());
}
@Test @Test
public void test_contradiction_config(){ public void test_contradiction_config(){
CompatibilityManager cm2 = new CompatibilityManagerImpl(); CompatibilityManager cm2 = new CompatibilityManagerImpl();
PartType eg= new PartTypeImpl("Eg", Engine); PartType eg= new PartTypeImpl("eg",Engine.class, engine);
PartType tr= new PartTypeImpl("Tr", Transmission); PartType tr= new PartTypeImpl("Tr", Transmission.class, transmission);
PartType ex= new PartTypeImpl("Ex", Exterior); PartType ex= new PartTypeImpl("Ex", Exterior.class, exterior);
PartType in= new PartTypeImpl("In", Interior); PartType in= new PartTypeImpl("In", Interior.class, interior);
Set<PartType> egIncompatibilities = new HashSet<PartType>(); Set<PartType> egIncompatibilities = new HashSet<PartType>();
egIncompatibilities.add(tr); egIncompatibilities.add(tr);

227
src/fr/test/test_V2.java Normal file
View File

@@ -0,0 +1,227 @@
package src.fr.test;
import java.util.Set;
import java.io.IOException;
import java.util.HashSet;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import src.fr.impl.*;
import src.fr.impl.Parts.*;
import src.fr.api.*;
public class test_V2 {
CategoryImpl engine = new CategoryImpl("Engine");
CategoryImpl transmission = new CategoryImpl("Transmission");
CategoryImpl exterior = new CategoryImpl("Exterior");
CategoryImpl interior = new CategoryImpl("Interior");
//PartType
PartType EG100= new PartTypeImpl("EG100",Engine.class, engine);
PartType EG133= new PartTypeImpl("EG133",Engine.class, engine);
PartType EG210= new PartTypeImpl("EG210",Engine.class, engine);
PartType ED110= new PartTypeImpl("ED110",Engine.class, engine);
PartType ED180= new PartTypeImpl("ED180",Engine.class, engine);
PartType EH120= new PartTypeImpl("EH120",Engine.class, engine);
PartType TM5= new PartTypeImpl("TM5", Transmission.class ,transmission);
PartType TM6= new PartTypeImpl("TM6", Transmission.class ,transmission);
PartType TA5= new PartTypeImpl("TA5", Transmission.class ,transmission);
PartType TS6= new PartTypeImpl("TS6", Transmission.class ,transmission);
PartType TSF7= new PartTypeImpl("TSF7", Transmission.class ,transmission);
PartType TC120= new PartTypeImpl("TC120", Transmission.class ,transmission);
PartType XC= new PartTypeImpl("XC", Exterior.class,exterior);
PartType XM= new PartTypeImpl("XM", Exterior.class,exterior);
PartType XS= new PartTypeImpl("XS", Exterior.class,exterior);
PartType IN= new PartTypeImpl("IN", Interior.class ,interior);
PartType IH= new PartTypeImpl("IH", Interior.class ,interior);
PartType IS= new PartTypeImpl("IS", Interior.class ,interior);
CompatibilityManager cm;
@BeforeEach
public void init(){
cm = new CompatibilityManagerImpl();
Set<PartType> EH120Requirement = new HashSet<PartType>();
EH120Requirement.add(TC120);
Set<PartType> TA5Incompatibilities = new HashSet<PartType>();
TA5Incompatibilities.add(EG100);
Set<PartType> TSF7Incompatibilities = new HashSet<PartType>();
TSF7Incompatibilities.add(EG100);
TSF7Incompatibilities.add(EG133);
TSF7Incompatibilities.add(ED110);
Set<PartType> TC120Requirement = new HashSet<PartType>();
TC120Requirement.add(EH120);
Set<PartType> XCIncompatibilities = new HashSet<PartType>();
XCIncompatibilities.add(EG210);
Set<PartType> XMIncompatibilities = new HashSet<PartType>();
XMIncompatibilities.add(EG100);
Set<PartType> XSIncompatibilities = new HashSet<PartType>();
XSIncompatibilities.add(EG100);
Set<PartType> XSRequirement = new HashSet<PartType>();
XSRequirement.add(IS);
Set<PartType> ISIncompatibilities = new HashSet<PartType>();
ISIncompatibilities.add(EG100);
ISIncompatibilities.add(TM5);
Set<PartType> ISRequirement = new HashSet<PartType>();
ISRequirement.add(XS);
cm.addRequirements(EH120, EH120Requirement);
cm.addIncompatibilities(TA5, TA5Incompatibilities);
cm.addIncompatibilities(TSF7, TSF7Incompatibilities);
cm.addRequirements(TC120, TC120Requirement);
cm.addIncompatibilities(XC, XCIncompatibilities);
cm.addIncompatibilities(XM, XMIncompatibilities);
cm.addIncompatibilities(XS, XSIncompatibilities);
cm.addRequirements(XS, XSRequirement);
cm.addIncompatibilities(IS, ISIncompatibilities);
cm.addRequirements(IS, ISRequirement);
}
@Test
public void test_NotProperty(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210);
config1.selectPart(TSF7);
config1.selectPart(XS);
config1.selectPart(IS);
assertEquals(config1.getPart(exterior).getProperty("color").get(), "white");
assertEquals(config1.getPart(interior).getProperty("color").get(), "black");
assertTrue(config1.isValid());
}
@Test
public void test_Property(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210);
config1.selectPart(TSF7);
config1.selectPart(XS);
config1.selectPart(IS);
config1.getPart(exterior).setProperty("color","red");
assertEquals(config1.getPart(exterior).getProperty("color").get(), "red");
assertTrue(config1.isValid());
}
@Test
public void test_NotCompatibleProperty(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210);
config1.selectPart(TSF7);
config1.selectPart(XS);
config1.selectPart(IS);
config1.getPart(exterior).setProperty("color","gsqgsdf");
assertEquals(config1.getPart(exterior).getProperty("color").get(), "gsqgsdf");
assertFalse(config1.isValid());
}
@Test
void test_Price(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210);
assertEquals(((PartImpl)config1.getPart(engine)).getPrice(), 25000);
}
@Test
void test_Config_Price(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210);
config1.selectPart(TSF7);
config1.selectPart(XS);
config1.selectPart(IS);
assertEquals(config1.getTotalPrice(), 52500);
}
@Test
void test_Config_Price_No_Complete(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210);
config1.selectPart(TSF7);
assertEquals(config1.getTotalPrice(), 40000);
}
@Test
void test_Config_Price_No_Valid(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG100);
config1.selectPart(TSF7);
assertFalse(config1.isValid());
assertEquals(config1.getTotalPrice(), -1);
}
@Test
void test_Config_Price_Empty_config(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
assertTrue(config1.isValid());
assertEquals(config1.getTotalPrice(), 0);
}
@Test
void test_html(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210);
config1.selectPart(TSF7);
try {
HtmlGenerator.generateHTML(config1);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
void test_html2(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210);
config1.selectPart(TSF7);
config1.selectPart(XC); //incompatible
config1.selectPart(IS); //incompatible
config1.getPart(exterior).setProperty("color", "red");
config1.getPart(interior).setProperty("color", "red");
try {
HtmlGenerator.generateHTML(config1);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
void test_html3(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210);
config1.selectPart(TSF7);
config1.selectPart(XS);
config1.selectPart(IS);
config1.getPart(exterior).setProperty("color", "red");
config1.getPart(interior).setProperty("color", "red");
try {
HtmlGenerator.generateHTML(config1);
} catch (IOException e) {
e.printStackTrace();
}
}
}