78 Commits
main ... dev_v2

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
Minh VU
23ea8746b1 pass all tests, resee empty 7 2024-10-24 13:14:51 +02:00
Minh VU
1168b5377f Maybe the incompatible will be useful 2024-10-24 11:28:26 +02:00
trochas
1a09eda6e7 ajout de tests 2024-10-24 11:49:58 +02:00
trochas
ba3596319c test en cours ... 2024-10-24 10:56:07 +02:00
trochas
51a24aa140 test en cours ... 2024-10-24 10:51:00 +02:00
Minh VU
0b511522bc add transivity 2024-10-24 08:33:28 +02:00
trochas
8457ab48fa correction des tests en cours... 2024-10-24 10:21:35 +02:00
trochas
df189bf44c Merge branch 'dev_v1' of https://gitlab.istic.univ-rennes1.fr/trochas/cartailor into dev_v1 2024-10-24 10:20:51 +02:00
trochas
9bf322af6a correction test en cours... 2024-10-24 10:19:12 +02:00
trochas
8770ec3165 ajout de commentaires dans les interfaces et correction des test 2024-10-24 10:03:08 +02:00
Minh VU
82c9f268f8 add transivity to incompatbile 2024-10-24 08:18:10 +02:00
trochas
467b20f0b6 test problème 2024-10-24 08:11:44 +02:00
Minh VU
7bf5b5eb9f Test all verified
Nice tester ( Thibaut )
2024-10-18 19:24:20 +02:00
trochas
40e4c6532c ajout des test lié aux add Requirements et Incompatibilities 2024-10-18 18:15:13 +02:00
trochas
06fe1715a9 correction @Before test 2024-10-18 18:06:06 +02:00
trochas
7685f600ea correction nom des Impl 2024-10-18 17:43:50 +02:00
trochas
3af42dabdd correction nom des Impl 2024-10-18 17:43:12 +02:00
trochas
2fb99e1b62 test addRequirements & Incompatibility 2024-10-18 17:37:08 +02:00
trochas
8ea96996d4 correction PartTypeImpl 2024-10-18 17:32:47 +02:00
Minh VU
1b80e60980 my bad 2024-10-18 17:18:30 +02:00
Minh VU
f97509496e reorginazise 2024-10-18 17:11:29 +02:00
Minh VU
51fd5e6e07 test marche 2024-10-18 16:57:52 +02:00
trochas
e9d6072d25 implémentation des tests 2024-10-18 16:47:52 +02:00
Minh VU
1f4c0bdf63 Hope it works manager
like title
2024-10-18 16:41:39 +02:00
Minh VU
6c0b2e1ede remove the update 2024-10-18 16:30:25 +02:00
Minh VU
4ef176d3c5 Improve manager
update manager
2024-10-18 16:16:05 +02:00
Minh VU
ce92682230 Update test
Test
2024-10-18 15:54:49 +02:00
trochas
e96d87a815 Implémentation compatibility checker 2024-10-18 15:53:09 +02:00
Rochas Thibaut
1313390d0d Delete Iterator.java 2024-10-18 13:51:58 +00:00
trochas
51ad055258 Implémentation compatibility checker 2024-10-18 15:51:09 +02:00
Minh VU
ed03836ef4 Update Configuration
Il manque isValid()
2024-10-18 15:31:09 +02:00
Minh VU
53edc969c5 add more error
Merci de corriger stp
2024-10-18 14:59:49 +02:00
Minh VU
4268f53f8d Update error
Add class and update error
2024-10-18 14:58:39 +02:00
Minh VU
26928a231d add CompatibilityManager
and a bitte of Checker and Configuration
2024-10-10 13:00:13 +02:00
Minh VU
fdf82e5ce1 Configurator
add Configurator
2024-10-10 11:03:34 +02:00
trochas
d6f25d05ee ajout de CompatibilityChecker et Manager 2024-10-10 11:03:07 +02:00
trochas
1945c62d03 correction syntaxe 2024-10-10 10:44:48 +02:00
Minh VU
3049848931 push src 2024-10-10 10:41:27 +02:00
trochas
01ff7abe04 ajour de l'api v1 2024-10-10 10:35:43 +02:00
37 changed files with 1873 additions and 1 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

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

6
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/cartailor.iml" filepath="$PROJECT_DIR$/cartailor.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

97
.idea/workspace.xml generated Normal file
View File

