Commit a8c2a6a2 authored by Jakob Schöttl's avatar Jakob Schöttl
Browse files

Add tests for choosing seat

parent c8a17a9c
......@@ -11,7 +11,9 @@ import org.vadere.simulator.models.seating.trainmodel.Seat;
import org.vadere.simulator.models.seating.trainmodel.SeatGroup;
import org.vadere.simulator.models.seating.trainmodel.TrainModel;
import org.vadere.state.attributes.models.AttributesSeating;
import org.vadere.state.attributes.models.seating.SeatFacingDirection;
import org.vadere.state.attributes.models.seating.SeatRelativePosition;
import org.vadere.state.attributes.models.seating.SeatSide;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.data.TallySheet;
......@@ -70,6 +72,67 @@ public class TestChooseSeat {
}
}
@StatisticalTestCase
@Test
public void testChooseSeat2OnlySideChoice() {
final int nTrials = 1000;
fillSeatGroup(seatGroup, 0, 1);
final TallySheet<Seat> tallySheet = runChooseSeat(nTrials);
final Seat seat = seatGroup.getSeat(2); // window seat
Map<SeatSide, Double> map = FractionProbabilityNormalization.normalize(new AttributesSeating().getSeatChoice2Side());
assertEquals(map.get(SeatSide.WINDOW),
(double) tallySheet.getCount(seat) / nTrials, 0.05);
}
@StatisticalTestCase
@Test
public void testChooseSeat2OnlyDirectionChoice() {
final int nTrials = 1000;
fillSeatGroup(seatGroup, 0, 2);
final TallySheet<Seat> tallySheet = runChooseSeat(nTrials);
final Seat seat = seatGroup.getSeat(3); // forward facing seat
Map<SeatFacingDirection, Double> map = FractionProbabilityNormalization.normalize(new AttributesSeating().getSeatChoice2FacingDirection());
assertEquals(map.get(SeatFacingDirection.FORWARD),
(double) tallySheet.getCount(seat) / nTrials, 0.05);
}
@StatisticalTestCase
@Test
public void testChooseSeat2Both() {
final int nTrials = 1000;
fillSeatGroup(seatGroup, 0, 3);
final TallySheet<Seat> tallySheet = runChooseSeat(nTrials);
final Seat seat = seatGroup.getSeat(1); // forward facing seat
assertEquals(0.5, (double) tallySheet.getCount(seat) / nTrials, 0.05);
}
@Test
public void testChooseSeat3() {
clearSeatGroup(seatGroup);
fillSeatGroup(seatGroup, 1, 2, 3);
assertEquals(seatGroup.getSeat(0), model.chooseSeat(seatGroup));
clearSeatGroup(seatGroup);
fillSeatGroup(seatGroup, 0, 2, 3);
assertEquals(seatGroup.getSeat(1), model.chooseSeat(seatGroup));
clearSeatGroup(seatGroup);
fillSeatGroup(seatGroup, 0, 2, 1);
assertEquals(seatGroup.getSeat(3), model.chooseSeat(seatGroup));
}
@Test(expected=IllegalStateException.class)
public void testChooseSeat4() {
fillSeatGroup(seatGroup, 0, 1, 2, 3);
model.chooseSeat(seatGroup);
}
private TallySheet<Seat> runChooseSeat(final int nTrials) {
TallySheet<Seat> tallySheet = new TallySheet<>();
for (int i = 0; i < nTrials; i++) {
......
......@@ -41,16 +41,24 @@ public class AttributesSeating extends Attributes {
// TODO make this autogenerated
seatGroupChoice = new ArrayList<>(2);
seatGroupChoice.add(new ValueWithProbabilityFraction<>(true, 64.0));
seatGroupChoice.add(new ValueWithProbabilityFraction<>(false, 11.0));
addFraction(seatGroupChoice, true, 64.0);
addFraction(seatGroupChoice, false, 11.0);
seatChoice0 = new double[] { 2, 1, 14, 5 };
seatChoice1 = new ArrayList<>(3);
seatChoice1.add(new ValueWithProbabilityFraction<>(SeatRelativePosition.DIAGONAL, 31));
seatChoice1.add(new ValueWithProbabilityFraction<>(SeatRelativePosition.ACROSS, 8));
seatChoice1.add(new ValueWithProbabilityFraction<>(SeatRelativePosition.NEXT, 3));
addFraction(seatChoice1, SeatRelativePosition.DIAGONAL, 31);
addFraction(seatChoice1, SeatRelativePosition.ACROSS, 8);
addFraction(seatChoice1, SeatRelativePosition.NEXT, 3);
seatChoice2Side = new ArrayList<>(2);
addFraction(seatChoice2Side, SeatSide.AISLE, 3);
addFraction(seatChoice2Side, SeatSide.WINDOW, 1);
seatChoice2FacingDirection = new ArrayList<>(2);
addFraction(seatChoice2FacingDirection, SeatFacingDirection.FORWARD, 5);
addFraction(seatChoice2FacingDirection, SeatFacingDirection.BACKWARD, 1);
}
public String getTrainGeometry() {
......@@ -82,4 +90,8 @@ public class AttributesSeating extends Attributes {
return list.stream().map(ValueWithProbabilityFraction::toPair).collect(Collectors.toList());
}
private <T> void addFraction(List<ValueWithProbabilityFraction<T>> list, T value, double fraction) {
list.add(new ValueWithProbabilityFraction<>(value, fraction));
}
}
......@@ -8,7 +8,8 @@ import java.lang.annotation.Target;
/**
* This annotation can be used to mark statistical JUnit test methods that use a
* random generator and can fail with a certain probability.
* random generator and can fail with a certain probability. This is only for
* documentation.
*
*/
@Retention(SOURCE)
......
Supports Markdown
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