13 Commits

Author SHA1 Message Date
Rochas
04fdcc5d22 correction test 2024-12-20 21:24:43 +01:00
Rochas
1569746582 read me terminé + nouveau test 2024-12-20 21:01:30 +01:00
Rochas
01970a625a début du read me 2024-12-20 19:04:22 +01:00
Rochas Thibaut
5260d58c96 Add README.md 2024-12-20 17:12:15 +00:00
Rochas
4198d7a407 assertion Junit 5 2024-12-20 14:54:23 +01:00
Rochas
beeef622b3 Merge branch 'dev_v1' of https://gitlab2.istic.univ-rennes1.fr/tuvu/cartailor into dev_v1 2024-12-20 14:53:57 +01:00
Rochas
44fe20e95c assertion Junit 5 2024-12-20 14:53:47 +01:00
Vu Tuan Minh
4880ae8b3f Update Configuration.java 2024-12-20 12:17:45 +00:00
Minh VU
6a495edaa0 add description in interface 2024-12-20 12:26:21 +01:00
Rochas
1cb536a785 correction de BeforeEach avec Junit5 2024-12-20 00:05:31 +01:00
Rochas
45d796afc6 correction confif + Junit 5 2024-12-19 23:42:06 +01:00
trochas
b8d9eb5771 modification des test mineur 2024-11-13 10:13:28 +01:00
Minh VU
141cfdf4ff improve 2024-11-11 17:50:57 +01:00
29 changed files with 193 additions and 1017 deletions

10
.gitignore vendored
View File

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

31
.idea/workspace.xml generated
View File

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

5
.vscode/settings.json vendored Normal file
View File

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

View File

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

Binary file not shown.

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>

View File

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

View File

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

View File

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

View File

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

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,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,5 +1,4 @@
package src.fr.impl; package src.fr.impl;
import src.fr.api.Category; import src.fr.api.Category;
public class CategoryImpl implements Category { public class CategoryImpl implements Category {

View File

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

View File

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

View File

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

View File

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

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

View File

@@ -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

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

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