Skip to content

Commit

Permalink
histogram added to pbts
Browse files Browse the repository at this point in the history
  • Loading branch information
pfichtner committed Dec 4, 2024
1 parent a887fd2 commit a6d41ea
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@
import net.jqwik.api.arbitraries.DoubleArbitrary;
import net.jqwik.api.arbitraries.LongArbitrary;
import net.jqwik.api.arbitraries.SizableArbitrary;
import net.jqwik.api.statistics.Histogram;
import net.jqwik.api.statistics.Statistics;
import net.jqwik.api.statistics.StatisticsReport;

@Tag("pbt")
class DetectionExamples {
Expand Down Expand Up @@ -148,6 +150,7 @@ public long getOffset() {
private static final String METRIC_TABLE = "metricTable";

@Property
@StatisticsReport(format = Histogram.class)
void ballOnTableNeverWillRaiseTeamScoreOrTeamsScoredEvents(
@ForAll("positionsOnTable") List<RelativePosition> positions, @ForAll(METRIC_TABLE) Table table) {
statistics(positions);
Expand All @@ -167,6 +170,7 @@ private Predicate<Message> initialScorePayload() {
}

@Property
@StatisticsReport(format = Histogram.class)
void leftGoalProducesTeamScoredMessage(@ForAll("goalSituationsLeft") List<RelativePosition> positions,
@ForAll(METRIC_TABLE) Table table) {
statistics(positions);
Expand All @@ -175,6 +179,7 @@ void leftGoalProducesTeamScoredMessage(@ForAll("goalSituationsLeft") List<Relati
}

@Property
@StatisticsReport(format = Histogram.class)
void leftGoalsProducesTeamScoreMessage(@ForAll("goalSituationsLeft") List<RelativePosition> positions,
@ForAll(METRIC_TABLE) Table table) {
statistics(positions);
Expand All @@ -183,6 +188,7 @@ void leftGoalsProducesTeamScoreMessage(@ForAll("goalSituationsLeft") List<Relati
}

@Property
@StatisticsReport(format = Histogram.class)
void rightGoalProducesTeamScoredMessage(@ForAll("goalSituationsRight") List<RelativePosition> positions,
@ForAll(METRIC_TABLE) Table table) {
statistics(positions);
Expand All @@ -191,6 +197,7 @@ void rightGoalProducesTeamScoredMessage(@ForAll("goalSituationsRight") List<Rela
}

@Property
@StatisticsReport(format = Histogram.class)
void rightGoalProducesTeamScoreMessage(@ForAll("goalSituationsRight") List<RelativePosition> positions,
@ForAll(METRIC_TABLE) Table table) {
statistics(positions);
Expand All @@ -199,6 +206,7 @@ void rightGoalProducesTeamScoreMessage(@ForAll("goalSituationsRight") List<Relat
}

@Property
@StatisticsReport(format = Histogram.class)
void whenBallIsDetectedInAnyCornerAfterALeftHandGoalTheGoalGetsReverted(
@ForAll("leftGoalsToReverse") List<RelativePosition> positions, @ForAll(METRIC_TABLE) Table table) {
statistics(positions);
Expand All @@ -207,6 +215,7 @@ void whenBallIsDetectedInAnyCornerAfterALeftHandGoalTheGoalGetsReverted(
}

@Property
@StatisticsReport(format = Histogram.class)
void whenBallIsDetectedInAnyCornerAfterARightHandGoalTheGoalGetsReverted(
@ForAll("rightGoalsToReverse") List<RelativePosition> positions, @ForAll(METRIC_TABLE) Table table) {
statistics(positions);
Expand All @@ -215,13 +224,15 @@ void whenBallIsDetectedInAnyCornerAfterARightHandGoalTheGoalGetsReverted(
}

@Property
@StatisticsReport(format = Histogram.class)
void whenBallDoesNotMoveForMoreThanOneMinuteTheGameGoesToIdleMode(
@ForAll("idleWhereBallMaybeGone") List<RelativePosition> positions, @ForAll(METRIC_TABLE) Table table) {
statistics(positions);
assertThat(process(positions, table).filter(isTopic(GAME_IDLE).and(payloadIs("true"))).count(), is(1L));
}

@Property(shrinking = ShrinkingMode.OFF, afterFailure = AfterFailureMode.SAMPLE_ONLY)
@StatisticsReport(format = Histogram.class)
// TODO could produce falls positives: random data could contain fouls
void noIdleWithoutFoul(@ForAll("idle") List<RelativePosition> positions, @ForAll(METRIC_TABLE) Table table) {
statistics(positions);
Expand All @@ -234,6 +245,7 @@ void noIdleWithoutFoul(@ForAll("idle") List<RelativePosition> positions, @ForAll
}

@Property
@StatisticsReport(format = Histogram.class)
void allRelPositionAreBetween0And1(@ForAll("positionsOnTable") List<RelativePosition> positions,
@ForAll(METRIC_TABLE) Table table) {
statistics(positions);
Expand All @@ -243,13 +255,15 @@ void allRelPositionAreBetween0And1(@ForAll("positionsOnTable") List<RelativePosi
}

@Property
@StatisticsReport(format = Histogram.class)
boolean ballPositionAbsForEveryPosition(@ForAll("positionsOnTable") List<RelativePosition> positions,
@ForAll(METRIC_TABLE) Table table) {
statistics(positions);
return process(positions, table).filter(isTopic(BALL_POSITION_ABS)).count() == positions.size();
}

@Property(shrinking = ShrinkingMode.OFF, afterFailure = AfterFailureMode.SAMPLE_ONLY)
@StatisticsReport(format = Histogram.class)
void allAbsPositionAreBetween0AndTableSize(@ForAll("positionsOnTable") List<RelativePosition> positions,
@ForAll(METRIC_TABLE) Table table) {
statistics(positions);
Expand All @@ -260,13 +274,15 @@ void allAbsPositionAreBetween0AndTableSize(@ForAll("positionsOnTable") List<Rela
}

@Property
@StatisticsReport(format = Histogram.class)
boolean ballVelocityKmhForEveryPositionChange(@ForAll("positionsOnTable") List<RelativePosition> positions,
@ForAll(METRIC_TABLE) Table table) {
statistics(positions);
return process(positions, table).filter(isTopic(BALL_VELOCITY_KMH)).count() == positions.size() - 1;
}

@Property
@StatisticsReport(format = Histogram.class)
void allBallPositionVelocitiesArePositive(@ForAll("positionsOnTable") List<RelativePosition> positions,
@ForAll(METRIC_TABLE) Table table) {
statistics(positions);
Expand All @@ -275,13 +291,15 @@ void allBallPositionVelocitiesArePositive(@ForAll("positionsOnTable") List<Relat
}

@Property
@StatisticsReport(format = Histogram.class)
boolean ballVelocityMsForEveryPositionChange(@ForAll("positionsOnTable") List<RelativePosition> positions,
@ForAll(METRIC_TABLE) Table table) {
statistics(positions);
return process(positions, table).filter(isTopic(BALL_VELOCITY_MS)).count() == positions.size() - 1;
}

@Property
@StatisticsReport(format = Histogram.class)
void ballVelocityMsArePositive(@ForAll("positionsOnTable") List<RelativePosition> positions,
@ForAll(METRIC_TABLE) Table table) {
statistics(positions);
Expand All @@ -290,6 +308,7 @@ void ballVelocityMsArePositive(@ForAll("positionsOnTable") List<RelativePosition
}

@Property
@StatisticsReport(format = Histogram.class)
void ballDistanceArePositive(@ForAll("positionsOnTable") List<RelativePosition> positions,
@ForAll(METRIC_TABLE) Table table) {
statistics(positions);
Expand All @@ -298,6 +317,7 @@ void ballDistanceArePositive(@ForAll("positionsOnTable") List<RelativePosition>
}

@Property
@StatisticsReport(format = Histogram.class)
void forEachOverallDistanceThereIsASingleDistance(@ForAll("positionsOnTable") List<RelativePosition> positions,
@ForAll(METRIC_TABLE) Table table) {
statistics(positions);
Expand All @@ -307,6 +327,7 @@ void forEachOverallDistanceThereIsASingleDistance(@ForAll("positionsOnTable") Li
}

@Property
@StatisticsReport(format = Histogram.class)
void overallDistanceIsSumOfSingleDistances(@ForAll("positionsOnTable") List<RelativePosition> positions,
@ForAll(METRIC_TABLE) Table table) {
statistics(positions);
Expand Down

0 comments on commit a6d41ea

Please sign in to comment.