@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="12bd6c53-8ba7-454c-a61e-7a76cc3b801b" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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/Parts/Engine.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/impl/Parts/Engine.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/test/test.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/test/test.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Interface" />
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProblemsViewState">
<option name="selectedTabId" value="ProjectErrors" />
</component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 1
}</component>
<component name="ProjectId" id="2nEoqUUHcIor4OnYQ3cqGODPYlO" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"git-widget-placeholder": "Merging dev__v2",
"ignore.virus.scanning.warn.message": "true",
"kotlin-language-version-configured": "true",
"last_opened_file_path": "C:/Users/vumin/Desktop/M1/ALO/cartailor",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"project.structure.last.edited": "Project",
"project.structure.proportion": "0.15",
"project.structure.side.proportion": "0.2",
"settings.editor.selected.configurable": "preferences.lookFeel",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\vumin\Desktop\M1\ALO\cartailor\Catalog" />
<recent name="C:\Users\vumin\Desktop\M1\ALO\cartailor" />
</key>
</component>
<component name="SharedIndexes">
<attachedChunks>
<set>
<option value="bundled-jdk-9823dce3aa75-28b599e66164-intellij.indexing.shared.core-IU-242.23339.11" />
<option value="bundled-js-predefined-d6986cc7102b-5c90d61e3bab-JavaScript-IU-242.23339.11" />
</set>
</attachedChunks>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="12bd6c53-8ba7-454c-a61e-7a76cc3b801b" name="Changes" comment="" />
<created>1728547786554</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1728547786554</updated>
<workItem from="1729254205656" duration="1151000" />
<workItem from="1729507889060" duration="386000" />
<workItem from="1729595321874" duration="25000" />
<workItem from="1729743145740" duration="122000" />
<workItem from="1729757559608" duration="166000" />
<workItem from="1729764402753" duration="206000" />
<workItem from="1731196687641" duration="82000" />
<workItem from="1733327767478" duration="184000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
</project>

View File

@@ -1 +1,19 @@
V1 et V2 respectivement dans les branches dev_V1 et dev_v2
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 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>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 MiB

BIN
lib/hamcrest-core-1.3.jar Normal file

Binary file not shown.

Binary file not shown.

9
src/fr/api/Category.java Normal file
View File

@@ -0,0 +1,9 @@
package src.fr.api;
/**
* @author plouzeau
* <p>
* A public type to organize part types in categories
*/
public interface Category {
String getName();
}

View File

@@ -0,0 +1,6 @@
package src.fr.api;
import java.util.Set;
public interface CompatibilityChecker {
Set<PartType> getIncompatibilities(PartType reference);
Set<PartType> getRequirements(PartType reference);
}

View File

@@ -0,0 +1,8 @@
package src.fr.api;
import java.util.Set;
public interface CompatibilityManager extends CompatibilityChecker {
void addIncompatibilities(PartType reference,Set<PartType> target);
void removeIncompatibility(PartType reference, PartType target);
void addRequirements(PartType reference, Set<PartType> target);
void removeRequirement(PartType reference, PartType target);
}

View File

@@ -0,0 +1,45 @@
package src.fr.api;
import java.util.Set;
import java.util.Optional;
public interface Configuration {
/*
* @return true if there is no compatibility issue between PartType else false
*/
boolean isValid();
/*
* @return true if the configuration is valid and done
*/
boolean isComplete();
/*
* @return the list of the Part in the configuration
*/
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
* @param chosenPart : the PartType that we wish to add to the configuration
*/
void selectPart(PartType chosenPart);
/*
* DeSelect PartType has Catgerory catgoryToClear to delete from the configuration
* @param categoryToClear : the PartType has categoryToClear Category
* that we wish to delete from the configuration
*/
void unselectPartType(Category categoryToClear);
/*
* Remove all PartType from configuation
*/
void clear();
}

View File

@@ -0,0 +1,24 @@
package src.fr.api;
import java.util.Set;
public interface Configurator {
/*
* @return the list of the Category in the configurator
*/
Set<Category> getCategories();
/*
* @return the list of the Category in the configurator
* @param category: category that we want to see all PartType in that category
*/
Set<PartType> getVariants(Category category);
/*
* @return the configuration
*/
Configuration getConfiguration();
/*
* @return compabilitychecker
*/
CompatibilityChecker getCompatibilityChecker();
}

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();
}

12
src/fr/api/PartType.java Normal file
View File

@@ -0,0 +1,12 @@
package src.fr.api;
public interface PartType {
/*
* @return name of this PartType
*/
String getName();
/*
* @return the category of this PartType
*/
Category getCategory();
}

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

