yarn format

This commit is contained in:
Quinn Dougherty 2022-04-13 19:18:08 -04:00
parent 24fe66c9d3
commit b0ff2c19f5
4 changed files with 43 additions and 34 deletions

View File

@ -16,7 +16,7 @@ module Internals = {
let epsilon = 1e3 let epsilon = 1e3
let mean = GenericDist_Types.Constructors.UsingDists.mean let mean = GenericDist_Types.Constructors.UsingDists.mean
let expectImpossiblePath: string => assertion = algebraicOp => let expectImpossiblePath: string => assertion = algebraicOp =>
`${algebraicOp} has`->expect->toEqual("failed") `${algebraicOp} has`->expect->toEqual("failed")
@ -37,25 +37,24 @@ module Internals = {
} }
let testOperationMean = ( let testOperationMean = (
distOp: (DistributionTypes.genericDist, DistributionTypes.genericDist) => result<DistributionTypes.genericDist, DistributionTypes.error>, distOp: (
description: string, DistributionTypes.genericDist,
floatOp: (float, float) => float, DistributionTypes.genericDist,
dist1': SymbolicDistTypes.symbolicDist, ) => result<DistributionTypes.genericDist, DistributionTypes.error>,
dist2': SymbolicDistTypes.symbolicDist, description: string,
~epsilon: float floatOp: (float, float) => float,
) => { dist1': SymbolicDistTypes.symbolicDist,
let dist1 = dist1'->DistributionTypes.Symbolic // ->DistributionTypes.Other dist2': SymbolicDistTypes.symbolicDist,
let dist2 = dist2'->DistributionTypes.Symbolic // ->DistributionTypes.Other ~epsilon: float,
) => {
let dist1 = dist1'->DistributionTypes.Symbolic // ->DistributionTypes.Other
let dist2 = dist2'->DistributionTypes.Symbolic // ->DistributionTypes.Other
let received = let received =
distOp(dist1, dist2) distOp(dist1, dist2)->E.R2.fmap(mean)->E.R2.fmap(run)->E.R2.fmap(toFloat)->E.R.toExn
->E.R2.fmap(mean)
->E.R2.fmap(run)
->E.R2.fmap(toFloat)
->E.R.toExn
let expected = floatOp(runMean(dist1), runMean(dist2)) let expected = floatOp(runMean(dist1), runMean(dist2))
switch received { switch received {
| None => expectImpossiblePath(description) | None => expectImpossiblePath(description)
| Some(x) => expectErrorToBeBounded(x, expected, ~epsilon=epsilon) | Some(x) => expectErrorToBeBounded(x, expected, ~epsilon)
} }
} }
} }
@ -79,58 +78,67 @@ let algebraicPower = algebraicPower(~env)
let {testOperationMean, distributions, pairsOfDifferentDistributions, epsilon} = module(Internals) let {testOperationMean, distributions, pairsOfDifferentDistributions, epsilon} = module(Internals)
describe("Means invariant", () => { describe("Means invariant", () => {
describe("for addition", () => { describe("for addition", () => {
let testAdditionMean = testOperationMean(algebraicAdd, "algebraicAdd", \"+.", ~epsilon=epsilon) let testAdditionMean = testOperationMean(algebraicAdd, "algebraicAdd", \"+.", ~epsilon)
testAll("of two of the same distribution", distributions, dist => { testAll("of two of the same distribution", distributions, dist => {
E.R.liftM2(testAdditionMean, dist, dist) -> E.R.toExn E.R.liftM2(testAdditionMean, dist, dist)->E.R.toExn
}) })
testAll("of two different distributions", pairsOfDifferentDistributions, dists => { testAll("of two different distributions", pairsOfDifferentDistributions, dists => {
let (dist1, dist2) = dists let (dist1, dist2) = dists
E.R.liftM2(testAdditionMean, dist1, dist2) -> E.R.toExn E.R.liftM2(testAdditionMean, dist1, dist2)->E.R.toExn
}) })
testAll("of two difference distributions", pairsOfDifferentDistributions, dists => { testAll("of two difference distributions", pairsOfDifferentDistributions, dists => {
let (dist1, dist2) = dists let (dist1, dist2) = dists
E.R.liftM2(testAdditionMean, dist2, dist1) -> E.R.toExn E.R.liftM2(testAdditionMean, dist2, dist1)->E.R.toExn
}) })
}) })
describe("for subtraction", () => { describe("for subtraction", () => {
let testSubtractionMean = testOperationMean(algebraicSubtract, "algebraicSubtract", \"-.", ~epsilon=epsilon) let testSubtractionMean = testOperationMean(
algebraicSubtract,
"algebraicSubtract",
\"-.",
~epsilon,
)
testAll("of two of the same distribution", distributions, dist => { testAll("of two of the same distribution", distributions, dist => {
E.R.liftM2(testSubtractionMean, dist, dist) -> E.R.toExn E.R.liftM2(testSubtractionMean, dist, dist)->E.R.toExn
}) })
testAll("of two different distributions", pairsOfDifferentDistributions, dists => { testAll("of two different distributions", pairsOfDifferentDistributions, dists => {
let (dist1, dist2) = dists let (dist1, dist2) = dists
E.R.liftM2(testSubtractionMean, dist1, dist2) -> E.R.toExn E.R.liftM2(testSubtractionMean, dist1, dist2)->E.R.toExn
}) })
testAll("of two different distributions", pairsOfDifferentDistributions, dists => { testAll("of two different distributions", pairsOfDifferentDistributions, dists => {
let (dist1, dist2) = dists let (dist1, dist2) = dists
E.R.liftM2(testSubtractionMean, dist2, dist1) -> E.R.toExn E.R.liftM2(testSubtractionMean, dist2, dist1)->E.R.toExn
}) })
}) })
describe("for multiplication", () => { describe("for multiplication", () => {
let testMultiplicationMean = testOperationMean(algebraicMultiply, "algebraicMultiply", \"*.", ~epsilon=epsilon) let testMultiplicationMean = testOperationMean(
algebraicMultiply,
"algebraicMultiply",
\"*.",
~epsilon,
)
testAll("of two of the same distribution", distributions, dist => { testAll("of two of the same distribution", distributions, dist => {
E.R.liftM2(testMultiplicationMean, dist, dist) -> E.R.toExn E.R.liftM2(testMultiplicationMean, dist, dist)->E.R.toExn
}) })
testAll("of two different distributions", pairsOfDifferentDistributions, dists => { testAll("of two different distributions", pairsOfDifferentDistributions, dists => {
let (dist1, dist2) = dists let (dist1, dist2) = dists
E.R.liftM2(testMultiplicationMean, dist1, dist2) -> E.R.toExn E.R.liftM2(testMultiplicationMean, dist1, dist2)->E.R.toExn
}) })
testAll("of two different distributions", pairsOfDifferentDistributions, dists => { testAll("of two different distributions", pairsOfDifferentDistributions, dists => {
let (dist1, dist2) = dists let (dist1, dist2) = dists
E.R.liftM2(testMultiplicationMean, dist2, dist1) -> E.R.toExn E.R.liftM2(testMultiplicationMean, dist2, dist1)->E.R.toExn
}) })
}) })
}) })

