From 335d0b5d0430cb556e4dc222e5dd3c573fe649cf Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Thu, 28 Apr 2022 07:36:53 -0400 Subject: [PATCH] Cleaned tests --- .../Distributions/SampleSetDist_test.res | 33 +++++++------------ .../squiggle-lang/src/rescript/Utility/E.res | 2 +- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/packages/squiggle-lang/__tests__/Distributions/SampleSetDist_test.res b/packages/squiggle-lang/__tests__/Distributions/SampleSetDist_test.res index edfcb6ef..825c0095 100644 --- a/packages/squiggle-lang/__tests__/Distributions/SampleSetDist_test.res +++ b/packages/squiggle-lang/__tests__/Distributions/SampleSetDist_test.res @@ -1,36 +1,27 @@ open Jest open TestHelpers +let prepareInputs = (ar, minWeight) => + E.A.Sorted.Floats.splitContinuousAndDiscreteForMinWeight(ar, minWeight) |> ( + ((c, disc)) => (c, disc |> E.FloatFloatMap.toArray) + ) + describe("Continuous and discrete splits", () => { makeTest( - "splits (1)", - E.A.Sorted.Floats.splitContinuousAndDiscreteForMinWeight([1.432, 1.33455, 2.0], 2), - ([1.33455, 1.432, 2.0], E.FloatFloatMap.empty()), - ) - makeTest( - "splits (2)", - E.A.Sorted.Floats.splitContinuousAndDiscreteForMinWeight( - [1.432, 1.33455, 2.0, 2.0, 2.0, 2.0], - 2, - ) |> (((c, disc)) => (c, disc |> E.FloatFloatMap.toArray)), - ([1.33455, 1.432], [(2.0, 4.0)]), + "is empty, with no common elements", + prepareInputs([1.432, 1.33455, 2.0], 2), + ([1.33455, 1.432, 2.0], []), ) makeTest( - "splits (3)", - E.A.Sorted.Floats.splitContinuousAndDiscreteForMinWeight( - [1.432, 1.33455, 2.0, 2.0, 3.5, 3.5, 3.5], - 3, - ) |> (((c, disc)) => (c, disc |> E.FloatFloatMap.toArray)), + "only stores 3.5 as discrete when minWeight is 3", + prepareInputs([1.432, 1.33455, 2.0, 2.0, 3.5, 3.5, 3.5], 3), ([1.33455, 1.432, 2.0, 2.0], [(3.5, 3.0)]), ) makeTest( - "splits (3)", - E.A.Sorted.Floats.splitContinuousAndDiscreteForMinWeight( - [1.432, 1.33455, 2.0, 2.0, 3.5, 3.5, 3.5], - 5, - ) |> (((c, disc)) => (c, disc |> E.FloatFloatMap.toArray)), + "doesn't store 3.5 as discrete when minWeight is 5", + prepareInputs([1.432, 1.33455, 2.0, 2.0, 3.5, 3.5, 3.5], 5), ([1.33455, 1.432, 2.0, 2.0, 3.5, 3.5, 3.5], []), ) diff --git a/packages/squiggle-lang/src/rescript/Utility/E.res b/packages/squiggle-lang/src/rescript/Utility/E.res index 69ded69b..b0d9ef19 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E.res +++ b/packages/squiggle-lang/src/rescript/Utility/E.res @@ -550,7 +550,7 @@ module A = { minDiscreteWeight: int, ) => { let (continuous, discrete) = splitContinuousAndDiscreteForDuplicates(sortedArray) - let keepFn = v => Belt.Float.toInt(v) > minDiscreteWeight + let keepFn = v => Belt.Float.toInt(v) >= minDiscreteWeight let (discreteToKeep, discreteToIntegrate) = FloatFloatMap.partition( ((_, v)) => keepFn(v), discrete,