Changes in response to CR
This commit is contained in:
parent
e7c2a7db01
commit
688cf0b19e
|
@ -1,28 +1,28 @@
|
|||
open Jest
|
||||
open Reducer_TestHelpers
|
||||
|
||||
let makeTest = (str, result) => test(str, () => expectEvalToBe(str, result))
|
||||
let testEval = (str, result) => test(str, () => expectEvalToBe(str, result))
|
||||
|
||||
describe("eval", () => {
|
||||
Only.describe("expressions", () => {
|
||||
makeTest("normal(5,2)", "Ok(Normal(5,2))")
|
||||
makeTest("5 to 2", "Error(TODO: Low value must be less than high value.)")
|
||||
makeTest("to(2,5)", "Ok(Lognormal(1.1512925464970227,0.278507821238345))")
|
||||
makeTest("to(-2,2)", "Ok(Normal(0,1.215913388057542))")
|
||||
makeTest("lognormal(5,2)", "Ok(Lognormal(5,2))")
|
||||
makeTest("mean(normal(5,2))", "Ok(5)")
|
||||
makeTest("mean(lognormal(1,2))", "Ok(20.085536923187668)")
|
||||
makeTest("normalize(normal(5,2))", "Ok(Normal(5,2))")
|
||||
makeTest("toPointSet(normal(5,2))", "Ok(Point Set Distribution)")
|
||||
makeTest("toSampleSet(normal(5,2), 100)", "Ok(Sample Set Distribution)")
|
||||
makeTest("add(normal(5,2), normal(10,2))", "Ok(Normal(15,2.8284271247461903))")
|
||||
makeTest("add(normal(5,2), lognormal(10,2))", "Ok(Sample Set Distribution)")
|
||||
makeTest("dotAdd(normal(5,2), lognormal(10,2))", "Ok(Point Set Distribution)")
|
||||
makeTest("dotAdd(normal(5,2), 3)", "Ok(Point Set Distribution)")
|
||||
makeTest("add(normal(5,2), 3)", "Ok(Point Set Distribution)")
|
||||
makeTest("add(3, normal(5,2))", "Ok(Point Set Distribution)")
|
||||
makeTest("3+normal(5,2)", "Ok(Point Set Distribution)")
|
||||
makeTest("add(3, 3)", "Ok(6)")
|
||||
makeTest("truncateLeft(normal(5,2), 3)", "Ok(Point Set Distribution)")
|
||||
testEval("normal(5,2)", "Ok(Normal(5,2))")
|
||||
testEval("5 to 2", "Error(TODO: Low value must be less than high value.)")
|
||||
testEval("to(2,5)", "Ok(Lognormal(1.1512925464970227,0.278507821238345))")
|
||||
testEval("to(-2,2)", "Ok(Normal(0,1.215913388057542))")
|
||||
testEval("lognormal(5,2)", "Ok(Lognormal(5,2))")
|
||||
testEval("mean(normal(5,2))", "Ok(5)")
|
||||
testEval("mean(lognormal(1,2))", "Ok(20.085536923187668)")
|
||||
testEval("normalize(normal(5,2))", "Ok(Normal(5,2))")
|
||||
testEval("toPointSet(normal(5,2))", "Ok(Point Set Distribution)")
|
||||
testEval("toSampleSet(normal(5,2), 100)", "Ok(Sample Set Distribution)")
|
||||
testEval("add(normal(5,2), normal(10,2))", "Ok(Normal(15,2.8284271247461903))")
|
||||
testEval("add(normal(5,2), lognormal(10,2))", "Ok(Sample Set Distribution)")
|
||||
testEval("dotAdd(normal(5,2), lognormal(10,2))", "Ok(Point Set Distribution)")
|
||||
testEval("dotAdd(normal(5,2), 3)", "Ok(Point Set Distribution)")
|
||||
testEval("add(normal(5,2), 3)", "Ok(Point Set Distribution)")
|
||||
testEval("add(3, normal(5,2))", "Ok(Point Set Distribution)")
|
||||
testEval("3+normal(5,2)", "Ok(Point Set Distribution)")
|
||||
testEval("add(3, 3)", "Ok(6)")
|
||||
testEval("truncateLeft(normal(5,2), 3)", "Ok(Point Set Distribution)")
|
||||
})
|
||||
})
|
||||
|
|
|
@ -12,17 +12,17 @@ module Helpers = {
|
|||
let arithmeticMap = r =>
|
||||
switch r {
|
||||
| "add" => #Add
|
||||
| "dotAdd" => #Add
|
||||
| "pointwiseAdd" => #Add
|
||||
| "subtract" => #Subtract
|
||||
| "dotSubtract" => #Subtract
|
||||
| "pointwiseSubtract" => #Subtract
|
||||
| "divide" => #Divide
|
||||
| "logarithm" => #Logarithm
|
||||
| "dotDivide" => #Divide
|
||||
| "pointwiseDivide" => #Divide
|
||||
| "exponentiate" => #Exponentiate
|
||||
| "dotExponentiate" => #Exponentiate
|
||||
| "pointwiseExponentiate" => #Exponentiate
|
||||
| "multiply" => #Multiply
|
||||
| "dotMultiply" => #Multiply
|
||||
| "dotLogarithm" => #Logarithm
|
||||
| "pointwiseMultiply" => #Multiply
|
||||
| "pointwiseLogarithm" => #Logarithm
|
||||
| _ => #Multiply
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ module SymbolicConstructors = {
|
|||
let oneFloat = name =>
|
||||
switch name {
|
||||
| "exponential" => Ok(SymbolicDist.Exponential.make)
|
||||
| _ => Error("impossible path")
|
||||
| _ => Error("Unreachable state")
|
||||
}
|
||||
|
||||
let twoFloat = name =>
|
||||
|
@ -75,13 +75,13 @@ module SymbolicConstructors = {
|
|||
| "beta" => Ok(SymbolicDist.Beta.make)
|
||||
| "lognormal" => Ok(SymbolicDist.Lognormal.make)
|
||||
| "to" => Ok(SymbolicDist.From90thPercentile.make)
|
||||
| _ => Error("impossible path")
|
||||
| _ => Error("Unreachable state")
|
||||
}
|
||||
|
||||
let threeFloat = name =>
|
||||
switch name {
|
||||
| "triangular" => Ok(SymbolicDist.Triangular.make)
|
||||
| _ => Error("impossible path")
|
||||
| _ => Error("Unreachable state")
|
||||
}
|
||||
|
||||
let symbolicResultToOutput = (
|
||||
|
@ -128,12 +128,20 @@ let dispatchToGenericOutput = (call: ExpressionValue.functionCall): option<
|
|||
Helpers.toDistFn(Truncate(None, Some(float)), dist)
|
||||
| ("truncate", [EvDistribution(dist), EvNumber(float1), EvNumber(float2)]) =>
|
||||
Helpers.toDistFn(Truncate(Some(float1), Some(float2)), dist)
|
||||
| (("add" | "multiply" | "subtract" | "divide" | "exponentiate" | "log") as arithmetic, [a, b] as args) =>
|
||||
| (
|
||||
("add" | "multiply" | "subtract" | "divide" | "exponentiate" | "log") as arithmetic,
|
||||
[a, b] as args,
|
||||
) =>
|
||||
Helpers.catchAndConvertTwoArgsToDists(args)->E.O2.fmap(((fst, snd)) =>
|
||||
Helpers.twoDiststoDistFn(Algebraic, arithmetic, fst, snd)
|
||||
)
|
||||
| (
|
||||
("dotAdd" | "dotMultiply" | "dotSubtract" | "dotDivide" | "dotExponentiate" | "dotLogarithm") as arithmetic,
|
||||
("pointwiseAdd"
|
||||
| "pointwiseMultiply"
|
||||
| "pointwiseSubtract"
|
||||
| "pointwiseDivide"
|
||||
| "pointwiseExponentiate"
|
||||
| "pointwiseLogarithm") as arithmetic,
|
||||
[a, b] as args,
|
||||
) =>
|
||||
Helpers.catchAndConvertTwoArgsToDists(args)->E.O2.fmap(((fst, snd)) =>
|
||||
|
|
Loading…
Reference in New Issue
Block a user