Commit c27312fe authored by Arthur POIGNONNEC's avatar Arthur POIGNONNEC

[TEST] Ajout de tests sur le banc d'essai

parent 58553969
......@@ -19,11 +19,18 @@ public class Task {
//METHODS
public void execute() throws ExecutionFailedException {
Class[] mArgs = new Class[args.size()];
for(Integer i = 0; i < args.size(); i++) mArgs[i] = args.get(i).getClass();
Class[] mArgs = new Class[0];
if(args != null){
mArgs = new Class[args.size()];
for(Integer i = 0; i < args.size(); i++) mArgs[i] = args.get(i).getClass();
}
try {
System.out.println("Calling method " + method + " of class -> " + obj.getClass());
Method m = obj.getClass().getMethod(method, mArgs);
m.invoke(obj, args.toArray());
if(args == null) m.invoke(obj, null);
else m.invoke(obj, args.toArray());
}catch(Exception e){
throw new ExecutionFailedException(e.getMessage());
}
......
......@@ -61,16 +61,20 @@ public class TestBench {
}
public void run(Integer time) {
for (Integer t = 0; t < time; t++) {
final Integer tick = t;
tasks.stream().filter(task -> tick.equals(task.getT())).forEach(task -> {
try {
task.execute();
vehicle.update();
} catch (ExecutionFailedException e) {
System.out.println("ERROR -> " + e.getMessage());
}
});
if(vehicle != null) {
for (Integer t = 0; t < time; t++) {
final Integer tick = t;
tasks.stream().filter(task -> tick.equals(task.getT())).forEach(task -> {
try {
task.execute();
vehicle.update();
} catch (ExecutionFailedException e) {
System.out.println("ERROR -> " + e.getMessage());
}
});
}
}else{
System.out.println("Aucune véhicule sur le banc d'essai");
}
}
}
......@@ -74,6 +74,7 @@ public class Vehicle {
// METHODS /////////////////////////////////////////////////////////////////////////////////////////////////////////
public void update(){
for(Pedal p : pedals) p.update();
}
......
......@@ -6,7 +6,7 @@ import vehicle.part.frame.FrameType;
public enum VehicleModel {
FIAT_500(VehicleBrand.FIAT, "500", EngineModel.TDI_A_D, FrameType.MICRO, BrakeType.PAD_FX200, 4),
FIAT_500(VehicleBrand.FIAT, "500", EngineModel.TDI_M_D, FrameType.MICRO, BrakeType.PAD_FX200, 4),
PEUGEOT_5008(VehicleBrand.PEUGEOT, "5008", EngineModel.TDI_A_P, FrameType.SUV, BrakeType.DISC_FX200, 4);
private final VehicleBrand brand;
......
......@@ -12,4 +12,6 @@ public interface GearBox {
void reverse() throws StallException, EngineBrokenException;
public Gear getCurrentGear();
}
\ No newline at end of file
......@@ -43,4 +43,9 @@ public class GearBoxAutomatic implements GearBox {
currentGear = Gear.REVERSE;
}
}
@Override
public Gear getCurrentGear() {
return currentGear;
}
}
......@@ -95,4 +95,9 @@ public class GearBoxManual implements GearBox{
public void disengage(){
engaged = false;
}
@Override
public Gear getCurrentGear() {
return currentGear;
}
}
package vehicle.part.pedal;
public enum PedalPosition {
ACCELERATOR(0),
BRAKE(1),
CLUTCH(2);
private final Integer value;
PedalPosition(Integer value) {
this.value = value;
}
public Integer getValue() {
return value;
}
public static PedalPosition getEnum(Integer value) {
for (PedalPosition position : PedalPosition.values()) {
if (position.getValue().equals(value)) {
return position;
}
}
return null;
}
}
......@@ -2,10 +2,13 @@ import garage.ExecutionFailedException;
import garage.Task;
import garage.TestBench;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import vehicle.Vehicle;
import vehicle.VehicleModel;
import vehicle.part.gearbox.Gear;
import vehicle.part.pedal.PedalAccelerator;
import vehicle.part.pedal.PedalPosition;
import java.util.Arrays;
......@@ -107,4 +110,18 @@ public class TestBenchTest {
testBench.run(10);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Test
public void scenario1Test(){
testBench.addVehicle(fiat500);
testBench.addTask(new Task(fiat500.getPedals().get(PedalPosition.CLUTCH.getValue()), "setState", Arrays.asList(70d), 2));
testBench.addTask(new Task(fiat500.getGearBox(), "gearUp", null, 3));
testBench.addTask(new Task(fiat500.getPedals().get(PedalPosition.CLUTCH.getValue()), "setState", Arrays.asList(0d), 4));
assertEquals(Gear.NEUTRAL, fiat500.getGearBox().getCurrentGear());
testBench.run(10);
assertEquals(Gear.FIRST, fiat500.getGearBox().getCurrentGear());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment