From 837088a9c6ba50facc54dc7b59fa9d55b8f86a1d Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Fri, 8 Apr 2022 08:53:37 -0400 Subject: [PATCH] Refactored tests to use GenericOperation --- .../GenericDist/GenericDistSparkline_Test.res | 24 ------- .../GenericDist/GenericOperation__Test.res | 65 ++++++++++++++++++- 2 files changed, 63 insertions(+), 26 deletions(-) delete mode 100644 packages/squiggle-lang/__tests__/GenericDist/GenericDistSparkline_Test.res diff --git a/packages/squiggle-lang/__tests__/GenericDist/GenericDistSparkline_Test.res b/packages/squiggle-lang/__tests__/GenericDist/GenericDistSparkline_Test.res deleted file mode 100644 index 5aa72004..00000000 --- a/packages/squiggle-lang/__tests__/GenericDist/GenericDistSparkline_Test.res +++ /dev/null @@ -1,24 +0,0 @@ -open Jest -open Expect - -let {normalDist, uniformDist, betaDist, lognormalDist, cauchyDist, triangularDist, exponentialDist} = module(GenericDist_Fixtures) - -let runTest = (name: string, dist : GenericDist_Types.genericDist, expected: string) => { - test(name, () => { - let result = GenericDist.toSparkline(dist, ~sampleCount=100, ~buckets=20, ()) - switch result { - | Ok(sparkline) => expect(sparkline)->toEqual(expected) - | Error(err) => expect("Error")->toEqual(expected) - } - }) -} - -describe("sparkline of generic distribution", () => { - runTest("normal", normalDist, `▁▁▁▁▁▂▄▆▇██▇▆▄▂▁▁▁▁▁`) - runTest("uniform", uniformDist, `████████████████████`) - runTest("beta", betaDist, `▁▄▇████▇▆▅▄▃▃▂▁▁▁▁▁▁`) - runTest("lognormal", lognormalDist, `▁█▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁`) - runTest("cauchy", cauchyDist, `▁▁▁▁▁▁▁▁▁██▁▁▁▁▁▁▁▁▁`) - runTest("triangular", triangularDist, `▁▁▂▃▄▅▆▇████▇▆▅▄▃▂▁▁`) - runTest("exponential", exponentialDist, `█▅▄▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁`) -}) diff --git a/packages/squiggle-lang/__tests__/GenericDist/GenericOperation__Test.res b/packages/squiggle-lang/__tests__/GenericDist/GenericOperation__Test.res index c936e0bd..be01c87f 100644 --- a/packages/squiggle-lang/__tests__/GenericDist/GenericOperation__Test.res +++ b/packages/squiggle-lang/__tests__/GenericDist/GenericOperation__Test.res @@ -6,8 +6,18 @@ let env: DistributionOperation.env = { xyPointLength: 100, } - -let {normalDist5, normalDist10, normalDist20, uniformDist} = module(GenericDist_Fixtures) +let { + normalDist5, + normalDist10, + normalDist20, + normalDist, + uniformDist, + betaDist, + lognormalDist, + cauchyDist, + triangularDist, + exponentialDist, +} = module(GenericDist_Fixtures) let {toFloat, toDist, toString, toError} = module(DistributionOperation.Output) let {run} = module(DistributionOperation) let {fmap} = module(DistributionOperation.Output) @@ -42,6 +52,57 @@ describe("mixture", () => { }) }) +describe("sparkline", () => { + let runTest = ( + name: string, + dist: GenericDist_Types.genericDist, + expected: DistributionOperation.outputType, + ) => { + test(name, () => { + let result = DistributionOperation.run(~env, FromDist(ToSparkline(20), dist)) + expect(result)->toEqual(expected) + }) + } + + runTest( + "normal", + normalDist, + String(`▁▁▁▁▁▂▄▆▇██▇▆▄▂▁▁▁▁▁`), + ) + + runTest( + "uniform", + uniformDist, + String(`████████████████████`), + ) + + runTest("beta", betaDist, String(`▁▄▇████▇▆▅▄▃▃▂▁▁▁▁▁▁`)) + + runTest( + "lognormal", + lognormalDist, + String(`▁█▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁`), + ) + + runTest( + "cauchy", + cauchyDist, + String(`▁▁▁▁▁▁▁▁▁██▁▁▁▁▁▁▁▁▁`), + ) + + runTest( + "triangular", + triangularDist, + String(`▁▁▂▃▄▅▆▇████▇▆▅▄▃▂▁▁`), + ) + + runTest( + "exponential", + exponentialDist, + String(`█▅▄▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁`), + ) +}) + describe("toPointSet", () => { test("on symbolic normal distribution", () => { let result =