From e49343713500581de067b2fb751494d2d0411a61 Mon Sep 17 00:00:00 2001 From: Sam Nolan Date: Mon, 29 Aug 2022 13:46:52 +1000 Subject: [PATCH] Remove hardcoded enum strings --- .../squiggle-lang/__tests__/TS/JS_test.ts | 23 +++---------------- .../__tests__/TS/PointSet_test.ts | 4 ++-- .../__tests__/TS/SampleSet_test.ts | 10 ++++---- .../squiggle-lang/__tests__/TS/TestHelpers.ts | 7 ++---- 4 files changed, 12 insertions(+), 32 deletions(-) diff --git a/packages/squiggle-lang/__tests__/TS/JS_test.ts b/packages/squiggle-lang/__tests__/TS/JS_test.ts index 33b55fb5..871248da 100644 --- a/packages/squiggle-lang/__tests__/TS/JS_test.ts +++ b/packages/squiggle-lang/__tests__/TS/JS_test.ts @@ -1,6 +1,6 @@ import { SqProject, SqValue } from "../../src/js"; import { SqNumberValue } from "../../src/js/SqValue"; -import { failDefault, testRun } from "./TestHelpers"; +import { testRun } from "./TestHelpers"; function Ok(x: b) { return { tag: "Ok", value: x }; @@ -9,28 +9,11 @@ function Ok(x: b) { describe("Simple calculations and results", () => { test("mean(normal(5,2))", () => { const result = testRun("mean(normal(5,2))"); // FIXME - expect(result.tag).toEqual("Number"); - switch (result.tag) { - case "Number": - expect(result.value).toEqual(5); - break; - default: - fail(); - } - // tag: "number", - // value: 5, - // }); + expect(result.value).toEqual(5); }); test("10+10", () => { let result = testRun("10 + 10") as SqNumberValue; - expect(result.tag).toEqual("Number"); - switch (result.tag) { - case "Number": - expect(result.value).toEqual(20); - break; - default: - fail(); - } + expect(result.value).toEqual(20); }); }); // describe("Log function", () => { diff --git a/packages/squiggle-lang/__tests__/TS/PointSet_test.ts b/packages/squiggle-lang/__tests__/TS/PointSet_test.ts index 11812681..60a8e4e4 100644 --- a/packages/squiggle-lang/__tests__/TS/PointSet_test.ts +++ b/packages/squiggle-lang/__tests__/TS/PointSet_test.ts @@ -1,5 +1,5 @@ // import { errorValueToString } from "../../src/js/index"; -import { testRun, expectErrorToBeBounded } from "./TestHelpers"; +import { testRun, expectErrorToBeBounded, SqValueTag } from "./TestHelpers"; import * as fc from "fast-check"; describe("Mean of mixture is weighted average of means", () => { @@ -20,7 +20,7 @@ describe("Mean of mixture is weighted average of means", () => { let lognormalWeight = y / weightDenom; let betaMean = 1 / (1 + b / a); let lognormalMean = m + s ** 2 / 2; - if (res.tag === "Number") { + if (res.tag === SqValueTag.Number) { expectErrorToBeBounded( res.value, betaWeight * betaMean + lognormalWeight * lognormalMean, diff --git a/packages/squiggle-lang/__tests__/TS/SampleSet_test.ts b/packages/squiggle-lang/__tests__/TS/SampleSet_test.ts index a072f2df..1fac3905 100644 --- a/packages/squiggle-lang/__tests__/TS/SampleSet_test.ts +++ b/packages/squiggle-lang/__tests__/TS/SampleSet_test.ts @@ -1,4 +1,4 @@ -import { expectErrorToBeBounded, failDefault, testRun } from "./TestHelpers"; +import { expectErrorToBeBounded, testRun, SqValueTag } from "./TestHelpers"; import * as fc from "fast-check"; // Beware: float64Array makes it appear in an infinite loop. @@ -19,7 +19,7 @@ let arrayGen = () => let makeSampleSet = (samples: number[]) => { let sampleList = samples.map((x) => x.toFixed(20)).join(","); let result = testRun(`SampleSet.fromList([${sampleList}])`); - if (result.tag === "Distribution") { + if (result.tag === SqValueTag.Distribution) { return result.value; } else { fail("Expected to be distribution"); @@ -104,7 +104,7 @@ describe("cumulative density function", () => { } else if (typeof cdfValue == "number") { expect(Math.round(1e5 * cdfValue) / 1e5).toBeLessThanOrEqual(1); } else { - failDefault(); + fail(); } }) ); @@ -166,7 +166,7 @@ describe("mean is mean", () => { 1 ); } else { - failDefault(); + fail(); } } ) @@ -191,7 +191,7 @@ describe("mean is mean", () => { 1 ); } else { - failDefault(); + fail(); } } ) diff --git a/packages/squiggle-lang/__tests__/TS/TestHelpers.ts b/packages/squiggle-lang/__tests__/TS/TestHelpers.ts index 05b14408..ceb807e6 100644 --- a/packages/squiggle-lang/__tests__/TS/TestHelpers.ts +++ b/packages/squiggle-lang/__tests__/TS/TestHelpers.ts @@ -1,4 +1,5 @@ -import { run, SqValue } from "../../src/js"; +import { run, SqValueTag } from "../../src/js"; +export { SqValueTag }; export function testRun(x: string) { const { result, bindings } = run(x); // FIXME - set environment @@ -20,10 +21,6 @@ export function testRun(x: string) { } } -export function failDefault() { - expect("be reached").toBe("codepath should never"); -} - /** * This appears also in `TestHelpers.res`. According to https://www.math.net/percent-error, it computes * absolute error when numerical stability concerns make me not want to compute relative error.