From e89042406be6d07ab86d6358b66f01adb5120f8f Mon Sep 17 00:00:00 2001 From: Quinn Dougherty Date: Wed, 6 Apr 2022 23:01:17 -0400 Subject: [PATCH] some cleanup of files --- ...est.res => DistributionOperation_test.res} | 6 +-- .../__tests__/Distributions/Samples_test.res | 46 ++++++++++++++++++ .../squiggle-lang/__tests__/Samples_test.res | 47 ------------------- packages/squiggle-lang/bsconfig.json | 2 +- 4 files changed, 50 insertions(+), 51 deletions(-) rename packages/squiggle-lang/__tests__/Distributions/{DistributionOperation__test.res => DistributionOperation_test.res} (91%) create mode 100644 packages/squiggle-lang/__tests__/Distributions/Samples_test.res delete mode 100644 packages/squiggle-lang/__tests__/Samples_test.res diff --git a/packages/squiggle-lang/__tests__/Distributions/DistributionOperation__test.res b/packages/squiggle-lang/__tests__/Distributions/DistributionOperation_test.res similarity index 91% rename from packages/squiggle-lang/__tests__/Distributions/DistributionOperation__test.res rename to packages/squiggle-lang/__tests__/Distributions/DistributionOperation_test.res index c4410f68..bfe630ae 100644 --- a/packages/squiggle-lang/__tests__/Distributions/DistributionOperation__test.res +++ b/packages/squiggle-lang/__tests__/Distributions/DistributionOperation_test.res @@ -26,7 +26,7 @@ describe("toPointSet", () => { ->outputMap(FromDist(ToFloat(#Mean))) ->toFloat ->toExt - expect(result)->toBeCloseTo(5.09) + expect(result)->toBeSoCloseTo(5.0, ~digits=0) }) test("on sample set distribution with under 4 points", () => { @@ -37,7 +37,7 @@ describe("toPointSet", () => { expect(result)->toEqual(GenDistError(Other("Converting sampleSet to pointSet failed"))) }) - Skip.test("on sample set", () => { + test("on sample set", () => { let result = run(FromDist(ToDist(ToPointSet), normalDist5)) ->outputMap(FromDist(ToDist(ToSampleSet(1000)))) @@ -45,6 +45,6 @@ describe("toPointSet", () => { ->outputMap(FromDist(ToFloat(#Mean))) ->toFloat ->toExt - expect(result)->toBeCloseTo(5.09) + expect(result)->toBeSoCloseTo(5.0, ~digits=-1) }) }) diff --git a/packages/squiggle-lang/__tests__/Distributions/Samples_test.res b/packages/squiggle-lang/__tests__/Distributions/Samples_test.res new file mode 100644 index 00000000..170ede1c --- /dev/null +++ b/packages/squiggle-lang/__tests__/Distributions/Samples_test.res @@ -0,0 +1,46 @@ +open Jest +open Expect + +let makeTest = (~only=false, str, item1, item2) => + only + ? Only.test(str, () => expect(item1) -> toEqual(item2)) + : test(str, () => expect(item1) -> toEqual(item2)) + +describe("Continuous and discrete splits", () => { + makeTest( + "check splits one", + SampleSet.Internals.T.splitContinuousAndDiscrete([1.432, 1.33455, 2.0]), + ([1.432, 1.33455, 2.0], E.FloatFloatMap.empty()), + ) + makeTest( + "check splits two", + SampleSet.Internals.T.splitContinuousAndDiscrete([ + 1.432, + 1.33455, + 2.0, + 2.0, + 2.0, + 2.0, + ]) |> (((c, disc)) => (c, disc |> E.FloatFloatMap.toArray)), + ([1.432, 1.33455], [(2.0, 4.0)]), + ) + + let makeDuplicatedArray = count => { + let arr = Belt.Array.range(1, count) |> E.A.fmap(float_of_int) + let sorted = arr |> Belt.SortArray.stableSortBy(_, compare) + E.A.concatMany([sorted, sorted, sorted, sorted]) |> Belt.SortArray.stableSortBy(_, compare) + } + + let (_, discrete) = SampleSet.Internals.T.splitContinuousAndDiscrete( + makeDuplicatedArray(10), + ) + let toArr = discrete |> E.FloatFloatMap.toArray + makeTest("splitMedium at count=10", toArr |> Belt.Array.length, 10) + + let (_c, discrete) = SampleSet.Internals.T.splitContinuousAndDiscrete( + makeDuplicatedArray(500), + ) + let toArr = discrete |> E.FloatFloatMap.toArray + makeTest("splitMedium at count=500", toArr |> Belt.Array.length, 500) +}) + diff --git a/packages/squiggle-lang/__tests__/Samples_test.res b/packages/squiggle-lang/__tests__/Samples_test.res deleted file mode 100644 index 01c248f0..00000000 --- a/packages/squiggle-lang/__tests__/Samples_test.res +++ /dev/null @@ -1,47 +0,0 @@ -open Jest -open Expect - -let makeTest = (~only=false, str, item1, item2) => - only - ? Only.test(str, () => expect(item1) -> toEqual(item2)) - : test(str, () => expect(item1) -> toEqual(item2)) - -describe("Lodash", () => - describe("Lodash", () => { - makeTest( - "split", - SampleSet.Internals.T.splitContinuousAndDiscrete([1.432, 1.33455, 2.0]), - ([1.432, 1.33455, 2.0], E.FloatFloatMap.empty()), - ) - makeTest( - "split", - SampleSet.Internals.T.splitContinuousAndDiscrete([ - 1.432, - 1.33455, - 2.0, - 2.0, - 2.0, - 2.0, - ]) |> (((c, disc)) => (c, disc |> E.FloatFloatMap.toArray)), - ([1.432, 1.33455], [(2.0, 4.0)]), - ) - - let makeDuplicatedArray = count => { - let arr = Belt.Array.range(1, count) |> E.A.fmap(float_of_int) - let sorted = arr |> Belt.SortArray.stableSortBy(_, compare) - E.A.concatMany([sorted, sorted, sorted, sorted]) |> Belt.SortArray.stableSortBy(_, compare) - } - - let (_, discrete) = SampleSet.Internals.T.splitContinuousAndDiscrete( - makeDuplicatedArray(10), - ) - let toArr = discrete |> E.FloatFloatMap.toArray - makeTest("splitMedium", toArr |> Belt.Array.length, 10) - - let (_c, discrete) = SampleSet.Internals.T.splitContinuousAndDiscrete( - makeDuplicatedArray(500), - ) - let toArr = discrete |> E.FloatFloatMap.toArray - makeTest("splitMedium", toArr |> Belt.Array.length, 500) - }) -) diff --git a/packages/squiggle-lang/bsconfig.json b/packages/squiggle-lang/bsconfig.json index 9bd15e11..76df3eda 100644 --- a/packages/squiggle-lang/bsconfig.json +++ b/packages/squiggle-lang/bsconfig.json @@ -50,7 +50,7 @@ [ "../../node_modules/bisect_ppx/ppx", "--exclude-files", - ".*_Test\\.res$$" + ".*_test\\.res$$" ] ] }