squiggle/packages/squiggle-lang/__tests__/TS/Scalars_test.ts

30 lines
970 B
TypeScript
Raw Permalink Normal View History

2022-04-20 22:48:04 +00:00
// import { errorValueToString } from "../../src/js/index";
2022-04-20 03:42:24 +00:00
import { testRun } from "./TestHelpers";
import * as fc from "fast-check";
describe("Scalar manipulation is well-modeled by javascript math", () => {
2022-04-20 22:48:04 +00:00
test("in the case of natural logarithms", () => {
fc.assert(
fc.property(fc.integer(), (x) => {
2022-04-20 22:48:04 +00:00
let squiggleString = `log(${x})`;
let squiggleResult = testRun(squiggleString);
if (x == 0) {
2022-04-20 22:48:04 +00:00
expect(squiggleResult.value).toEqual(-Infinity);
} else {
2022-04-20 22:48:04 +00:00
expect(squiggleResult.value).toEqual(Math.log(x));
}
})
);
});
test("in the case of addition (with assignment)", () => {
fc.assert(
fc.property(fc.integer(), fc.integer(), fc.integer(), (x, y, z) => {
let squiggleString = `x = ${x}; y = ${y}; z = ${z}; x + y + z`;
let squiggleResult = testRun(squiggleString);
2022-04-20 22:48:04 +00:00
expect(squiggleResult.value).toBeCloseTo(x + y + z);
})
);
});
});