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)