Simple tests for fake FunctionRegistry output types

This commit is contained in:
Ozzie Gooen 2022-07-15 19:18:36 -07:00
parent 8839f1d9c7
commit 9d5aaf43a8
3 changed files with 91 additions and 74 deletions

View File

@ -15,10 +15,11 @@ module FooImplementation = {
open FunctionRegistry_Core open FunctionRegistry_Core
open FunctionRegistry_Helpers open FunctionRegistry_Helpers
let library = [ let fn = Function.make(
Function.make(
~name="add", ~name="add",
~nameSpace="Foo", ~nameSpace="Foo",
~examples=["Foo.add(1, 2)", "Foo.add(1, 2, 3)"],
~output=EvtNumber,
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~requiresNamespace=false, ~requiresNamespace=false,
@ -45,8 +46,9 @@ module FooImplementation = {
), ),
], ],
(), (),
), )
]
let library = [fn]
} }
let makeBindings = (previousBindings: Bindings.t): Bindings.t => let makeBindings = (previousBindings: Bindings.t): Bindings.t =>
@ -75,8 +77,19 @@ describe("Module", () => {
let result = evalToStringResultWithFoo("Foo.add(1,2,3)") let result = evalToStringResultWithFoo("Foo.add(1,2,3)")
expect(result)->toEqual("Ok(6)") expect(result)->toEqual("Ok(6)")
}) })
test("add(1,2,3,5)", () => { })
let result = evalToStringResultWithFoo("Foo.add(1,2,3,5)")
expect(result)->toEqual("Ok(6)") describe("Fn auto-testing", () => {
let items = FooImplementation.fn.examples->E.A.to_list
testAll("tests of validity", items, r => {
expect(r->evalWithFoo->E.R.isOk)->toEqual(true)
})
testAll("tests of type", items, r => {
let responseType =
r->evalWithFoo->E.R2.fmap(ReducerInterface_InternalExpressionValue.valueToValueType)
let expectedOutputType = FooImplementation.fn.output |> E.O.toExn("")
expect(responseType)->toEqual(Ok(expectedOutputType))
}) })
}) })

View File

