From b44bf0cc38ddfb55d64e5fc8430f4ee3db8367b3 Mon Sep 17 00:00:00 2001 From: Sam Nolan Date: Tue, 12 Jul 2022 17:25:11 +1000 Subject: [PATCH] Fix failing tests due to environment change --- .../squiggle-lang/__tests__/TS/JS_test.ts | 3 +- .../__tests__/TS/SampleSet_test.ts | 47 +++++++------------ 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/packages/squiggle-lang/__tests__/TS/JS_test.ts b/packages/squiggle-lang/__tests__/TS/JS_test.ts index 8d2d5a1c..01219147 100644 --- a/packages/squiggle-lang/__tests__/TS/JS_test.ts +++ b/packages/squiggle-lang/__tests__/TS/JS_test.ts @@ -3,6 +3,7 @@ import { resultMap, defaultBindings, mergeBindings, + defaultEnvironment, } from "../../src/js/index"; import { testRun, testRunPartial } from "./TestHelpers"; @@ -109,7 +110,7 @@ describe("JS Imports", () => { describe("Distribution", () => { //It's important that sampleCount is less than 9. If it's more, than that will create randomness //Also, note, the value should be created using makeSampleSetDist() later on. - let env = { sampleCount: 8, xyPointLength: 100 }; + let env = { ...defaultEnvironment, sampleCount: 8, xyPointLength: 100 }; let dist1Samples = [3, 4, 5, 6, 6, 7, 10, 15, 30]; let dist1SampleCount = dist1Samples.length; let dist = new Distribution( diff --git a/packages/squiggle-lang/__tests__/TS/SampleSet_test.ts b/packages/squiggle-lang/__tests__/TS/SampleSet_test.ts index b235bf1b..d63e8042 100644 --- a/packages/squiggle-lang/__tests__/TS/SampleSet_test.ts +++ b/packages/squiggle-lang/__tests__/TS/SampleSet_test.ts @@ -1,4 +1,4 @@ -import { Distribution } from "../../src/js/index"; +import { Distribution, defaultEnvironment } from "../../src/js/index"; import { expectErrorToBeBounded, failDefault, testRun } from "./TestHelpers"; import * as fc from "fast-check"; @@ -16,6 +16,7 @@ let arrayGen = () => ); describe("cumulative density function", () => { let n = 10000; + let env = { ...defaultEnvironment, sampleCount: n, xyPointLength: 100 }; // We should fix this. test.skip("'s codomain is bounded above", () => { @@ -23,10 +24,7 @@ describe("cumulative density function", () => { fc.property(arrayGen(), fc.float(), (xs_, x) => { let xs = Array.from(xs_); // Should compute with squiggle strings once interpreter has `sample` - let dist = new Distribution( - { tag: "SampleSet", value: xs }, - { sampleCount: n, xyPointLength: 100 } - ); + let dist = new Distribution({ tag: "SampleSet", value: xs }, env); let cdfValue = dist.cdf(x).value; let epsilon = 5e-7; expect(cdfValue).toBeLessThanOrEqual(1 + epsilon); @@ -39,10 +37,7 @@ describe("cumulative density function", () => { fc.property(arrayGen(), fc.float(), (xs_, x) => { let xs = Array.from(xs_); // Should compute with squiggle strings once interpreter has `sample` - let dist = new Distribution( - { tag: "SampleSet", value: xs }, - { sampleCount: n, xyPointLength: 100 } - ); + let dist = new Distribution({ tag: "SampleSet", value: xs }, env); let cdfValue = dist.cdf(x).value; expect(cdfValue).toBeGreaterThanOrEqual(0); }) @@ -57,10 +52,7 @@ describe("cumulative density function", () => { let xs = Array.from(xs_); let max = Math.max(...xs); // Should compute with squiggle strings once interpreter has `sample` - let dist = new Distribution( - { tag: "SampleSet", value: xs }, - { sampleCount: n, xyPointLength: 100 } - ); + let dist = new Distribution({ tag: "SampleSet", value: xs }, env); let cdfValue = dist.cdf(max).value; expect(cdfValue).toBeCloseTo(1.0, 2); }) @@ -74,10 +66,7 @@ describe("cumulative density function", () => { let xs = Array.from(xs_); let min = Math.min(...xs); // Should compute with squiggle strings once interpreter has `sample` - let dist = new Distribution( - { tag: "SampleSet", value: xs }, - { sampleCount: n, xyPointLength: 100 } - ); + let dist = new Distribution({ tag: "SampleSet", value: xs }, env); let cdfValue = dist.cdf(min).value; let max = Math.max(...xs); let epsilon = 5e-3; @@ -95,10 +84,7 @@ describe("cumulative density function", () => { fc.assert( fc.property(arrayGen(), fc.float(), (xs_, x) => { let xs = Array.from(xs_); - let dist = new Distribution( - { tag: "SampleSet", value: xs }, - { sampleCount: n, xyPointLength: 100 } - ); + let dist = new Distribution({ tag: "SampleSet", value: xs }, env); let cdfValue = dist.cdf(x).value; let max = Math.max(...xs); if (x > max) { @@ -117,10 +103,7 @@ describe("cumulative density function", () => { fc.assert( fc.property(arrayGen(), fc.float(), (xs_, x) => { let xs = Array.from(xs_); - let dist = new Distribution( - { tag: "SampleSet", value: xs }, - { sampleCount: n, xyPointLength: 100 } - ); + let dist = new Distribution({ tag: "SampleSet", value: xs }, env); let cdfValue = dist.cdf(x).value; expect(cdfValue).toBeGreaterThanOrEqual(0); }) @@ -131,6 +114,7 @@ describe("cumulative density function", () => { // I no longer believe this is true. describe("probability density function", () => { let n = 1000; + let env = { ...defaultEnvironment, sampleCount: n, xyPointLength: 100 }; test.skip("assigns to the max at most the weight of the mean", () => { fc.assert( @@ -139,10 +123,7 @@ describe("probability density function", () => { let max = Math.max(...xs); let mean = xs.reduce((a, b) => a + b, 0.0) / xs.length; // Should be from squiggleString once interpreter exposes sampleset - let dist = new Distribution( - { tag: "SampleSet", value: xs }, - { sampleCount: n, xyPointLength: 100 } - ); + let dist = new Distribution({ tag: "SampleSet", value: xs }, env); let pdfValueMean = dist.pdf(mean).value; let pdfValueMax = dist.pdf(max).value; if (typeof pdfValueMean == "number" && typeof pdfValueMax == "number") { @@ -166,7 +147,7 @@ describe("mean is mean", () => { let n = xs.length; let dist = new Distribution( { tag: "SampleSet", value: xs }, - { sampleCount: 2 * n, xyPointLength: 4 * n } + { ...defaultEnvironment, sampleCount: 2 * n, xyPointLength: 4 * n } ); let mean = dist.mean(); if (typeof mean.value == "number") { @@ -193,7 +174,11 @@ describe("mean is mean", () => { let n = xs.length; let dist = new Distribution( { tag: "SampleSet", value: xs }, - { sampleCount: Math.floor(n / 2), xyPointLength: 4 * n } + { + ...defaultEnvironment, + sampleCount: Math.floor(n / 2), + xyPointLength: 4 * n, + } ); let mean = dist.mean(); if (typeof mean.value == "number") {