Minor cleanup
This commit is contained in:
parent
ee244463fa
commit
28036bfb36
|
@ -8,30 +8,8 @@ let expectEvalToBeOk = (expr: string) =>
|
|||
let registry = FunctionRegistry_Library.registry
|
||||
let examples = E.A.to_list(FunctionRegistry_Core.Registry.allExamples(registry))
|
||||
|
||||
describe("Fn auto-testing", () => {
|
||||
testAll("tests of validity", examples, r => {
|
||||
expectEvalToBeOk(r)
|
||||
})
|
||||
|
||||
testAll(
|
||||
"tests of type",
|
||||
E.A.to_list(
|
||||
FunctionRegistry_Core.Registry.allExamplesWithFns(registry)->E.A2.filter(((fn, _)) =>
|
||||
E.O.isSome(fn.output)
|
||||
),
|
||||
),
|
||||
((fn, example)) => {
|
||||
let responseType =
|
||||
example
|
||||
->Reducer.evaluate
|
||||
->E.R2.fmap(ReducerInterface_InternalExpressionValue.externalValueToValueType)
|
||||
let expectedOutputType = fn.output |> E.O.toExn("")
|
||||
expect(responseType)->toEqual(Ok(expectedOutputType))
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
describe("FunctionRegistry Library", () => {
|
||||
describe("Regular tests", () => {
|
||||
testEvalToBe("List.make(3, 'HI')", "Ok(['HI','HI','HI'])")
|
||||
testEvalToBe("make(3, 'HI')", "Error(Function not found: make(Number,String))")
|
||||
testEvalToBe("List.upTo(1,3)", "Ok([1,2,3])")
|
||||
|
@ -75,4 +53,28 @@ describe("FunctionRegistry Library", () => {
|
|||
)
|
||||
testEvalToBe("Dist.logScore({estimate: normal(5,2), answer: 4.5})", "Ok(1.6433360626394853)")
|
||||
testEvalToBe("Dist.klDivergence(normal(5,2), normal(5,1.5))", "Ok(0.06874342818671068)")
|
||||
})
|
||||
|
||||
describe("Fn auto-testing", () => {
|
||||
testAll("tests of validity", examples, r => {
|
||||
expectEvalToBeOk(r)
|
||||
})
|
||||
|
||||
testAll(
|
||||
"tests of type",
|
||||
E.A.to_list(
|
||||
FunctionRegistry_Core.Registry.allExamplesWithFns(registry)->E.A2.filter(((fn, _)) =>
|
||||
E.O.isSome(fn.output)
|
||||
),
|
||||
),
|
||||
((fn, example)) => {
|
||||
let responseType =
|
||||
example
|
||||
->Reducer.evaluate
|
||||
->E.R2.fmap(ReducerInterface_InternalExpressionValue.externalValueToValueType)
|
||||
let expectedOutputType = fn.output |> E.O.toExn("")
|
||||
expect(responseType)->toEqual(Ok(expectedOutputType))
|
||||
},
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -350,9 +350,6 @@ module FnDefinition = {
|
|||
}
|
||||
}
|
||||
|
||||
let toFfiFn = (t: t): Reducer_Expression_T.optionFfiFn =>
|
||||
(args, environment) => run(t, args, environment)->E.R.toOption
|
||||
|
||||
let make = (~name, ~inputs, ~run, ()): t => {
|
||||
name: name,
|
||||
inputs: inputs,
|
||||
|
@ -414,7 +411,7 @@ module Registry = {
|
|||
let allExamplesWithFns = (r: registry) =>
|
||||
r.functions->E.A2.fmap(fn => fn.examples->E.A2.fmap(example => (fn, example)))->E.A.concatMany
|
||||
|
||||
let buildFnNameDict = (r: array<function>): fnNameDict => {
|
||||
let _buildFnNameDict = (r: array<function>): fnNameDict => {
|
||||
let allDefinitionsWithFns =
|
||||
r
|
||||
->E.A2.fmap(fn => fn.definitions->E.A2.fmap(definitions => (fn, definitions)))
|
||||
|
@ -441,7 +438,7 @@ module Registry = {
|
|||
}
|
||||
|
||||
let make = (fns: array<function>): registry => {
|
||||
let dict = buildFnNameDict(fns)
|
||||
let dict = _buildFnNameDict(fns)
|
||||
{functions: fns, fnNameDict: dict}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user