pass all tests, resee empty 7

This commit is contained in:
Minh VU
2024-10-24 13:14:51 +02:00
parent 1168b5377f
commit 23ea8746b1
6 changed files with 76 additions and 26 deletions

2
.idea/misc.xml generated
View File

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

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

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

16
.idea/workspace.xml generated
View File

@@ -4,7 +4,17 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<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$/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" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@@ -35,6 +45,7 @@
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"git-widget-placeholder": "dev__v1",
"ignore.virus.scanning.warn.message": "true",
"kotlin-language-version-configured": "true",
@@ -44,7 +55,7 @@
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"project.structure.last.edited": "SDKs",
"project.structure.last.edited": "Project",
"project.structure.proportion": "0.15",
"project.structure.side.proportion": "0.2",
"settings.editor.selected.configurable": "preferences.lookFeel",
@@ -93,6 +104,7 @@
<workItem from="1729595321874" duration="25000" />
<workItem from="1729743145740" duration="122000" />
<workItem from="1729757559608" duration="166000" />
<workItem from="1729764402753" duration="206000" />
</task>
<servers />
</component>

View File

@@ -1,6 +1,6 @@
package src.fr.impl;
import java.util.HashMap;
//import java.util.HashMap;
import java.util.Set;
import src.fr.api.PartType;

View File

@@ -42,6 +42,7 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
incompa.add(x);
System.out.println("Add "+reference.getName() +" incompatible with "+x.getName());
this.incompatibilities.put(reference, incompa);
// Symétrie
//Ajoute x à ref
//this.getIncompatibilities(x).add(reference);
@@ -64,7 +65,7 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
}else{
if(incompa.contains(target)){
incompa.remove(target);
this.incompatibilities.replace(reference, incompa);
// SyMéTrIe
//Remove target -> ref
//this.getIncompatibilities(target).remove(reference);
@@ -96,6 +97,7 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
require.add(x);
System.out.println("Add "+reference.getName() +" compatible with "+x.getName());
this.requirements.put(reference, require);
//Symétrie
//Ajoute x à ref
//this.getRequirements(x).add(reference);
@@ -119,7 +121,7 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
}else{
if(require.contains(target)){
require.remove(target);
this.requirements.replace(reference, require);
// SyMéTrIe
//Remove target -> ref
//this.getRequirements(target).remove(reference);
@@ -130,8 +132,8 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
}
// A -> B -> C -> A, D -> B
//bool verify requirement (1) or incompatible (0)
private void Femeture_Transivite(PartType reference, Set<PartType> result, Set<PartType> visited, boolean bool){
//erquirement only
private void Femeture_Transivite(PartType reference, Set<PartType> result, Set<PartType> visited, PartType start){
//Condition de quitter la boucle
if(visited.contains(reference)){
return;
@@ -140,42 +142,63 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
}
Set<PartType> list = null;
if(bool==true){ // requirement
//Get all requirement of A (in example is B)
list = this.requirements.get(reference);
}else{ //incompatible
list = this.incompatibilities.get(reference);
}
//Get all requirement of A (in example is B)
list = this.requirements.get(reference);
if(list != null){ // list = {B}
for(PartType pt: list){
if(!result.contains(pt)){
if(!result.contains(pt)&& pt !=start){
result.add(pt);
}
Femeture_Transivite(pt,result,visited,bool);
Femeture_Transivite(pt,result,visited,reference);
}
}
}
private void check_All_Catalog(PartType reference, Set<PartType> result, boolean bool){
if(bool){ //
}
}
@Override
public Set<PartType> getIncompatibilities(PartType reference) {
Set<PartType> result = new HashSet<>();
Femeture_Transivite(reference, result,new HashSet<>(),false);
// Remove the case of result become null
Set<PartType> directIncompa = this.incompatibilities.get(reference);
if(directIncompa!=null){
result.addAll(directIncompa);
}
// Collect the requirements list
Set<PartType> requirements = new HashSet<>();
Femeture_Transivite(reference, requirements,new HashSet<>(),reference);
for(Map.Entry<PartType, Set<PartType>> entry : this.incompatibilities.entrySet()){
// check start
if(entry.getValue().contains(reference)){
result.add(entry.getKey());
}
// check incompatible of A's requirements
for(PartType pt: requirements){
// In Catalog of pt
if(entry.getValue().contains(pt)){
result.add(entry.getKey());
}
// Direct of pt
Set<PartType> direct_pt = this.incompatibilities.get(pt);
if(direct_pt!=null){
result.addAll(direct_pt);
}
}
}
return result;
}
}
@Override
public Set<PartType> getRequirements(PartType reference) {
Set<PartType> result = new HashSet<>();
Femeture_Transivite(reference, result,new HashSet<>(),true);
Femeture_Transivite(reference, result,new HashSet<>(),reference);
return result;
}

View File

@@ -149,6 +149,11 @@ public class test {
@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));
@@ -173,7 +178,9 @@ public class test {
@Test
public void test_Remove_Empty_7(){
assertTrue(cm.getIncompatibilities(EG100).isEmpty());
//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));
}