@ -1,4 +1,5 @@
type internalExpressionValue = ReducerInterface_InternalExpressionValue.t type internalExpressionValue = ReducerInterface_InternalExpressionValue.t
type internalExpressionValueType = ReducerInterface_InternalExpressionValue.internalExpressionValueType
/* /*
Function Registry "Type". A type, without any other information. Function Registry "Type". A type, without any other information.
@ -54,6 +55,7 @@ type function = {
name: string, name: string,
definitions: array<fnDefinition>, definitions: array<fnDefinition>,
nameSpace: string, nameSpace: string,
output: option<internalExpressionValueType>,
examples: array<string>, examples: array<string>,
description: option<string>, description: option<string>,
isExperimental: bool, isExperimental: bool,
@ -374,6 +376,7 @@ module Function = {
~nameSpace, ~nameSpace,
~definitions, ~definitions,
~examples=?, ~examples=?,
~output=?,
~description=?, ~description=?,
~isExperimental=false, ~isExperimental=false,
(), (),
@ -381,6 +384,7 @@ module Function = {
name: name, name: name,
nameSpace: nameSpace, nameSpace: nameSpace,
definitions: definitions, definitions: definitions,
output: output,
examples: examples |> E.O.default([]), examples: examples |> E.O.default([]),
isExperimental: isExperimental, isExperimental: isExperimental,
description: description, description: description,

View File

@ -55,7 +55,7 @@ module PointSet = {
let library = [ let library = [
Function.make( Function.make(
~name="PointSet.makeContinuous", ~name="makeContinuous",
~nameSpace, ~nameSpace,
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
@ -69,7 +69,7 @@ module PointSet = {
(), (),
), ),
Function.make( Function.make(
~name="PointSet.makeDiscrete", ~name="makeDiscrete",
~nameSpace, ~nameSpace,
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
@ -89,7 +89,7 @@ module Functionn = {
let nameSpace = "Function" let nameSpace = "Function"
let library = [ let library = [
Function.make( Function.make(
~name="Function.declare", ~name="declare",
~nameSpace, ~nameSpace,
~description="Adds metadata to a function of the input ranges. Works now for numeric and date inputs. This is useful when making predictions. It allows you to limit the domain that your prediction will be used and scored within.", ~description="Adds metadata to a function of the input ranges. Works now for numeric and date inputs. This is useful when making predictions. It allows you to limit the domain that your prediction will be used and scored within.",
~examples=[ ~examples=[
@ -177,7 +177,7 @@ module DistributionCreation = {
let library = [ let library = [
Function.make( Function.make(
~name="Normal", ~name="normal",
~nameSpace, ~nameSpace,
~examples=["normal(5,1)", "normal({p5: 4, p95: 10})", "normal({mean: 5, stdev: 2})"], ~examples=["normal(5,1)", "normal({p5: 4, p95: 10})", "normal({mean: 5, stdev: 2})"],
~definitions=[ ~definitions=[
@ -190,7 +190,7 @@ module DistributionCreation = {
(), (),
), ),
Function.make( Function.make(
~name="Lognormal", ~name="lognormal",
~nameSpace, ~nameSpace,
~examples=[ ~examples=[
"lognormal(0.5, 0.8)", "lognormal(0.5, 0.8)",
@ -210,14 +210,14 @@ module DistributionCreation = {
(), (),
), ),
Function.make( Function.make(
~name="Uniform", ~name="uniform",
~nameSpace, ~nameSpace,
~examples=[`uniform(10, 12)`], ~examples=[`uniform(10, 12)`],
~definitions=[TwoArgDist.make("uniform", twoArgs(SymbolicDist.Uniform.make))], ~definitions=[TwoArgDist.make("uniform", twoArgs(SymbolicDist.Uniform.make))],
(), (),
), ),
Function.make( Function.make(
~name="Beta", ~name="beta",
~nameSpace, ~nameSpace,
~examples=[`beta(20, 25)`, `beta({mean: 0.39, stdev: 0.1})`], ~examples=[`beta(20, 25)`, `beta({mean: 0.39, stdev: 0.1})`],
~definitions=[ ~definitions=[
@ -227,28 +227,28 @@ module DistributionCreation = {
(), (),
), ),
Function.make( Function.make(
~name="Cauchy", ~name="cauchy",
~nameSpace, ~nameSpace,
~examples=[`cauchy(5, 1)`], ~examples=[`cauchy(5, 1)`],
~definitions=[TwoArgDist.make("cauchy", twoArgs(SymbolicDist.Cauchy.make))], ~definitions=[TwoArgDist.make("cauchy", twoArgs(SymbolicDist.Cauchy.make))],
(), (),
), ),
Function.make( Function.make(
~name="Gamma", ~name="gamma",
~nameSpace, ~nameSpace,
~examples=[`gamma(5, 1)`], ~examples=[`gamma(5, 1)`],
~definitions=[TwoArgDist.make("gamma", twoArgs(SymbolicDist.Gamma.make))], ~definitions=[TwoArgDist.make("gamma", twoArgs(SymbolicDist.Gamma.make))],
(), (),
), ),
Function.make( Function.make(
~name="Logistic", ~name="logistic",
~nameSpace, ~nameSpace,
~examples=[`logistic(5, 1)`], ~examples=[`logistic(5, 1)`],
~definitions=[TwoArgDist.make("logistic", twoArgs(SymbolicDist.Logistic.make))], ~definitions=[TwoArgDist.make("logistic", twoArgs(SymbolicDist.Logistic.make))],
(), (),
), ),
Function.make( Function.make(
~name="To (Distribution)", ~name="to (distribution)",
~nameSpace, ~nameSpace,
~examples=[`5 to 10`, `to(5,10)`, `-5 to 5`], ~examples=[`5 to 10`, `to(5,10)`, `-5 to 5`],
~definitions=[ ~definitions=[
@ -261,21 +261,21 @@ module DistributionCreation = {
(), (),
), ),
Function.make( Function.make(
~name="Exponential", ~name="exponential",
~nameSpace, ~nameSpace,
~examples=[`exponential(2)`], ~examples=[`exponential(2)`],
~definitions=[OneArgDist.make("exponential", SymbolicDist.Exponential.make)], ~definitions=[OneArgDist.make("exponential", SymbolicDist.Exponential.make)],
(), (),
), ),
Function.make( Function.make(
~name="Bernoulli", ~name="bernoulli",
~nameSpace, ~nameSpace,
~examples=[`bernoulli(0.5)`], ~examples=[`bernoulli(0.5)`],
~definitions=[OneArgDist.make("bernoulli", SymbolicDist.Bernoulli.make)], ~definitions=[OneArgDist.make("bernoulli", SymbolicDist.Bernoulli.make)],
(), (),
), ),
Function.make( Function.make(
~name="PointMass", ~name="pointMass",
~nameSpace, ~nameSpace,
~examples=[`pointMass(0.5)`], ~examples=[`pointMass(0.5)`],
~definitions=[OneArgDist.make("pointMass", SymbolicDist.Float.makeSafe)], ~definitions=[OneArgDist.make("pointMass", SymbolicDist.Float.makeSafe)],
@ -333,61 +333,61 @@ module Number = {
let library = [ let library = [
Function.make( Function.make(
~name="Floor", ~name="floor",
~nameSpace, ~nameSpace,
~definitions=[NumberToNumber.make("floor", Js.Math.floor_float)], ~definitions=[NumberToNumber.make("floor", Js.Math.floor_float)],
(), (),
), ),
Function.make( Function.make(
~name="Ceiling", ~name="ceiling",
~nameSpace, ~nameSpace,
~definitions=[NumberToNumber.make("ceil", Js.Math.ceil_float)], ~definitions=[NumberToNumber.make("ceil", Js.Math.ceil_float)],
(), (),
), ),
Function.make( Function.make(
~name="Absolute Value", ~name="absolute value",
~nameSpace, ~nameSpace,
~definitions=[NumberToNumber.make("abs", Js.Math.abs_float)], ~definitions=[NumberToNumber.make("abs", Js.Math.abs_float)],
(), (),
), ),
Function.make( Function.make(
~name="Exponent", ~name="exponent",
~nameSpace, ~nameSpace,
~definitions=[NumberToNumber.make("exp", Js.Math.exp)], ~definitions=[NumberToNumber.make("exp", Js.Math.exp)],
(), (),
), ),
Function.make( Function.make(
~name="Log", ~name="log",
~nameSpace, ~nameSpace,
~definitions=[NumberToNumber.make("log", Js.Math.log)], ~definitions=[NumberToNumber.make("log", Js.Math.log)],
(), (),
), ),
Function.make( Function.make(
~name="Log Base 10", ~name="log base 10",
~nameSpace, ~nameSpace,
~definitions=[NumberToNumber.make("log10", Js.Math.log10)], ~definitions=[NumberToNumber.make("log10", Js.Math.log10)],
(), (),
), ),
Function.make( Function.make(
~name="Log Base 2", ~name="log base 2",
~nameSpace, ~nameSpace,
~definitions=[NumberToNumber.make("log2", Js.Math.log2)], ~definitions=[NumberToNumber.make("log2", Js.Math.log2)],
(), (),
), ),
Function.make( Function.make(
~name="Round", ~name="round",
~nameSpace, ~nameSpace,
~definitions=[NumberToNumber.make("round", Js.Math.round)], ~definitions=[NumberToNumber.make("round", Js.Math.round)],
(), (),
), ),
Function.make( Function.make(
~name="Sum", ~name="sum",
~nameSpace, ~nameSpace,
~definitions=[ArrayNumberDist.make("sum", r => r->E.A.Floats.sum->Wrappers.evNumber->Ok)], ~definitions=[ArrayNumberDist.make("sum", r => r->E.A.Floats.sum->Wrappers.evNumber->Ok)],
(), (),
), ),
Function.make( Function.make(
~name="Product", ~name="product",
~nameSpace, ~nameSpace,
~definitions=[ ~definitions=[
ArrayNumberDist.make("product", r => r->E.A.Floats.product->Wrappers.evNumber->Ok), ArrayNumberDist.make("product", r => r->E.A.Floats.product->Wrappers.evNumber->Ok),
@ -395,25 +395,25 @@ module Number = {
(), (),
), ),
Function.make( Function.make(
~name="Min", ~name="min",
~nameSpace, ~nameSpace,
~definitions=[ArrayNumberDist.make("min", r => r->E.A.Floats.min->Wrappers.evNumber->Ok)], ~definitions=[ArrayNumberDist.make("min", r => r->E.A.Floats.min->Wrappers.evNumber->Ok)],
(), (),
), ),
Function.make( Function.make(
~name="Max", ~name="max",
~nameSpace, ~nameSpace,
~definitions=[ArrayNumberDist.make("max", r => r->E.A.Floats.max->Wrappers.evNumber->Ok)], ~definitions=[ArrayNumberDist.make("max", r => r->E.A.Floats.max->Wrappers.evNumber->Ok)],
(), (),
), ),
Function.make( Function.make(
~name="Mean", ~name="mean",
~nameSpace, ~nameSpace,
~definitions=[ArrayNumberDist.make("mean", r => r->E.A.Floats.mean->Wrappers.evNumber->Ok)], ~definitions=[ArrayNumberDist.make("mean", r => r->E.A.Floats.mean->Wrappers.evNumber->Ok)],
(), (),
), ),
Function.make( Function.make(
~name="Geometric Mean", ~name="geometric mean",
~nameSpace, ~nameSpace,
~definitions=[ ~definitions=[
ArrayNumberDist.make("geomean", r => r->E.A.Floats.geomean->Wrappers.evNumber->Ok), ArrayNumberDist.make("geomean", r => r->E.A.Floats.geomean->Wrappers.evNumber->Ok),
@ -421,13 +421,13 @@ module Number = {
(), (),
), ),
Function.make( Function.make(
~name="Standard Deviation", ~name="standard deviation",
~nameSpace, ~nameSpace,
~definitions=[ArrayNumberDist.make("stdev", r => r->E.A.Floats.stdev->Wrappers.evNumber->Ok)], ~definitions=[ArrayNumberDist.make("stdev", r => r->E.A.Floats.stdev->Wrappers.evNumber->Ok)],
(), (),
), ),
Function.make( Function.make(
~name="Variance", ~name="variance",
~nameSpace, ~nameSpace,
~definitions=[ ~definitions=[
ArrayNumberDist.make("variance", r => r->E.A.Floats.stdev->Wrappers.evNumber->Ok), ArrayNumberDist.make("variance", r => r->E.A.Floats.stdev->Wrappers.evNumber->Ok),
@ -435,7 +435,7 @@ module Number = {
(), (),
), ),
Function.make( Function.make(
~name="Sort", ~name="sort",
~nameSpace, ~nameSpace,
~definitions=[ ~definitions=[
ArrayNumberDist.make("sort", r => ArrayNumberDist.make("sort", r =>
@ -445,7 +445,7 @@ module Number = {
(), (),
), ),
Function.make( Function.make(
~name="Cumulative Sum", ~name="cumulative sum",
~nameSpace, ~nameSpace,
~definitions=[ ~definitions=[
ArrayNumberDist.make("cumsum", r => ArrayNumberDist.make("cumsum", r =>
@ -455,7 +455,7 @@ module Number = {
(), (),
), ),
Function.make( Function.make(
~name="Cumulative Prod", ~name="cumulative prod",
~nameSpace, ~nameSpace,
~definitions=[ ~definitions=[
ArrayNumberDist.make("cumprod", r => ArrayNumberDist.make("cumprod", r =>
@ -465,7 +465,7 @@ module Number = {
(), (),
), ),
Function.make( Function.make(
~name="Diff", ~name="diff",
~nameSpace, ~nameSpace,
~definitions=[ ~definitions=[
ArrayNumberDist.make("diff", r => ArrayNumberDist.make("diff", r =>
@ -665,7 +665,7 @@ module List = {
let library = [ let library = [
Function.make( Function.make(
~name="List.make", ~name="make",
~nameSpace, ~nameSpace,
~definitions=[ ~definitions=[
//Todo: If the second item is a function with no args, it could be nice to run this function and return the result. //Todo: If the second item is a function with no args, it could be nice to run this function and return the result.
@ -685,7 +685,7 @@ module List = {
(), (),
), ),
Function.make( Function.make(
~name="List.upTo", ~name="upTo",
~nameSpace, ~nameSpace,
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
@ -702,7 +702,7 @@ module List = {
(), (),
), ),
Function.make( Function.make(
~name="List.first", ~name="first",
~nameSpace, ~nameSpace,
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
@ -720,7 +720,7 @@ module List = {
(), (),
), ),
Function.make( Function.make(
~name="List.last", ~name="last",
~nameSpace, ~nameSpace,
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
@ -738,7 +738,7 @@ module List = {
(), (),
), ),
Function.make( Function.make(
~name="List.reverse", ~name="reverse",
~nameSpace, ~nameSpace,
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(