Skip to content

Commit

Permalink
reduce flakiness of normal distribution test
Browse files Browse the repository at this point in the history
  • Loading branch information
marques-work committed Oct 5, 2017
1 parent a1c87f6 commit 77f1fd4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions generator/distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func TestNormalDistribution(t *testing.T) {
// close enough though.
expectedStandDev := 28.0

AssertEqual(t, expectedMean, RoundFloat(mean, 1), "Mean should be roughly %f", expectedMean)
AssertEqual(t, expectedStandDev, RoundFloat(sd, 1), "Standard deviation should be roughly %f", expectedStandDev)
Assert(t, withinTolerance(expectedMean, RoundFloat(mean, 1), 1), "Mean should be roughly %f", expectedMean)
Assert(t, withinTolerance(expectedStandDev, RoundFloat(sd, 1), 1), "Standard deviation should be roughly %f", expectedStandDev)
}

func TestWeightedType(t *testing.T) {
Expand All @@ -89,6 +89,10 @@ func TestNormalType(t *testing.T) {
AssertEqual(t, NORMAL_DIST, w.Type())
}

func withinTolerance(expected, actual, tolerance float64) bool {
return expected == actual || (actual <= (expected+tolerance) && actual >= (expected-tolerance))
}

func stdDev(mean float64, values []float64) float64 {
count := len(values)
Warn("count is %v", count)
Expand Down

0 comments on commit 77f1fd4

Please sign in to comment.