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

Refactor tests

parent 2641d902
......@@ -44,15 +44,11 @@ public class TestChooseSeat {
final int nTrials = 1000;
TallySheet<Seat> tallySheet = runChooseSeat(nTrials);
final double[] fractions = new AttributesSeating().getSeatChoice0();
double sum = 0;
for (double d : fractions) {
sum += d;
}
final double[] probabilities = FractionProbabilityNormalization.normalize(new AttributesSeating().getSeatChoice0());
for (int i = 0; i < tallySheet.getKeys().size(); i++) {
Seat s = seatGroup.getSeat(i);
assertEquals(fractions[i] / sum, (double) tallySheet.getCount(s) / nTrials, 0.05);
assertEquals(probabilities[i], (double) tallySheet.getCount(s) / nTrials, 0.05);
}
}
......
......@@ -3,10 +3,10 @@ package org.vadere.simulator.models.seating;
import static org.junit.Assert.*;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;
import org.apache.commons.math3.util.Pair;
import org.junit.Before;
import org.junit.Test;
import org.vadere.simulator.models.seating.trainmodel.Compartment;
......@@ -16,6 +16,7 @@ import org.vadere.state.attributes.models.AttributesSeating;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.data.TallySheet;
import org.vadere.util.test.FractionProbabilityNormalization;
import org.vadere.util.test.StatisticalTestCase;
public class TestChooseSeatGroup {
......@@ -117,17 +118,11 @@ public class TestChooseSeatGroup {
}
private double[] getSeatGroupPersonCountProbabilities() {
final List<Pair<Boolean, Double>> probabilities = new AttributesSeating().getSeatGroupChoice();
final Pair<Boolean, Double> pair = probabilities.get(0);
assert pair.getFirst() == true;
final Pair<Boolean, Double> otherPair = probabilities.get(1);
assert otherPair.getFirst() == false;
double p1 = pair.getSecond();
double p2 = otherPair.getSecond();
final double sum = p1 + p2;
p1 /= sum;
p2 /= sum;
final Map<Boolean, Double> probabilities = FractionProbabilityNormalization
.normalize(new AttributesSeating().getSeatGroupChoice());
double p1 = probabilities.get(true);
double p2 = probabilities.get(false);
double[] ps = { p1, p2, p2*p2, p2*p2*p2 };
return ps;
}
......
......@@ -25,5 +25,19 @@ public class FractionProbabilityNormalization {
return map;
}
public static double[] normalize(double[] fractions) {
double sum = 0;
for (double d : fractions) {
sum += d;
}
double[] result = new double[fractions.length];
for (int i = 0; i < result.length; i++) {
result[i] = fractions[i] / sum;
}
return result;
}
}
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