229 lines
8.5 KiB
Java
229 lines
8.5 KiB
Java
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.impl.Parts.*;
|
|
import src.fr.api.*;
|
|
|
|
|
|
public class test {
|
|
CategoryImpl engine = new CategoryImpl("Engine");
|
|
CategoryImpl transmission = new CategoryImpl("Transmission");
|
|
CategoryImpl exterior = new CategoryImpl("Exterior");
|
|
CategoryImpl interior = new CategoryImpl("Interior");
|
|
|
|
|
|
|
|
|
|
PartType EG100PartType = new PartTypeImpl("EG100",Engine.class,engine);
|
|
|
|
Engine EG100 = new Engine("EG100",engine,3000);
|
|
Engine EG133 = new Engine("EG133",engine,8000);
|
|
Engine EG210= new Engine("EG210", engine,15000);
|
|
Engine ED110= new Engine("ED110", engine,2000);
|
|
Engine ED180= new Engine("ED180", engine,4000);
|
|
Engine EH120= new Engine("EH120", engine,15000);
|
|
|
|
Transmission TM5= new Transmission("TM5", transmission,2000);
|
|
Transmission TM6= new Transmission("TM6", transmission,4000);
|
|
Transmission TA5= new Transmission("TA5", transmission,7000);
|
|
Transmission TS6= new Transmission("TS6", transmission,10000);
|
|
Transmission TSF7= new Transmission("TSF7", transmission,15000);
|
|
Transmission TC120= new Transmission("TC120", transmission,1000);
|
|
|
|
Exterior XC= new Exterior("XC", exterior,0);
|
|
Exterior XM= new Exterior("XM", exterior,1000);
|
|
Exterior XS= new Exterior("XS", exterior,10000);
|
|
|
|
Interior IN= new Interior("IN", interior,0);
|
|
Interior IH= new Interior("IH", interior,800);
|
|
Interior IS= new Interior("IS", interior,2500);
|
|
|
|
|
|
|
|
|
|
CompatibilityManager cm = new CompatibilityManagerImpl();
|
|
@Before
|
|
public void init(){
|
|
Set<PartType> EH120Requirement = new HashSet<PartType>();
|
|
EH120Requirement.add(TC120.getType());
|
|
|
|
Set<PartType> TA5Incompatibilities = new HashSet<PartType>();
|
|
TA5Incompatibilities.add(EG100.getType());
|
|
|
|
Set<PartType> TSF7Incompatibilities = new HashSet<PartType>();
|
|
TSF7Incompatibilities.add(EG100.getType());
|
|
TSF7Incompatibilities.add(EG133.getType());
|
|
TSF7Incompatibilities.add(ED110.getType());
|
|
|
|
Set<PartType> TC120Requirement = new HashSet<PartType>();
|
|
TC120Requirement.add(EH120.getType());
|
|
|
|
Set<PartType> XCIncompatibilities = new HashSet<PartType>();
|
|
XCIncompatibilities.add(EG210.getType());
|
|
|
|
Set<PartType> XMIncompatibilities = new HashSet<PartType>();
|
|
XMIncompatibilities.add(EG100.getType());
|
|
|
|
Set<PartType> XSIncompatibilities = new HashSet<PartType>();
|
|
XSIncompatibilities.add(EG100.getType());
|
|
Set<PartType> XSRequirement = new HashSet<PartType>();
|
|
XSRequirement.add(IS.getType());
|
|
|
|
Set<PartType> ISIncompatibilities = new HashSet<PartType>();
|
|
ISIncompatibilities.add(EG100.getType());
|
|
ISIncompatibilities.add(TM5.getType());
|
|
Set<PartType> ISRequirement = new HashSet<PartType>();
|
|
ISRequirement.add(XS.getType());
|
|
|
|
cm.addRequirements(EH120.getType(), EH120Requirement);
|
|
cm.addIncompatibilities(TA5.getType(), TA5Incompatibilities);
|
|
cm.addIncompatibilities(TSF7.getType(), TSF7Incompatibilities);
|
|
cm.addRequirements(TC120.getType(), TC120Requirement);
|
|
cm.addIncompatibilities(XC.getType(), XCIncompatibilities);
|
|
cm.addIncompatibilities(XM.getType(), XMIncompatibilities);
|
|
cm.addIncompatibilities(XS.getType(), XSIncompatibilities);
|
|
cm.addRequirements(XS.getType(), XSRequirement);
|
|
cm.addIncompatibilities(IS.getType(), ISIncompatibilities);
|
|
cm.addRequirements(IS.getType(), ISRequirement);
|
|
|
|
|
|
|
|
//EG100.setProperty("prix","5€");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
@Test
|
|
public void test_Incompatibilities_Simple_1(){
|
|
assertTrue(cm.getIncompatibilities(TA5.getType()).contains(EG100.getType()));
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
public void test_multiple_Incompatibilities_Simple_2(){
|
|
assertTrue(
|
|
cm.getIncompatibilities(TSF7.getType()).contains(EG100.getType())&&
|
|
cm.getIncompatibilities(TSF7.getType()).contains(EG133.getType())&&
|
|
cm.getIncompatibilities(TSF7.getType()).contains(ED110.getType())
|
|
);
|
|
}
|
|
|
|
@Test
|
|
public void test_Requirements_3(){
|
|
assertTrue(cm.getRequirements(EH120.getType()).contains(TC120.getType()));
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
* A <-> B
|
|
* if A -> B then B -> A
|
|
*/
|
|
@Test
|
|
public void test_Incompatibilities_Complex_4(){
|
|
System.out.println("size EG100 incompatibilities : "+cm.getIncompatibilities(EG100.getType()).size());
|
|
assertTrue(cm.getIncompatibilities(EG100.getType()).contains(IS.getType()));
|
|
assertTrue(cm.getIncompatibilities(EG100.getType()).contains(XS.getType()));
|
|
}
|
|
|
|
/*
|
|
* 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.getType()).contains(EG100.getType()));
|
|
System.out.println("size XS incompatibilities : " + cm.getIncompatibilities(XS.getType()).size());
|
|
assertTrue(cm.getIncompatibilities(XS.getType()).contains(TM5.getType()));
|
|
}
|
|
|
|
|
|
/*
|
|
* Require Require Require
|
|
* if A -> B && B -> C then A -> C
|
|
*/
|
|
@Test
|
|
public void test_Incompatibilities_Complex_7(){
|
|
cm.addRequirements(TC120.getType(), Set.of(XC.getType()));
|
|
assertTrue(cm.getRequirements(TC120.getType()).contains(XC.getType()));
|
|
assertTrue(cm.getRequirements(EH120.getType()).contains(XC.getType()));
|
|
cm.removeRequirement(TC120.getType(), XC.getType());
|
|
}
|
|
|
|
@Test
|
|
public void test_Empty_Requirements_5(){
|
|
assertTrue(cm.getRequirements(ED180.getType()).isEmpty());
|
|
}
|
|
|
|
@Test
|
|
public void test_Remove_and_restore_Incompatibilities_6(){
|
|
assertTrue(cm.getIncompatibilities(XM.getType()).contains(EG100.getType()));
|
|
cm.removeIncompatibility(XM.getType(), EG100.getType());
|
|
assertFalse(cm.getIncompatibilities(XM.getType()).contains(EG100.getType()));
|
|
Set<PartType> setEG100 = new HashSet<PartType>();
|
|
setEG100.add(EG100.getType());
|
|
cm.addIncompatibilities(XM.getType(), setEG100);
|
|
assertTrue(cm.getIncompatibilities(XM.getType()).contains(EG100.getType()));
|
|
}
|
|
|
|
@Test
|
|
public void test_Remove_Empty_7(){
|
|
assertTrue(cm.getIncompatibilities(EH120.getType()).isEmpty());
|
|
cm.removeIncompatibility(EH120.getType(), EG100.getType());
|
|
assertTrue(cm.getIncompatibilities(EH120.getType()).isEmpty()); }
|
|
|
|
@Test
|
|
public void test_Remove_and_restore_Requirements_8(){
|
|
assertTrue(cm.getRequirements(EH120.getType()).contains(TC120.getType()));
|
|
cm.removeRequirement(EH120.getType(), TC120.getType());
|
|
assertFalse(cm.getRequirements(EH120.getType()).contains(TC120.getType()));
|
|
Set<PartType> setTC120 = new HashSet<PartType>();
|
|
setTC120.add(TC120.getType());
|
|
cm.addRequirements(EH120.getType(), setTC120);
|
|
assertTrue(cm.getRequirements(EH120.getType()).contains(TC120.getType()));
|
|
}
|
|
|
|
@Test
|
|
public void test_remove_incompatibilities_but_no_removable(){
|
|
assertTrue(cm.getIncompatibilities(EG100.getType()).contains(IS.getType()));
|
|
cm.removeIncompatibility(EG100.getType(), IS.getType());
|
|
assertTrue(cm.getIncompatibilities(EG100.getType()).contains(IS.getType()));
|
|
}
|
|
|
|
@Test
|
|
public void test_Add_and_restore_Incompatibilities_9(){
|
|
assertTrue(cm.getIncompatibilities(TSF7.getType()).contains(EG100.getType()));
|
|
assertTrue(cm.getIncompatibilities(TSF7.getType()).contains(EG133.getType()));
|
|
assertTrue(cm.getIncompatibilities(TSF7.getType()).contains(ED110.getType()));
|
|
cm.removeIncompatibility(TSF7.getType(), EG100.getType());
|
|
assertFalse(cm.getIncompatibilities(TSF7.getType()).contains(EG100.getType()));
|
|
assertTrue(cm.getIncompatibilities(TSF7.getType()).contains(EG133.getType()));
|
|
assertTrue(cm.getIncompatibilities(TSF7.getType()).contains(ED110.getType()));
|
|
Set<PartType> setEG100 = new HashSet<PartType>();
|
|
setEG100.add(EG100.getType());
|
|
cm.addIncompatibilities(TSF7.getType(), setEG100);
|
|
assertTrue(cm.getIncompatibilities(TSF7.getType()).contains(EG100.getType()));
|
|
assertTrue(cm.getIncompatibilities(TSF7.getType()).contains(EG133.getType()));
|
|
assertTrue(cm.getIncompatibilities(TSF7.getType()).contains(ED110.getType()));
|
|
}
|
|
|
|
|
|
@Test
|
|
public void test_PropertyInteriorColor(){
|
|
XS.setColor("red");
|
|
assertTrue(XS.getColor()=="red");
|
|
}
|
|
|
|
|
|
} |