From 77f1fd48f332fc2f7e9a07c145954bf32e7220d0 Mon Sep 17 00:00:00 2001 From: Marques Lee Date: Thu, 5 Oct 2017 13:07:49 -0700 Subject: [PATCH] reduce flakiness of normal distribution test --- generator/distribution_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/generator/distribution_test.go b/generator/distribution_test.go index 0df1b40..6256e50 100644 --- a/generator/distribution_test.go +++ b/generator/distribution_test.go @@ -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) { @@ -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)