Commit 58553969 authored by Arthur POIGNONNEC's avatar Arthur POIGNONNEC

Merge branch 'master' of https://gvipers.imt-lille-douai.fr/arthur.poignonnec/geometry

# Conflicts:
#	garage/src/Option/Option.java
#	garage/src/vehicle/part/engine/Engine.java
parent cd9bde91
package garage;
public class ExecutionFailedException extends Exception{
public ExecutionFailedException(String message) {
super(message);
}
}
......@@ -16,4 +16,34 @@ public class Task {
this.args = args;
this.t = t;
}
//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();
try {
Method m = obj.getClass().getMethod(method, mArgs);
m.invoke(obj, args.toArray());
}catch(Exception e){
throw new ExecutionFailedException(e.getMessage());
}
}
// GETTERS
public Object getObj() {
return obj;
}
public String getMethod() {
return method;
}
public List<Object> getArgs() {
return args;
}
public Integer getT() {
return t;
}
}
......@@ -17,47 +17,60 @@ public class TestBench {
vehicle = null;
}
public void addVehicle(Vehicle vehicle){
if(this.vehicle == null){
public void addVehicle(Vehicle vehicle) {
if (this.vehicle == null) {
this.vehicle = vehicle;
}else{
} else {
System.out.println("A car is already on the testbench");
}
}
public void removeVehicle(){
if(this.vehicle != null){
public void removeVehicle() {
if (this.vehicle != null) {
this.vehicle = null;
}else{
} else {
System.out.println("No vehicle in the test bench.");
}
}
public Vehicle swapVehicle(Vehicle vehicule){
if(this.vehicle != null){
public Vehicle swapVehicle(Vehicle vehicule) {
if (this.vehicle != null) {
Vehicle temp = this.vehicle;
this.vehicle = vehicule;
return temp;
}else{
} else {
System.out.println("No vehicle in the test bench.");
return null;
}
}
public void addTask(Task task){
public void addTask(Task task) {
tasks.add(task);
}
public void removeTask(Task task){
public void removeTask(Task task) {
tasks.remove(task);
}
public Vehicle getVehicle(){
public Vehicle getVehicle() {
return this.vehicle;
}
public List<Task> getTasks(){
public List<Task> getTasks() {
return tasks;
}
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());
}
});
}
}
}
package vehicle.part.pedal;
public interface Pedal {
import vehicle.part.engine.Engine;
void setState(Double pressure);
public interface Pedal {
void release();
void update();
void setState(Double pressure);
Double getState();
}
......@@ -9,7 +9,7 @@ public class PedalAccelerator implements Pedal{
public PedalAccelerator(Engine engine) {
this.engine = engine;
this.state = state;
this.state = 0d;
}
@Override
......@@ -17,6 +17,15 @@ public class PedalAccelerator implements Pedal{
this.state = pressure;
}
@Override
public Double getState() {
return state;
}
public Engine getEngine() {
return engine;
}
@Override
public void release() {
state = 0d;
......@@ -26,4 +35,5 @@ public class PedalAccelerator implements Pedal{
public void update() {
}
}
package vehicle.part.pedal;
import vehicle.part.brake.Brake;
import vehicle.part.engine.Engine;
import java.util.List;
......@@ -18,6 +19,11 @@ public class PedalBrake implements Pedal{
state = pressure;
}
@Override
public Double getState() {
return state;
}
@Override
public void release() {
state = 0d;
......
package vehicle.part.pedal;
import vehicle.part.engine.Engine;
import vehicle.part.gearbox.GearBox;
import vehicle.part.gearbox.GearBoxManual;
......@@ -18,6 +19,11 @@ public class PedalClutch implements Pedal{
state = pressure;
}
@Override
public Double getState() {
return state;
}
@Override
public void release() {
state = 0d;
......
import garage.ExecutionFailedException;
import garage.Task;
import garage.TestBench;
import org.junit.Before;
......@@ -89,5 +90,21 @@ public class TestBenchTest {
assertEquals(0, testBench.getTasks().size());
}
@Test
public void runTest(){
testBench.addVehicle(fiat500);
testBench.addTask(task);
assertEquals(0d, fiat500.getPedals().get(0).getState());
testBench.run(10);
assertEquals(50d, fiat500.getPedals().get(0).getState());
}
@Test
public void runWrongTaskTest(){
testBench.addVehicle(fiat500);
task = new Task(fiat500.getPedals().get(0), "setStat", Arrays.asList(50d), 5);
testBench.addTask(task);
testBench.run(10);
}
}
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