Skip to content
This repository has been archived by the owner on Mar 3, 2019. It is now read-only.

Commit

Permalink
Test d'actionneurs
Browse files Browse the repository at this point in the history
  • Loading branch information
PFGimenez committed Feb 22, 2017
1 parent 57a9b24 commit 8ee2428
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
8 changes: 4 additions & 4 deletions pc/src/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ public void baisseFilet() throws InterruptedException
filetBaisse = true;
}

public void filetMiHauteur() throws InterruptedException
public void bougeFiletMiChemin() throws InterruptedException
{
bloque("bougeFiletMiChemin");
filetBaisse = true;
}

public void remonteFilet() throws InterruptedException
public void leveFilet() throws InterruptedException
{
bloque("leveFilet");
filetBaisse = false;
Expand All @@ -120,9 +120,9 @@ public void fermeFilet() throws InterruptedException
// filetPlein = false; // TODO
}

public void ejectBalles() throws InterruptedException
public void ejecteBalles() throws InterruptedException
{
bloque("ejecte", !symetrie);
bloque("ejecteBalles", !symetrie);
filetPlein = false;
}

Expand Down
16 changes: 11 additions & 5 deletions pc/src/robot/RobotReal.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,26 +195,32 @@ protected void bloque(String nom, Object... param) throws InterruptedException
{
Ticket.State etat;
Ticket t = null;
Class<?>[] paramClasses = new Class[param.length];
for(int i = 0; i < param.length; i++)
paramClasses[i] = param[i].getClass();
Class<?>[] paramClasses = null;
if(param.length > 0)
{
paramClasses = new Class[param.length];
for(int i = 0; i < param.length; i++)
paramClasses[i] = param[i].getClass();
}
long avant = System.currentTimeMillis();
int nbEssai = nbRetente;
do {
try {
t = (Ticket) BufferOutgoingOrder.class.getMethod(nom, paramClasses.length == 0 ? null : paramClasses).invoke(out, param.length == 0 ? null : param);
t = (Ticket) BufferOutgoingOrder.class.getMethod(nom, paramClasses).invoke(out, param.length == 0 ? null : param);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
e.printStackTrace();
}
synchronized(t)
{
if(t.isEmpty())
t.wait();
etat = t.getAndClear();
}
etat = t.getAndClear();
nbEssai--;
if(etat == Ticket.State.KO)
log.warning("Problème pour l'actionneur "+nom+" : on "+(nbEssai >= 0 ? "retente." : "abandonne."));
} while(nbEssai >= 0 && etat == Ticket.State.KO);
log.debug("Temps d'exécution de "+nom+" : "+(System.currentTimeMillis()-avant));
}

}
4 changes: 2 additions & 2 deletions pc/src/scripts/ScriptCratere.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void setUpCercleArrivee()
protected void run(GameState<? extends Robot> state) throws InterruptedException, UnableToMoveException
{
state.robot.avance(-20);
state.robot.filetMiHauteur();
state.robot.bougeFiletMiChemin();
state.robot.ouvreFilet();
state.robot.baisseFilet();
state.table.setDone(element, EtatElement.PRIS_PAR_NOUS);
Expand All @@ -75,7 +75,7 @@ protected void run(GameState<? extends Robot> state) throws InterruptedException
protected void termine(GameState<? extends Robot> state) throws InterruptedException, UnableToMoveException
{
state.robot.fermeFilet();
state.robot.remonteFilet();
state.robot.leveFilet();
state.robot.avance(20);
}

Expand Down
4 changes: 2 additions & 2 deletions pc/src/serie/BufferOutgoingOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public synchronized Ticket beginFollowTrajectory(Speed vitesseInitiale, boolean
public synchronized Ticket immobilise()
{
if(debugSerie)
log.debug("Stop !");
log.warning("Stop !");
stop = new Ticket();
notify();
return stop;
Expand Down Expand Up @@ -222,7 +222,7 @@ public synchronized Ticket fermeFilet()
/**
* Ejecte les balles
*/
public synchronized Ticket ejecte(Boolean droite) // la réflectivité demande d'utiliser Boolean et pas boolean
public synchronized Ticket ejecteBalles(Boolean droite) // la réflectivité demande d'utiliser Boolean et pas boolean
{
Ticket t = new Ticket();
bufferBassePriorite.add(new Order(droite ? OutOrder.EJECT_RIGHT_SIDE : OutOrder.EJECT_LEFT_SIDE, t));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
*/

public class JUnit_Actionneurs extends JUnit_Test {
public class JUnit_Robot extends JUnit_Test {

private RobotReal robot;

Expand All @@ -43,8 +43,13 @@ public void setUp() throws Exception {
@Test
public void test_actionneurs() throws Exception
{
robot.ejectBalles();
robot.baisseFilet();
robot.leveFilet();
robot.bougeFiletMiChemin();
robot.ejecteBalles();
robot.rearme();
robot.ouvreFilet();
robot.fermeFilet();
robot.traverseBascule();
}
}
6 changes: 4 additions & 2 deletions pc/src/tests/lowlevel/JUnit_Serie.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,19 @@ public void test_actionneurs() throws Exception
Thread.sleep(2000);
data.bougeFiletMiChemin();
Thread.sleep(2000);
data.ejecte(true);
data.ejecteBalles(true);
Thread.sleep(2000);
data.rearme(true);
Thread.sleep(2000);
data.ejecte(false);
data.ejecteBalles(false);
Thread.sleep(2000);
data.rearme(false);
Thread.sleep(2000);
data.ouvreFilet();
Thread.sleep(2000);
data.fermeFilet();
Thread.sleep(2000);
data.traverseBascule();
Thread.sleep(2000);
}
}

0 comments on commit 8ee2428

Please sign in to comment.