@@ -0,0 +1,15 @@
package src.fr.impl;
import src.fr.api.Category;
public class CategoryImpl implements Category {
private String name;
public CategoryImpl(String name){
this.name= name;
}
public String getName(){
return this.name;
}
}

View File

@@ -0,0 +1,29 @@
package src.fr.impl;
import java.util.Set;
import src.fr.api.PartType;
import src.fr.api.CompatibilityChecker;
import src.fr.api.CompatibilityManager;
public class CompatibilityCheckerImpl implements CompatibilityChecker {
private CompatibilityManager compatibilityManager;
public CompatibilityCheckerImpl( CompatibilityManager compatibilityManager){
this.compatibilityManager=compatibilityManager;
}
@Override
public Set<PartType> getIncompatibilities(PartType reference) {
return this.compatibilityManager.getIncompatibilities(reference);
}
@Override
public Set<PartType> getRequirements(PartType reference) {
return this.compatibilityManager.getRequirements(reference);
}
}

View File

@@ -0,0 +1,204 @@
package src.fr.impl;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.Objects;
import src.fr.api.PartType;
import src.fr.api.CompatibilityManager;
public class CompatibilityManagerImpl implements CompatibilityManager {
private HashMap<PartType, Set<PartType>> incompatibilities;
private HashMap<PartType, Set<PartType>> requirements;
public CompatibilityManagerImpl() {
this.incompatibilities = new HashMap<>();
this.requirements = new HashMap<>();
}
@Override
public void addIncompatibilities(PartType reference, Set<PartType> target){
//Précondition
Objects.requireNonNull(reference);
Objects.requireNonNull(target);
Set<PartType> incompa = this.getIncompatibilities(reference);
Set<PartType> require = this.getRequirements(reference);
if(incompa.isEmpty()){
incompatibilities.put(reference, target);
}else {
for(PartType x: target){
if (incompa.contains(x)){
System.out.println("We have it already");
}else {
if(require.contains(x)){
System.out.println("Cannot remove");
}else{
//Ajout ref à x
incompa.add(x);
System.out.println("Add "+reference.getName() +" incompatible with "+x.getName());
this.incompatibilities.put(reference, incompa);
// Symétrie
//Ajoute x à ref
//this.getIncompatibilities(x).add(reference);
//System.out.println("Add "+x.getName() +" incompatible with "+reference.getName());
}
}
}
}
}
@Override
public void removeIncompatibility(PartType reference, PartType target){
//Précondition
Objects.requireNonNull(reference);
Objects.requireNonNull(target);
Set<PartType> incompa = this.getIncompatibilities(reference);
if(incompa.isEmpty()){
System.out.println("No part incompatible");
}else{
if(incompa.contains(target)){
incompa.remove(target);
this.incompatibilities.replace(reference, incompa);
// SyMéTrIe
//Remove target -> ref
//this.getIncompatibilities(target).remove(reference);
}else {
System.out.println("This part doesn't exist in incompatibilities list");
}
}
}
@Override
public void addRequirements(PartType reference, Set<PartType> target){
//Précondition
Objects.requireNonNull(reference);
Objects.requireNonNull(target);
Set<PartType> incompa = this.getIncompatibilities(reference);
Set<PartType> require = this.getRequirements(reference);
if(require.isEmpty()){
requirements.put(reference, target);
}else {
for(PartType x: target){
if (require.contains(x)){
System.out.println("We have it already");
}else {
if(incompa.contains(x)){
System.out.println("Cannot remove");
}else{
//Ajout ref à x
require.add(x);
System.out.println("Add "+reference.getName() +" compatible with "+x.getName());
this.requirements.put(reference, require);
//Symétrie
//Ajoute x à ref
//this.getRequirements(x).add(reference);
//System.out.println("Add "+x.getName() +" compatible with "+reference.getName());
}
}
}
}
}
@Override
public void removeRequirement(PartType reference, PartType target){
//Précondition
Objects.requireNonNull(reference);
Objects.requireNonNull(target);
Set<PartType> require = this.getRequirements(reference);
if(require.isEmpty()){
System.out.println("No part compatible");
}else{
if(require.contains(target)){
require.remove(target);
this.requirements.replace(reference, require);
// SyMéTrIe
//Remove target -> ref
//this.getRequirements(target).remove(reference);
}else {
System.out.println("This part doesn't exist in compatibilities list");
}
}
}
// A -> B -> C -> A, D -> B
//erquirement only
private void Femeture_Transivite(PartType reference, Set<PartType> result, Set<PartType> visited, PartType start){
//Condition de quitter la boucle
if(visited.contains(reference)){
return;
}else {
visited.add(reference);
}
Set<PartType> list = null;
//Get all requirement of A (in example is B)
list = this.requirements.get(reference);
if(list != null){ // list = {B}
for(PartType pt: list){
if(!result.contains(pt)&& pt !=start){
result.add(pt);
}
Femeture_Transivite(pt,result,visited,reference);
}
}
}
@Override
public Set<PartType> getIncompatibilities(PartType reference) {
Set<PartType> result = new HashSet<>();
// Remove the case of result become null
Set<PartType> directIncompa = this.incompatibilities.get(reference);
if(directIncompa!=null){
result.addAll(directIncompa);
}
// Collect the requirements list
Set<PartType> requirements = new HashSet<>();
Femeture_Transivite(reference, requirements,new HashSet<>(),reference);
for(Map.Entry<PartType, Set<PartType>> entry : this.incompatibilities.entrySet()){
// check start
if(entry.getValue().contains(reference)){
result.add(entry.getKey());
}
// check incompatible of A's requirements
for(PartType pt: requirements){
// In Catalog of pt
if(entry.getValue().contains(pt)){
result.add(entry.getKey());
}
// Direct of pt
Set<PartType> direct_pt = this.incompatibilities.get(pt);
if(direct_pt!=null){
result.addAll(direct_pt);
}
}
}
return result;
}
@Override
public Set<PartType> getRequirements(PartType reference) {
Set<PartType> result = new HashSet<>();
Femeture_Transivite(reference, result,new HashSet<>(),reference);
return result;
}
}

