Add basic partial test
This commit is contained in:
parent
8f879b7168
commit
58a357cce5
|
@ -1,5 +1,5 @@
|
||||||
import { Distribution, resultMap } from "../../src/js/index";
|
import { Distribution, resultMap } from "../../src/js/index";
|
||||||
import { testRun } from "./TestHelpers";
|
import { testRun, testRunPartial } from "./TestHelpers";
|
||||||
|
|
||||||
function Ok<b>(x: b) {
|
function Ok<b>(x: b) {
|
||||||
return { tag: "Ok", value: x };
|
return { tag: "Ok", value: x };
|
||||||
|
@ -57,6 +57,17 @@ describe("Record", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Partials", () => {
|
||||||
|
test("Can pass variables between partials and cells", () => {
|
||||||
|
let bindings = testRunPartial(`x = 5`);
|
||||||
|
let bindings2 = testRunPartial(`y = x + 2`, bindings);
|
||||||
|
expect(testRun(`y + 3`, bindings2)).toEqual({
|
||||||
|
tag: "number",
|
||||||
|
value: 10,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("Distribution", () => {
|
describe("Distribution", () => {
|
||||||
//It's important that sampleCount is less than 9. If it's more, than that will create randomness
|
//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.
|
//Also, note, the value should be created using makeSampleSetDist() later on.
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
import {
|
import {
|
||||||
run,
|
run,
|
||||||
// Distribution,
|
runPartial,
|
||||||
|
bindings,
|
||||||
squiggleExpression,
|
squiggleExpression,
|
||||||
errorValueToString,
|
errorValueToString,
|
||||||
// errorValue,
|
|
||||||
// result,
|
|
||||||
} from "../../src/js/index";
|
} from "../../src/js/index";
|
||||||
|
|
||||||
export function testRun(x: string): squiggleExpression {
|
export function testRun(x: string, bindings = {}): squiggleExpression {
|
||||||
let squiggleResult = run(x, {}, { sampleCount: 1000, xyPointLength: 100 });
|
let squiggleResult = run(x, bindings, {
|
||||||
|
sampleCount: 1000,
|
||||||
|
xyPointLength: 100,
|
||||||
|
});
|
||||||
// return squiggleResult.value
|
// return squiggleResult.value
|
||||||
if (squiggleResult.tag === "Ok") {
|
if (squiggleResult.tag === "Ok") {
|
||||||
return squiggleResult.value;
|
return squiggleResult.value;
|
||||||
|
@ -21,6 +23,22 @@ export function testRun(x: string): squiggleExpression {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function testRunPartial(x: string, bindings: bindings = {}): bindings {
|
||||||
|
let squiggleResult = runPartial(x, bindings, {
|
||||||
|
sampleCount: 1000,
|
||||||
|
xyPointLength: 100,
|
||||||
|
});
|
||||||
|
if (squiggleResult.tag === "Ok") {
|
||||||
|
return squiggleResult.value;
|
||||||
|
} else {
|
||||||
|
throw new Error(
|
||||||
|
`Expected squiggle expression to evaluate but got error: ${errorValueToString(
|
||||||
|
squiggleResult.value
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function failDefault() {
|
export function failDefault() {
|
||||||
expect("be reached").toBe("codepath should never");
|
expect("be reached").toBe("codepath should never");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user