squiggle/packages/squiggle-lang/__tests__/JS__Test.ts

30 lines
902 B
TypeScript
Raw Normal View History

2022-02-18 02:16:31 +00:00
import { run } from '../src/js/index';
2022-01-29 23:56:44 +00:00
2022-03-22 02:33:28 +00:00
let testRun = (x: string) => {
let result = run(x)
if(result.tag == 'Ok'){
return { tag: 'Ok', value: result.value.exports }
}
else {
return result
}
}
2022-01-29 23:56:44 +00:00
describe("A simple result", () => {
test("mean(normal(5,2))", () => {
2022-03-22 02:33:28 +00:00
expect(testRun("mean(normal(5,2))")).toEqual({ tag: 'Ok', value: [ { NAME: 'Float', VAL: 5 } ] })
2022-03-07 00:10:43 +00:00
})
2022-01-29 23:56:44 +00:00
test("10+10", () => {
2022-03-22 02:33:28 +00:00
let foo = testRun("10 + 10")
2022-03-07 00:10:43 +00:00
expect(foo).toEqual({ tag: 'Ok', value: [ { NAME: 'Float', VAL: 20 } ] })
})
2022-02-18 02:26:39 +00:00
test("log(1) = 0", () => {
2022-03-22 02:33:28 +00:00
let foo = testRun("log(1)")
2022-03-07 00:10:43 +00:00
expect(foo).toEqual({ tag: 'Ok', value: [ { NAME: 'Float', VAL: 0} ]})
})
test("mm(0,0,[0,0,0])", () => {
2022-03-22 02:33:28 +00:00
let foo = testRun("mm(0,0,[0,0,0])")
2022-03-07 00:10:43 +00:00
expect(foo).toEqual({ "tag": "Error", "value": "Function multimodal error: Too many weights provided" })
2022-02-18 02:26:39 +00:00
})
2022-02-18 01:50:32 +00:00
});