View File

@@ -0,0 +1,154 @@
package src.fr.impl;
import src.fr.api.Category;
import src.fr.api.PartType;
import src.fr.api.CompatibilityManager;
import src.fr.api.Configuration;
import src.fr.api.Part;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
public class ConfigurationImpl implements Configuration {
private Set<Part> selectedParts = new HashSet<Part> ();
private CompatibilityManager compatibilityManager;
private static int NB_CATEGORY = 4;
public ConfigurationImpl(CompatibilityManager cm){
this.compatibilityManager=cm;
}
@Override
public boolean isValid() {
boolean test = true;
for(Part pt1: selectedParts){
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
for(PartType require : compatibilityManager.getRequirements(pt1.getType())){
test_Requirement = 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
for(PartType incompa : compatibilityManager.getIncompatibilities(pt1.getType())){
System.out.println("\tIncompatibility : " + incompa.getName());
for (Part selectPart : selectedParts){
if(selectPart.getType().equals(incompa)){
test_Incompabilities = false;
break;
}
}
}
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
public boolean isComplete() {
if(selectedParts.size()==NB_CATEGORY){
return true;
}
return false;
}
@Override
public Set<Part> getSelectedParts() {
return selectedParts;
}
@Override
public void selectPart(PartType chosenPart) {
Category category_chosenPart = chosenPart.getCategory();
//Vérifier s'il y a des pièces dans la même catégorie, si oui return
for(Part pt: selectedParts){
if(pt.getCategory().equals(category_chosenPart)){
System.out.println("Il y a une pièce dans la même catégorie dans la configuration");
selectedParts.remove(pt);
break;
}
}
PartImpl newPart = ((PartTypeImpl)chosenPart).newInstance();
newPart.setType(chosenPart);
selectedParts.add(newPart);
//System.out.println(chosenPart.getName() + " : size = " + selectedParts.size());
}
@Override
public Optional<Part> getSelectionForCategory(Category category) {
for( Part pt: selectedParts){
if(pt.getCategory().equals(category)){
return Optional.of(pt);
}
}
return Optional.empty();
}
@Override
public void unselectPartType(Category categoryToClear) {
for( Part pt: selectedParts){
if(pt.getCategory().equals(categoryToClear)){
selectedParts.remove(pt);
}
}
System.out.println("Il n'y a pas des pièces dans cette catégorie");
}
@Override
public void 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

@@ -0,0 +1,49 @@
package src.fr.impl;
import src.fr.api.Category;
import src.fr.api.CompatibilityChecker;
import src.fr.api.Configuration;
import src.fr.api.Configurator;
import src.fr.api.PartType;
import java.util.HashSet;
import java.util.Set;
public class ConfiguratorImpl implements Configurator {
private Set<Category> categories;
private Set<PartType> partTypes;
private Configuration configuration;
private CompatibilityChecker compatibilityChecker;
public ConfiguratorImpl (Set<Category> cat, Set<PartType> pt, Configuration config) {
this.categories= cat;
this.partTypes=pt;
this.configuration=config;
}
@Override
public Set<Category> getCategories() {
return this.categories;
}
@Override
public Set<PartType> getVariants(Category category) {
Set<PartType>a = new HashSet<PartType>();
for(PartType x : partTypes){
if (x.getCategory()==category){
a.add(x);
}
}
return a;
}
@Override
public Configuration getConfiguration() {
return this.configuration;
}
@Override
public CompatibilityChecker getCompatibilityChecker() {
return this.compatibilityChecker;
}
}

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

@@ -0,0 +1,40 @@
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.PartType;
public class PartTypeImpl implements PartType {
private String name;
private Category category;
private Class<? extends PartImpl> classRef;
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;
}
public String getName(){
return this.name;
}
public Category getCategory(){
return this.category;
}
}

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;
}
}

370
src/fr/test/test_V1.java Normal file
View File

@@ -0,0 +1,370 @@
package src.fr.test;
import java.util.Set;
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_V1 {
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);
}
//compatibilitiesManager
@Test
public void test_Incompatibilities_Simple_1(){
assertTrue(cm.getIncompatibilities(TA5).contains(EG100));
}
@Test
public void test_multiple_Incompatibilities_Simple_2(){
assertTrue(
cm.getIncompatibilities(TSF7).contains(EG100)&&
cm.getIncompatibilities(TSF7).contains(EG133)&&
cm.getIncompatibilities(TSF7).contains(ED110)
);
}
@Test
public void test_Requirements_3(){
assertTrue(cm.getRequirements(EH120).contains(TC120));
}
/*
* A <-> B
* if A -> B then B -> A
*/
@Test
public void test_Incompatibilities_Complex_4(){
System.out.println("size EG100 incompatibilities : "+cm.getIncompatibilities(EG100).size());
assertTrue(cm.getIncompatibilities(EG100).contains(IS));
assertTrue(cm.getIncompatibilities(EG100).contains(XS));
}
/*
* if A require B
* then A is incompatible with all incompatible of B
*/
@Test
public void test_Require_Incompatibilities_Complex_5(){
assertTrue(cm.getIncompatibilities(XS).contains(EG100));
System.out.println("size XS incompatibilities : " + cm.getIncompatibilities(XS).size());
assertTrue(cm.getIncompatibilities(XS).contains(TM5));
}
/*
* Require Require Require
* if A -> B && B -> C then A -> C
*/
@Test
public void test_Incompatibilities_Complex_7(){
cm.addRequirements(TC120, Set.of(XC));
assertTrue(cm.getRequirements(TC120).contains(XC));
assertTrue(cm.getRequirements(EH120).contains(XC));
cm.removeRequirement(TC120, XC);
}
@Test
public void test_Empty_Requirements_5(){
assertTrue(cm.getRequirements(ED180).isEmpty());
}
@Test
public void test_Remove_and_restore_Incompatibilities_6(){
assertTrue(cm.getIncompatibilities(XM).contains(EG100));
cm.removeIncompatibility(XM, EG100);
assertFalse(cm.getIncompatibilities(XM).contains(EG100));
Set<PartType> setEG100 = new HashSet<PartType>();
setEG100.add(EG100);
cm.addIncompatibilities(XM, setEG100);
assertTrue(cm.getIncompatibilities(XM).contains(EG100));
}
@Test
public void test_Remove_Empty_7(){
assertTrue(cm.getIncompatibilities(EH120).isEmpty());
cm.removeIncompatibility(EH120, EG100);
assertTrue(cm.getIncompatibilities(EH120).isEmpty()); }
@Test
public void test_Remove_and_restore_Requirements_8(){
assertTrue(cm.getRequirements(EH120).contains(TC120));
cm.removeRequirement(EH120, TC120);
assertFalse(cm.getRequirements(EH120).contains(TC120));
Set<PartType> setTC120 = new HashSet<PartType>();
setTC120.add(TC120);
cm.addRequirements(EH120, setTC120);
assertTrue(cm.getRequirements(EH120).contains(TC120));
}
@Test
public void test_remove_incompatibilities_but_no_removable(){
assertTrue(cm.getIncompatibilities(EG100).contains(IS));
cm.removeIncompatibility(EG100, IS);
assertTrue(cm.getIncompatibilities(EG100).contains(IS));
}
@Test
public void test_Add_and_restore_Incompatibilities_9(){
assertTrue(cm.getIncompatibilities(TSF7).contains(EG100));
assertTrue(cm.getIncompatibilities(TSF7).contains(EG133));
assertTrue(cm.getIncompatibilities(TSF7).contains(ED110));
cm.removeIncompatibility(TSF7, EG100);
assertFalse(cm.getIncompatibilities(TSF7).contains(EG100));
assertTrue(cm.getIncompatibilities(TSF7).contains(EG133));
assertTrue(cm.getIncompatibilities(TSF7).contains(ED110));
Set<PartType> setEG100 = new HashSet<PartType>();
setEG100.add(EG100);
cm.addIncompatibilities(TSF7, setEG100);
assertTrue(cm.getIncompatibilities(TSF7).contains(EG100));
assertTrue(cm.getIncompatibilities(TSF7).contains(EG133));
assertTrue(cm.getIncompatibilities(TSF7).contains(ED110));
}
@Test
public void test_contradiction(){
CompatibilityManager cm2 = new CompatibilityManagerImpl();
PartType eg= new PartTypeImpl("eg",Engine.class, engine);
PartType tr= new PartTypeImpl("Tr", Transmission.class, transmission);
Set<PartType> egIncompatibilities = new HashSet<PartType>();
egIncompatibilities.add(tr);
cm.addIncompatibilities(eg, egIncompatibilities);
Set<PartType> efRequirement = new HashSet<PartType>();
efRequirement.add(eg);
cm.addRequirements(tr, efRequirement);
assertFalse(cm.getIncompatibilities(eg).contains(eg));
assertTrue(cm.getRequirements(tr).contains(eg));
assertTrue(cm.getIncompatibilities(tr).contains(tr)); //tr Require eg, eg Incompatible tr, -> eg Incompatible eg
}
//Configuration
@Test
public void test_isComplete_empty_config(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
assertFalse(config1.isComplete());
}
@Test
public void test_isComplete(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210);
config1.selectPart(TM5);
config1.selectPart(XS);
config1.selectPart(IS);
assertTrue(config1.isComplete());
}
@Test
public void test_isNotComplete(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210);
config1.selectPart(TM5);
config1.selectPart(XS);
assertFalse(config1.isComplete());
}
@Test
public void test_isNotComplete_empty_cm(){
CompatibilityManager cm2 = new CompatibilityManagerImpl();
ConfigurationImpl config1 = new ConfigurationImpl(cm2);
config1.selectPart(EG210);
config1.selectPart(TM5);
config1.selectPart(XS);
assertFalse(config1.isComplete());
}
@Test
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();
ConfigurationImpl config1 = new ConfigurationImpl(cm2);
config1.selectPart(EG210);
config1.selectPart(TM5);
config1.selectPart(XS);
config1.selectPart(IS);
assertTrue(config1.isValid());
}
@Test
public void test_isValide1(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210);
config1.selectPart(TSF7);
config1.selectPart(XS);
config1.selectPart(IS);
assertTrue(config1.isValid());
}
@Test
public void test_isValide2(){
ConfigurationImpl config1 = new ConfigurationImpl(cm);
config1.selectPart(EG210);
config1.selectPart(TSF7);
config1.selectPart(XS);
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());
}
@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
public void test_contradiction_config(){
CompatibilityManager cm2 = new CompatibilityManagerImpl();
PartType eg= new PartTypeImpl("eg",Engine.class, engine);
PartType tr= new PartTypeImpl("Tr", Transmission.class, transmission);
PartType ex= new PartTypeImpl("Ex", Exterior.class, exterior);
PartType in= new PartTypeImpl("In", Interior.class, interior);
Set<PartType> egIncompatibilities = new HashSet<PartType>();
egIncompatibilities.add(tr);
cm2.addIncompatibilities(eg, egIncompatibilities);
Set<PartType> efRequirement = new HashSet<PartType>();
efRequirement.add(eg);
cm2.addRequirements(eg, efRequirement);
ConfigurationImpl config1 = new ConfigurationImpl(cm2);
config1.selectPart(eg);
config1.selectPart(tr);
config1.selectPart(ex);
config1.selectPart(in);
assertFalse(config1.isValid());
}
}

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();
}
}
}