Package rinde.sim.event

Examples of rinde.sim.event.ListenerEventHistory


   * Tests transitions.
   */
  @SuppressWarnings({ "rawtypes", "unchecked" })
  @Test
  public void testTransition() {
    final ListenerEventHistory history = new ListenerEventHistory();
    fsm.getEventAPI()
        .addListener(history, StateMachine.StateMachineEvent.values());

    // start in STOPPED state
    assertEquals(stopState, fsm.getCurrentState());
    fsm.handle(Events.START, CONTEXT);
    assertEquals(startState, fsm.getCurrentState());
    // history.getHistory()

    // nothing should happen
    fsm.handle(CONTEXT);
    assertEquals(startState, fsm.getCurrentState());

    // should go to SPECIAL and back to STARTED immediately
    history.clear();
    fsm.handle(Events.SPEZIAL, SPECIAL_CONTEXT);
    assertEquals(startState, fsm.getCurrentState());
    assertEquals(2, history.getHistory().size());
    assertTrue(((StateTransitionEvent) history.getHistory().get(0))
        .equalTo(startState, Events.SPEZIAL, specialState));
    assertTrue(((StateTransitionEvent) history.getHistory().get(1))
        .equalTo(specialState, Events.START, startState));

    // testing the equalTo method
    assertFalse(((StateTransitionEvent) history.getHistory().get(1))
        .equalTo(startState, Events.START, startState));
    assertFalse(((StateTransitionEvent) history.getHistory().get(1))
        .equalTo(specialState, Events.PAUSE, startState));
    assertFalse(((StateTransitionEvent) history.getHistory().get(1))
        .equalTo(specialState, Events.START, specialState));

    // go to SPECIAL
    fsm.handle(Events.SPEZIAL, CONTEXT);
    assertEquals(specialState, fsm.getCurrentState());
View Full Code Here


  /**
   * Tests recursive transitions.
   */
  @Test
  public void testRecursiveTransitions() {
    final ListenerEventHistory history = new ListenerEventHistory();
    fsm.getEventAPI()
        .addListener(history, StateMachine.StateMachineEvent.values());

    // stopped recursive
    assertEquals(stopState, fsm.getCurrentState());
    assertTrue(stopState.handleHistory().isEmpty());
    assertTrue(stopState.onEntryHistory().isEmpty());
    assertTrue(stopState.onExitHistory().isEmpty());
    assertTrue(history.getHistory().isEmpty());

    fsm.handle(Events.RECURSIVE, CONTEXT);
    assertEquals(stopState, fsm.getCurrentState());

    assertEquals(1, stopState.handleHistory().size());
    if (explicitRecursiveTransitions) {
      assertEquals(1, stopState.onEntryHistory().size());
      assertEquals(1, stopState.onExitHistory().size());
      assertEquals(1, history.getHistory().size());
      assertEquals(
          new StateTransitionEvent<Events, Context>(fsm, stopState,
              Events.RECURSIVE, stopState),
          history.getHistory().get(0));
    }
    else {
      assertTrue(stopState.onEntryHistory().isEmpty());
      assertTrue(stopState.onExitHistory().isEmpty());
      assertTrue(history.getHistory().isEmpty());
    }
  }
View Full Code Here

  public void finiteSimulation() throws ConfigurationException,
      InterruptedException {
    final ScenarioController sc = new ScenarioController(scenario, simulator,
        new TestHandler(TestEvents.values()), 101);

    final ListenerEventHistory leh = new ListenerEventHistory();
    sc.getEventAPI().addListener(leh);
    assertFalse(sc.isScenarioFinished());
    sc.start();
    assertEquals(asList(SCENARIO_STARTED, EVENT_A, EVENT_B, EVENT_B, EVENT_A, EVENT_C, EVENT_C, SCENARIO_FINISHED), leh
        .getEventTypeHistory());

    assertTrue(sc.isScenarioFinished());
    sc.stop();
    final long before = sc.simulator.getCurrentTime();
View Full Code Here

  @Test
  public void moveToEventIssuerType() {
    final MovingRoadUser user = new TestRoadUser();
    model.addObjectAt(user, SW);

    final ListenerEventHistory list = new ListenerEventHistory();
    model.getEventAPI().addListener(list, RoadEventType.MOVE);
    assertTrue(list.getHistory().isEmpty());
    model.moveTo(user, NW, TimeLapseFactory.create(0, 10));

    assertEquals(1, list.getHistory().size());

    assertEquals(RoadEventType.MOVE, list.getHistory().get(0).getEventType());
    assertEquals(model, list.getHistory().get(0).getIssuer());

  }
View Full Code Here

  @Test
  public void followPathEventIssuerType() {
    final MovingRoadUser user = new TestRoadUser();
    model.addObjectAt(user, SW);

    final ListenerEventHistory list = new ListenerEventHistory();
    model.getEventAPI().addListener(list, RoadEventType.MOVE);
    assertTrue(list.getHistory().isEmpty());
    model.followPath(user, newLinkedList(asList(SW, SE, NE, NW)),
        TimeLapseFactory.create(0, 10));

    assertEquals(1, list.getHistory().size());

    assertEquals(RoadEventType.MOVE, list.getHistory().get(0).getEventType());
    assertEquals(model, list.getHistory().get(0).getIssuer());
  }
View Full Code Here

  /**
   * Test diversion with REROUTE events.
   */
  @Test
  public void diversionTestInGotoState2() {
    final ListenerEventHistory leh = new ListenerEventHistory();
    d.stateMachine.getEventAPI().addListener(leh,
        StateMachineEvent.STATE_TRANSITION);
    assertEquals(0, leh.getHistory().size());
    assertFalse(d.gotoState.destination.isPresent());
    assertFalse(d.gotoState.prevDestination.isPresent());

    d.setRoute(asList(p1));
    assertEquals(diversionIsAllowed, d.isDiversionAllowed());
    assertEquals(Optional.absent(), d.newRoute);
    tick(5, 6);
    assertEquals(d.gotoState, d.stateMachine.getCurrentState());
    assertEquals(1, leh.getHistory().size());
    assertEquals(p1, d.gotoState.getDestination());
    assertFalse(d.gotoState.prevDestination.isPresent());

    @SuppressWarnings("unchecked")
    final StateTransitionEvent<StateEvent, RouteFollowingVehicle> ev1 = ((StateTransitionEvent<StateEvent, RouteFollowingVehicle>) leh
        .getHistory().get(0));
    assertEquals(DefaultEvent.GOTO, ev1.event);
    assertEquals(d.waitState, ev1.previousState);
    assertEquals(d.gotoState, ev1.newState);

    assertEquals(d.gotoState, d.stateMachine.getCurrentState());
    assertEquals(p1, d.getRoute().iterator().next());

    boolean fail = false;
    try {
      d.setRoute(asList(p2));
    } catch (final IllegalArgumentException e) {
      fail = true;
    }
    assertEquals(!diversionIsAllowed && !allowDelayedRouteChanges, fail);

    tick(4, 5);
    assertEquals(d.gotoState, d.stateMachine.getCurrentState());

    if (diversionIsAllowed) {
      assertEquals(2, leh.getHistory().size());
      @SuppressWarnings("unchecked")
      final StateTransitionEvent<StateEvent, RouteFollowingVehicle> ev2 = ((StateTransitionEvent<StateEvent, RouteFollowingVehicle>) leh
          .getHistory().get(1));
      assertEquals(DefaultEvent.REROUTE, ev2.event);
      assertEquals(d.gotoState, ev2.previousState);
      assertEquals(d.gotoState, ev2.newState);

      assertEquals(p2, d.gotoState.getDestination());
      assertEquals(p1, d.gotoState.getPreviousDestination());
    }
    else {
      assertEquals(1, leh.getHistory().size());
      assertEquals(p1, d.gotoState.getDestination());
      assertFalse(d.gotoState.prevDestination.isPresent());
    }
  }
View Full Code Here

TOP

Related Classes of rinde.sim.event.ListenerEventHistory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.