Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88f90f0936 | ||
|
|
c62f1e1be1 | ||
|
|
ead826fd2e | ||
|
|
e44b45c35d | ||
|
|
7774db2254 | ||
|
|
617ee582dc | ||
|
|
f2c0645f60 | ||
|
|
d9d979b1e8 | ||
|
|
42dce975ad | ||
|
|
6c60549cfe | ||
|
|
a680ed5cd6 | ||
|
|
e43ecc8cfe | ||
|
|
090a609651 | ||
|
|
27eedecd8c | ||
|
|
69e9f01cdd | ||
|
|
3c7d910ab3 | ||
|
|
e82c50c90a | ||
|
|
6bc6fc678e | ||
|
|
af60294517 | ||
|
|
c2d6d245b4 | ||
|
|
93c1fab4de | ||
|
|
5e27042193 | ||
|
|
503d24f140 | ||
|
|
f9c6059067 | ||
|
|
e68e2771ed | ||
|
|
e1a5373c90 | ||
|
|
6ca58a33f6 | ||
|
|
d9e14bdd9f | ||
|
|
76e14bf7e0 | ||
|
|
955fd7006a | ||
|
|
f62ca87ef3 | ||
|
|
e6994a62b9 | ||
|
|
cc920bf6b6 | ||
|
|
9188d50741 | ||
|
|
c17f0352c8 | ||
|
|
4d85b9e036 | ||
|
|
61cdc3c766 | ||
|
|
91e25fb88d | ||
| 0b33ac703d |
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
# bloop and metals
|
||||
.bloop
|
||||
.bsp
|
||||
.metals
|
||||
project/metals.sbt
|
||||
|
||||
# vs code
|
||||
.vscode
|
||||
.idea
|
||||
31
.idea/workspace.xml
generated
31
.idea/workspace.xml
generated
@@ -5,15 +5,11 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="12bd6c53-8ba7-454c-a61e-7a76cc3b801b" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/cartailor.iml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/fr/impl/CategoryImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/impl/CategoryImpl.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/fr/impl/CompatibilityManagerImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/impl/CompatibilityManagerImpl.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/fr/impl/ConfigurationImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/impl/ConfigurationImpl.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/fr/impl/ConfiguratorImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/impl/ConfiguratorImpl.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/fr/impl/PartTypeImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/impl/PartTypeImpl.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/fr/impl/PartImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/fr/impl/PartImpl.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/fr/impl/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" />
|
||||
@@ -46,7 +42,7 @@
|
||||
"keyToString": {
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"git-widget-placeholder": "dev__v1",
|
||||
"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",
|
||||
@@ -68,21 +64,6 @@
|
||||
<recent name="C:\Users\vumin\Desktop\M1\ALO\cartailor" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunManager">
|
||||
<configuration default="true" type="JetRunConfigurationType">
|
||||
<module name="cartailor" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration default="true" type="KotlinStandaloneScriptRunConfigurationType">
|
||||
<module name="cartailor" />
|
||||
<option name="filePath" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
||||
<component name="SharedIndexes">
|
||||
<attachedChunks>
|
||||
<set>
|
||||
@@ -105,6 +86,8 @@
|
||||
<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>
|
||||
|
||||
19
README.md
Normal file
19
README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
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...
|
||||
BIN
V2/ACO TD5 guide for students.pdf
Normal file
BIN
V2/ACO TD5 guide for students.pdf
Normal file
Binary file not shown.
13
V2/snippet API V2.txt
Normal file
13
V2/snippet API V2.txt
Normal 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();
|
||||
}
|
||||
60
V2/snippet PropertyManager implementation.txt
Normal file
60
V2/snippet PropertyManager implementation.txt
Normal 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();
|
||||
}
|
||||
24
V2/snippet V2 PartTypeImpl.txt
Normal file
24
V2/snippet V2 PartTypeImpl.txt
Normal 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
27
cartailor.html
Normal 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.
BIN
lib/junit-platform-console-standalone-1.11.4.jar
Normal file
BIN
lib/junit-platform-console-standalone-1.11.4.jar
Normal file
Binary file not shown.
@@ -5,10 +5,5 @@ package src.fr.api;
|
||||
* A public type to organize part types in categories
|
||||
*/
|
||||
public interface Category {
|
||||
|
||||
/*
|
||||
* return the name of the cathegory
|
||||
* @return String, name of the cathegory, non null
|
||||
*/
|
||||
String getName();
|
||||
}
|
||||
@@ -1,18 +1,6 @@
|
||||
package src.fr.api;
|
||||
import java.util.Set;
|
||||
public interface CompatibilityChecker {
|
||||
|
||||
/*
|
||||
* return the list of the incompatibles PartType of a PartType
|
||||
* @param reference : the PartType that we want to see the incompatibilities,non null
|
||||
* @return the Set list of the incompatibles PartType
|
||||
*/
|
||||
Set<PartType> getIncompatibilities(PartType reference);
|
||||
|
||||
/*
|
||||
* return the list of the requirements PartType of a PartType
|
||||
* @param reference : the PartType that we want to see the requirements,non null
|
||||
* @return the Set list of the requirements PartType
|
||||
*/
|
||||
Set<PartType> getRequirements(PartType reference);
|
||||
}
|
||||
@@ -1,34 +1,8 @@
|
||||
package src.fr.api;
|
||||
import java.util.Set;
|
||||
public interface CompatibilityManager extends CompatibilityChecker {
|
||||
|
||||
/*
|
||||
* add a incompatibles PartType to a PartType
|
||||
* @param reference : the PartType that we wish to add incompatibilities
|
||||
* @param target : Set list of incompatibilities PartType to add
|
||||
*/
|
||||
void addIncompatibilities(PartType reference,Set<PartType> target);
|
||||
|
||||
/*
|
||||
* remove a PartType of the incompatibilities of a PartType, warning,
|
||||
* warning : we must also remove the incompatibility from all the other PartTypes which the @param reference in their incompatibility
|
||||
* @param reference : the PartType that we wish to remove a incompatible PartType
|
||||
* @param target : PartType to remove of incompatibility
|
||||
*/
|
||||
void removeIncompatibility(PartType reference, PartType target);
|
||||
|
||||
|
||||
/*
|
||||
* add requirements PartType to a PartType
|
||||
* @param reference : the PartType that we wish to add requirements
|
||||
* @param target : Set list of requirement PartType to add
|
||||
*/
|
||||
void addRequirements(PartType reference, Set<PartType> target);
|
||||
|
||||
/*
|
||||
* remove a PartType of the incompatibilities of a PartType
|
||||
* @param reference : the PartType that we wish to remove a requirement PartType
|
||||
* @param target : PartType to remove of requirement
|
||||
*/
|
||||
void removeRequirement(PartType reference, PartType target);
|
||||
}
|
||||
@@ -1,18 +1,45 @@
|
||||
package src.fr.api;
|
||||
import java.util.Set;
|
||||
public interface Configuration {
|
||||
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 true if there is no compatibility issue between PartType else false
|
||||
* @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
|
||||
*/
|
||||
boolean isValid();
|
||||
public Optional<Part> getSelectionForCategory(Category category);
|
||||
|
||||
|
||||
boolean isComplete();
|
||||
Set<PartType> getSelectedParts();
|
||||
/*
|
||||
* Select a PartType to add to the configuration
|
||||
* @param chosenPart : the PartType that we wish to add to the configuration
|
||||
*/
|
||||
void selectPart(PartType chosenPart);
|
||||
PartType getSelectionForCategory(Category category);
|
||||
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
@@ -1,8 +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
8
src/fr/api/Part.java
Normal 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();
|
||||
}
|
||||
@@ -1,5 +1,12 @@
|
||||
package src.fr.api;
|
||||
public interface PartType {
|
||||
/*
|
||||
* @return name of this PartType
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/*
|
||||
* @return the category of this PartType
|
||||
*/
|
||||
Category getCategory();
|
||||
}
|
||||
42
src/fr/api/PropertyManager.java
Normal file
42
src/fr/api/PropertyManager.java
Normal 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);
|
||||
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
package src.fr.impl;
|
||||
|
||||
import src.fr.api.Category;
|
||||
|
||||
public class CategoryImpl implements src.fr.api.Category {
|
||||
public class CategoryImpl implements Category {
|
||||
private String name;
|
||||
|
||||
public CategoryImpl(String name){
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package src.fr.impl;
|
||||
|
||||
//import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import src.fr.api.PartType;
|
||||
import src.fr.api.CompatibilityChecker;
|
||||
import src.fr.api.CompatibilityManager;
|
||||
|
||||
|
||||
public class CompatibilityCheckerImpl implements src.fr.api.CompatibilityChecker {
|
||||
public class CompatibilityCheckerImpl implements CompatibilityChecker {
|
||||
|
||||
private CompatibilityManager compatibilityManager;
|
||||
|
||||
public CompatibilityCheckerImpl( CompatibilityManager compatibilityManager){
|
||||
@@ -25,4 +25,5 @@ public class CompatibilityCheckerImpl implements src.fr.api.CompatibilityChecker
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package src.fr.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
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 src.fr.api.CompatibilityManager {
|
||||
public class CompatibilityManagerImpl implements CompatibilityManager {
|
||||
|
||||
private HashMap<PartType, Set<PartType>> incompatibilities;
|
||||
private HashMap<PartType, Set<PartType>> requirements;
|
||||
@@ -41,7 +42,6 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
|
||||
//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
|
||||
@@ -201,5 +201,4 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
|
||||
Femeture_Transivite(reference, result,new HashSet<>(),reference);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,35 +3,88 @@ 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 src.fr.api.Configuration {
|
||||
private Set<PartType> selectedParts;
|
||||
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() {
|
||||
if (this.isComplete()){
|
||||
for(PartType pt: selectedParts){
|
||||
//Verifier Requirements
|
||||
for(PartType require : compatibilityManager.getRequirements(pt)){
|
||||
if(!selectedParts.contains(require)) return false;
|
||||
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);
|
||||
}
|
||||
//Verifier Incompabilities
|
||||
for(PartType incompa : compatibilityManager.getIncompatibilities(pt)){
|
||||
if(selectedParts.contains(incompa)) return false;
|
||||
}
|
||||
else test = false;
|
||||
}
|
||||
return true;
|
||||
|
||||
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 false;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isComplete() {
|
||||
if(selectedParts.size()==NB_CATEGORY){
|
||||
@@ -41,37 +94,40 @@ public class ConfigurationImpl implements src.fr.api.Configuration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getSelectedParts() {
|
||||
public Set<Part> getSelectedParts() {
|
||||
return selectedParts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectPart(PartType chosenPart) {
|
||||
Category cat_chosenPart = chosenPart.getCategory();
|
||||
|
||||
Category category_chosenPart = chosenPart.getCategory();
|
||||
//Vérifier s'il y a des pièces dans la même catégorie, si oui return
|
||||
for( PartType pt: selectedParts){
|
||||
if(pt.getCategory().equals(cat_chosenPart)){
|
||||
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");
|
||||
return;
|
||||
selectedParts.remove(pt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
selectedParts.add(chosenPart);
|
||||
PartImpl newPart = ((PartTypeImpl)chosenPart).newInstance();
|
||||
newPart.setType(chosenPart);
|
||||
selectedParts.add(newPart);
|
||||
//System.out.println(chosenPart.getName() + " : size = " + selectedParts.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartType getSelectionForCategory(Category category) {
|
||||
for( PartType pt: selectedParts){
|
||||
public Optional<Part> getSelectionForCategory(Category category) {
|
||||
for( Part pt: selectedParts){
|
||||
if(pt.getCategory().equals(category)){
|
||||
return pt;
|
||||
return Optional.of(pt);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unselectPartType(Category categoryToClear) {
|
||||
for( PartType pt: selectedParts){
|
||||
for( Part pt: selectedParts){
|
||||
if(pt.getCategory().equals(categoryToClear)){
|
||||
selectedParts.remove(pt);
|
||||
}
|
||||
@@ -84,4 +140,15 @@ public class ConfigurationImpl implements src.fr.api.Configuration {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,13 @@ 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 src.fr.api.Configurator {
|
||||
public class ConfiguratorImpl implements Configurator {
|
||||
private Set<Category> categories;
|
||||
private Set<PartType> partTypes;
|
||||
private Configuration configuration;
|
||||
|
||||
69
src/fr/impl/HtmlGenerator.java
Normal file
69
src/fr/impl/HtmlGenerator.java
Normal 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
101
src/fr/impl/PartImpl.java
Normal 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());
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,35 @@
|
||||
package src.fr.impl;
|
||||
|
||||
import src.fr.api.Category;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class PartTypeImpl implements src.fr.api.PartType {
|
||||
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, 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;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
35
src/fr/impl/Parts/Engine.java
Normal file
35
src/fr/impl/Parts/Engine.java
Normal 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;
|
||||
}
|
||||
}
|
||||
56
src/fr/impl/Parts/Exterior.java
Normal file
56
src/fr/impl/Parts/Exterior.java
Normal 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;
|
||||
}
|
||||
}
|
||||
57
src/fr/impl/Parts/Interior.java
Normal file
57
src/fr/impl/Parts/Interior.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
35
src/fr/impl/Parts/Transmission.java
Normal file
35
src/fr/impl/Parts/Transmission.java
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -1,216 +0,0 @@
|
||||
package src.fr.test;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import src.fr.impl.*;
|
||||
import src.fr.api.*;
|
||||
|
||||
|
||||
public class test {
|
||||
|
||||
Category Engine = new CategoryImpl("Engine");
|
||||
Category Transmission = new CategoryImpl("Transmission");
|
||||
Category Exterior= new CategoryImpl("Exterior");
|
||||
Category Interior= new CategoryImpl("Interior");
|
||||
|
||||
//PartType
|
||||
PartType EG100= new PartTypeImpl("EG100", Engine);
|
||||
PartType EG133= new PartTypeImpl("EG133", Engine);
|
||||
PartType EG210= new PartTypeImpl("EG210", Engine);
|
||||
PartType ED110= new PartTypeImpl("ED110", Engine);
|
||||
PartType ED180= new PartTypeImpl("ED180", Engine);
|
||||
PartType EH120= new PartTypeImpl("EH120", Engine);
|
||||
|
||||
PartType TM5= new PartTypeImpl("TM5", Transmission);
|
||||
PartType TM6= new PartTypeImpl("TM6", Transmission);
|
||||
PartType TA5= new PartTypeImpl("TA5", Transmission);
|
||||
PartType TS6= new PartTypeImpl("TS6", Transmission);
|
||||
PartType TSF7= new PartTypeImpl("TSF7", Transmission);
|
||||
PartType TC120= new PartTypeImpl("TC120", Transmission);
|
||||
|
||||
PartType XC= new PartTypeImpl("XC", Exterior);
|
||||
PartType XM= new PartTypeImpl("XM", Exterior);
|
||||
PartType XS= new PartTypeImpl("XS", Exterior);
|
||||
|
||||
PartType IN= new PartTypeImpl("IN", Interior);
|
||||
PartType IH= new PartTypeImpl("IH", Interior);
|
||||
PartType IS= new PartTypeImpl("IS", Interior);
|
||||
|
||||
CompatibilityManager cm = new CompatibilityManagerImpl();
|
||||
|
||||
PartType[] list = {EG100,EG133,EG210,ED110,ED180,EH120,TM5,TM6,TA5,TS6,TSF7,TC120,XC,XM,XS,IN,IH,IS};
|
||||
PartType[] listEn = {EG100,EG133,EG210,ED110,ED180,EH120};
|
||||
PartType[] listTr = {TM5,TM6,TA5,TS6,TSF7,TC120};
|
||||
PartType[] listEx = {XC,XM,XS};
|
||||
PartType[] listIn = {IN,IH,IS};
|
||||
|
||||
|
||||
@Before
|
||||
public void init(){
|
||||
|
||||
|
||||
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_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));
|
||||
System.out.print(cm.getRequirements(TC120).size());
|
||||
for(PartType p : cm.getRequirements(TC120)){
|
||||
System.out.print(p.getName());
|
||||
}
|
||||
|
||||
System.out.println("TC120 requirment size : " + cm.getRequirements(TC120).contains(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(){
|
||||
//Wrong test
|
||||
//assertTrue(cm.getIncompatibilities(EG100).isEmpty());
|
||||
// je crois on a TA5, TSF7, XM, XS et IS, faut tester
|
||||
cm.removeIncompatibility(EG100, EG100);
|
||||
assertFalse(cm.getIncompatibilities(EG100).contains(EG100));
|
||||
}
|
||||
|
||||
@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_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));
|
||||
}
|
||||
|
||||
}
|
||||
370
src/fr/test/test_V1.java
Normal file
370
src/fr/test/test_V1.java
Normal 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
227
src/fr/test/test_V2.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user