5 Commits
dev_v2 ... main

Author SHA1 Message Date
Rochas Thibaut
a7bf89a0f2 Add README.md 2024-12-20 20:39:19 +00:00
Rochas Thibaut
3e084f5a98 Delete README.md 2024-12-20 16:52:31 +00:00
Rochas Thibaut
d59b15dea1 Add README.md 2024-12-20 16:49:28 +00:00
Minh VU
2ec38bc1ec reset
reset
2024-10-10 10:18:20 +02:00
Minh VU
b0a73d8468 Add interface
interfaces
2024-10-10 10:15:19 +02:00
37 changed files with 1 additions and 1873 deletions

10
.gitignore vendored
View File

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

8
.idea/.gitignore generated vendored
View File

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

6
.idea/misc.xml generated
View File

@@ -1,6 +0,0 @@
<?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
View File

@@ -1,8 +0,0 @@
<?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
View File

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

97
.idea/workspace.xml generated
View File

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

Binary file not shown.

View File

@@ -1,13 +0,0 @@
/*
* 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

@@ -1,60 +0,0 @@
/*
* 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

@@ -1,24 +0,0 @@
/*
* 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;
}

View File

@@ -1,27 +0,0 @@
<!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>

BIN
dragon.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

Binary file not shown.

View File

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

View File

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

View File

@@ -1,8 +0,0 @@
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

@@ -1,45 +0,0 @@
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

@@ -1,24 +0,0 @@
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();
}

View File

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

View File

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

View File

@@ -1,42 +0,0 @@
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,15 +0,0 @@
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

@@ -1,29 +0,0 @@
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

@@ -1,204 +0,0 @@
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

@@ -1,154 +0,0 @@
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

@@ -1,49 +0,0 @@
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

@@ -1,69 +0,0 @@
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");
}
}
}

View File

@@ -1,101 +0,0 @@
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,40 +0,0 @@
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

@@ -1,35 +0,0 @@
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

@@ -1,56 +0,0 @@
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

@@ -1,57 +0,0 @@
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

@@ -1,35 +0,0 @@
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

@@ -1,370 +0,0 @@
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());
}
}

View File

@@ -1,227 +0,0 @@
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();
}
}
}