Fixed bug with namespaces
This commit is contained in:
parent
aa3d91d78f
commit
d3a12eb4e9
|
@ -17,14 +17,6 @@ describe("builtin", () => {
|
||||||
testEval("1-1", "Ok(0)")
|
testEval("1-1", "Ok(0)")
|
||||||
testEval("2>1", "Ok(true)")
|
testEval("2>1", "Ok(true)")
|
||||||
testEval("concat('a','b')", "Ok('ab')")
|
testEval("concat('a','b')", "Ok('ab')")
|
||||||
testEval(
|
|
||||||
"addOne(t)=t+1; toList(Sampleset.map(fromSamples([1,2,3,4,5,6]), addOne))",
|
|
||||||
"Ok([2,3,4,5,6,7])",
|
|
||||||
)
|
|
||||||
testEval(
|
|
||||||
"toList(mapSamplesN([fromSamples([1,2,3,4,5,6]), fromSamples([6, 5, 4, 3, 2, 1])], {|x| x[0] > x[1] ? x[0] : x[1]}))",
|
|
||||||
"Ok([6,5,4,4,5,6])",
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("builtin exception", () => {
|
describe("builtin exception", () => {
|
||||||
|
|
|
@ -17,6 +17,7 @@ describe("FunctionRegistry Library", () => {
|
||||||
testEvalToBe("List.last([3,5,8])", "Ok(8)")
|
testEvalToBe("List.last([3,5,8])", "Ok(8)")
|
||||||
testEvalToBe("List.reverse([3,5,8])", "Ok([8,5,3])")
|
testEvalToBe("List.reverse([3,5,8])", "Ok([8,5,3])")
|
||||||
testEvalToBe("double(x)=2*x; arr=[1,2,3]; List.map(arr, double)", "Ok([2,4,6])")
|
testEvalToBe("double(x)=2*x; arr=[1,2,3]; List.map(arr, double)", "Ok([2,4,6])")
|
||||||
|
testEvalToBe("double(x)=2*x; arr=[1,2,3]; map(arr, double)", "Ok([2,4,6])")
|
||||||
testEvalToBe("myadd(acc,x)=acc+x; arr=[1,2,3]; List.reduce(arr, 0, myadd)", "Ok(6)")
|
testEvalToBe("myadd(acc,x)=acc+x; arr=[1,2,3]; List.reduce(arr, 0, myadd)", "Ok(6)")
|
||||||
testEvalToBe("change(acc,x)=acc*x+x; arr=[1,2,3]; List.reduce(arr, 0, change)", "Ok(15)")
|
testEvalToBe("change(acc,x)=acc*x+x; arr=[1,2,3]; List.reduce(arr, 0, change)", "Ok(15)")
|
||||||
testEvalToBe("change(acc,x)=acc*x+x; arr=[1,2,3]; List.reduceReverse(arr, 0, change)", "Ok(9)")
|
testEvalToBe("change(acc,x)=acc*x+x; arr=[1,2,3]; List.reduceReverse(arr, 0, change)", "Ok(9)")
|
||||||
|
@ -60,6 +61,15 @@ describe("FunctionRegistry Library", () => {
|
||||||
testEvalToBe("Dist.logScore({estimate: normal(5,2), answer: 4.5})", "Ok(1.6433360626394853)")
|
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)")
|
testEvalToBe("Dist.klDivergence(normal(5,2), normal(5,1.5))", "Ok(0.06874342818671068)")
|
||||||
testEvalToBe("Sampleset.fromList([3,5,2,3,5,2,3,5,2,3,3,5])", "Ok(Sample Set Distribution)")
|
testEvalToBe("Sampleset.fromList([3,5,2,3,5,2,3,5,2,3,3,5])", "Ok(Sample Set Distribution)")
|
||||||
|
testEvalToBe("Sampleset.fromList([3,5,2,3,5,2,3,5,2,3,3,5])", "Ok(Sample Set Distribution)")
|
||||||
|
testEvalToBe(
|
||||||
|
"addOne(t)=t+1; Sampleset.toList(Sampleset.map(Sampleset.fromList([1,2,3,4,5,6]), addOne))",
|
||||||
|
"Ok([2,3,4,5,6,7])",
|
||||||
|
)
|
||||||
|
testEvalToBe(
|
||||||
|
"toList(Sampleset.mapN([Sampleset.fromList([1,2,3,4,5,6]), Sampleset.fromList([6, 5, 4, 3, 2, 1])], {|x| x[0] > x[1] ? x[0] : x[1]}))",
|
||||||
|
"Ok([6,5,4,4,5,6])",
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("Fn auto-testing", () => {
|
describe("Fn auto-testing", () => {
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
"start": "rescript build -w -with-deps",
|
"start": "rescript build -w -with-deps",
|
||||||
"clean": "rescript clean && rm -rf dist",
|
"clean": "rescript clean && rm -rf dist",
|
||||||
"test:reducer": "jest __tests__/Reducer*/",
|
"test:reducer": "jest __tests__/Reducer*/",
|
||||||
"test:current": "jest __tests__/SquiggleLibrary/SquiggleLibrary_FunctionRegistryLibrary_test.bs.js",
|
|
||||||
"benchmark": "ts-node benchmark/conversion_tests.ts",
|
"benchmark": "ts-node benchmark/conversion_tests.ts",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
|
"test:lib": "jest __tests__/SquiggleLibrary/SquiggleLibrary_FunctionRegistryLibrary_test.bs.js",
|
||||||
"test:ts": "jest __tests__/TS/",
|
"test:ts": "jest __tests__/TS/",
|
||||||
"test:rescript": "jest --modulePathIgnorePatterns=__tests__/TS/*",
|
"test:rescript": "jest --modulePathIgnorePatterns=__tests__/TS/*",
|
||||||
"test:watch": "jest --watchAll",
|
"test:watch": "jest --watchAll",
|
||||||
|
|
|
@ -280,11 +280,11 @@ module Matcher = {
|
||||||
|
|
||||||
module RegistryMatch = {
|
module RegistryMatch = {
|
||||||
type match = {
|
type match = {
|
||||||
namespace: option<string>,
|
namespace: string,
|
||||||
fnName: string,
|
fnName: string,
|
||||||
inputIndex: int,
|
inputIndex: int,
|
||||||
}
|
}
|
||||||
let makeMatch = (namespace: option<string>, fnName: string, inputIndex: int) => {
|
let makeMatch = (namespace: string, fnName: string, inputIndex: int) => {
|
||||||
namespace: namespace,
|
namespace: namespace,
|
||||||
fnName: fnName,
|
fnName: fnName,
|
||||||
inputIndex: inputIndex,
|
inputIndex: inputIndex,
|
||||||
|
@ -303,7 +303,7 @@ module Matcher = {
|
||||||
let fullMatch = functionMatchPairs->E.A.getBy(((_, match)) => Match.isFullMatch(match))
|
let fullMatch = functionMatchPairs->E.A.getBy(((_, match)) => Match.isFullMatch(match))
|
||||||
fullMatch->E.O.bind(((fn, match)) =>
|
fullMatch->E.O.bind(((fn, match)) =>
|
||||||
switch match {
|
switch match {
|
||||||
| FullMatch(index) => Some(RegistryMatch.makeMatch(namespace, fn.name, index))
|
| FullMatch(index) => Some(RegistryMatch.makeMatch(fn.nameSpace, fn.name, index))
|
||||||
| _ => None
|
| _ => None
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -326,7 +326,7 @@ module Matcher = {
|
||||||
->E.A2.fmap(((fn, match)) =>
|
->E.A2.fmap(((fn, match)) =>
|
||||||
switch match {
|
switch match {
|
||||||
| SameNameDifferentArguments(indexes) =>
|
| SameNameDifferentArguments(indexes) =>
|
||||||
indexes->E.A2.fmap(index => RegistryMatch.makeMatch(namespace, fn.name, index))
|
indexes->E.A2.fmap(index => RegistryMatch.makeMatch(fn.nameSpace, fn.name, index))
|
||||||
| _ => []
|
| _ => []
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -355,10 +355,7 @@ module Matcher = {
|
||||||
): option<fnDefinition> =>
|
): option<fnDefinition> =>
|
||||||
registry.functions
|
registry.functions
|
||||||
->E.A.getBy(fn => {
|
->E.A.getBy(fn => {
|
||||||
switch namespace {
|
namespace === fn.nameSpace && fnName === fn.name
|
||||||
| Some(ns) => ns === fn.nameSpace && fnName === fn.name
|
|
||||||
| _ => fnName === fn.name
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
->E.O.bind(fn => E.A.get(fn.definitions, inputIndex))
|
->E.O.bind(fn => E.A.get(fn.definitions, inputIndex))
|
||||||
}
|
}
|
||||||
|
@ -511,7 +508,7 @@ module Registry = {
|
||||||
`There are function matches for ${fnName}(), but with different arguments: ${defs}`
|
`There are function matches for ${fnName}(), but with different arguments: ${defs}`
|
||||||
}
|
}
|
||||||
|
|
||||||
let match = Matcher.Registry.findMatches(modified, fnName, args)
|
// let match = Matcher.Registry.findMatches(modified, fnName, args); Js.log2("Match", match)
|
||||||
|
|
||||||
switch Matcher.Registry.findMatches(modified, fnName, args) {
|
switch Matcher.Registry.findMatches(modified, fnName, args) {
|
||||||
| Matcher.Match.FullMatch(match) =>
|
| Matcher.Match.FullMatch(match) =>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user