View File

@ -8,7 +8,7 @@ let expectErrorToBeBounded = (received, expected, ~epsilon) => {
} else { } else {
distance /. Js.Math.abs_float(expected) distance /. Js.Math.abs_float(expected)
} }
error -> expect -> toBeLessThan(epsilon) error->expect->toBeLessThan(epsilon)
} }
let makeTest = (~only=false, str, item1, item2) => let makeTest = (~only=false, str, item1, item2) =>

View File

@ -117,7 +117,8 @@ module Helpers = {
| Error(err) => GenDistError(ArgumentError(err)) | Error(err) => GenDistError(ArgumentError(err))
} }
} }
| Some(EvDistribution(b)) => switch parseDistributionArray(args) { | Some(EvDistribution(b)) =>
switch parseDistributionArray(args) {
| Ok(distributions) => mixtureWithDefaultWeights(distributions) | Ok(distributions) => mixtureWithDefaultWeights(distributions)
| Error(err) => GenDistError(ArgumentError(err)) | Error(err) => GenDistError(ArgumentError(err))
} }

View File

@ -215,8 +215,8 @@ module R2 = {
| Ok(r) => Ok(r) | Ok(r) => Ok(r)
| Error(e) => map(e) | Error(e) => map(e)
} }
let fmap2 = (xR, f) => let fmap2 = (xR, f) =>
switch xR { switch xR {
| Ok(x) => x->Ok | Ok(x) => x->Ok
| Error(x) => x->f->Error | Error(x) => x->f->Error