ajout de prix pour les Part
This commit is contained in:
@@ -62,8 +62,8 @@ public class ConfigurationImpl implements Configuration {
|
||||
}
|
||||
return test;
|
||||
}
|
||||
|
||||
public int getPriceTotal(){
|
||||
/*
|
||||
public int getTotalPrice(){
|
||||
int prix_final=0;
|
||||
if(this.isValid()){
|
||||
for(Part pt: selectedParts){
|
||||
@@ -77,6 +77,18 @@ public class ConfigurationImpl implements Configuration {
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
}*/
|
||||
|
||||
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
|
||||
|
||||
@@ -15,8 +15,8 @@ import src.fr.api.PartType;
|
||||
|
||||
public class PartImpl implements Part {
|
||||
|
||||
private PartType type;
|
||||
private int price;
|
||||
protected PartType type;
|
||||
protected int price;
|
||||
|
||||
/*public PartImpl(PartType type){
|
||||
this.type = type;
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
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 Engine extends PartImpl {
|
||||
@@ -7,6 +12,23 @@ public class Engine extends PartImpl {
|
||||
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;
|
||||
this.price = prices.get(type.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
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<>();
|
||||
@@ -39,4 +50,10 @@ public class Exterior extends PartImpl {
|
||||
public void setColor(String newColor){
|
||||
this.color = newColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(PartType type){
|
||||
this.type = type;
|
||||
this.price = prices.get(type.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
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;
|
||||
|
||||
|
||||
@@ -9,6 +12,14 @@ 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<>();
|
||||
@@ -36,6 +47,10 @@ public class Interior extends PartImpl {
|
||||
this.color = newColor;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setType(PartType type){
|
||||
this.type = type;
|
||||
this.price = prices.get(type.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package src.fr.impl.Parts;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import src.fr.api.PartType;
|
||||
import src.fr.impl.PartImpl;
|
||||
|
||||
public class Transmission extends PartImpl {
|
||||
@@ -7,6 +10,23 @@ public class Transmission extends PartImpl {
|
||||
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;
|
||||
this.price = prices.get(type.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ public class test_V1 {
|
||||
cm.addRequirements(IS, ISRequirement);
|
||||
}
|
||||
|
||||
//compatibilitiesManager
|
||||
|
||||
@Test
|
||||
public void test_Incompatibilities_Simple_1(){
|
||||
@@ -208,4 +209,96 @@ public class test_V1 {
|
||||
assertTrue(cm.getIncompatibilities(TSF7).contains(ED110));
|
||||
}
|
||||
|
||||
//Configuration
|
||||
|
||||
@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_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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -95,99 +95,6 @@ public class test_V2 {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@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_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_Property(){
|
||||
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
||||
@@ -213,4 +120,21 @@ public class test_V2 {
|
||||
assertTrue(config1.getPart(exterior).getProperty("color").isEmpty());
|
||||
assertTrue(config1.isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_Price(){
|
||||
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
||||
config1.selectPart(EG210);
|
||||
assertTrue(((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);
|
||||
assertTrue(config1.getTotalPrice()==52500);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user