Refactored tests to use GenericOperation
This commit is contained in:
parent
0fa954ae63
commit
837088a9c6
|
@ -1,24 +0,0 @@
|
||||||
open Jest
|
|
||||||
open Expect
|
|
||||||
|
|
||||||
let {normalDist, uniformDist, betaDist, lognormalDist, cauchyDist, triangularDist, exponentialDist} = module(GenericDist_Fixtures)
|
|
||||||
|
|
||||||
let runTest = (name: string, dist : GenericDist_Types.genericDist, expected: string) => {
|
|
||||||
test(name, () => {
|
|
||||||
let result = GenericDist.toSparkline(dist, ~sampleCount=100, ~buckets=20, ())
|
|
||||||
switch result {
|
|
||||||
| Ok(sparkline) => expect(sparkline)->toEqual(expected)
|
|
||||||
| Error(err) => expect("Error")->toEqual(expected)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("sparkline of generic distribution", () => {
|
|
||||||
runTest("normal", normalDist, `▁▁▁▁▁▂▄▆▇██▇▆▄▂▁▁▁▁▁`)
|
|
||||||
runTest("uniform", uniformDist, `████████████████████`)
|
|
||||||
runTest("beta", betaDist, `▁▄▇████▇▆▅▄▃▃▂▁▁▁▁▁▁`)
|
|
||||||
runTest("lognormal", lognormalDist, `▁█▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁`)
|
|
||||||
runTest("cauchy", cauchyDist, `▁▁▁▁▁▁▁▁▁██▁▁▁▁▁▁▁▁▁`)
|
|
||||||
runTest("triangular", triangularDist, `▁▁▂▃▄▅▆▇████▇▆▅▄▃▂▁▁`)
|
|
||||||
runTest("exponential", exponentialDist, `█▅▄▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁`)
|
|
||||||
})
|
|
|
@ -6,8 +6,18 @@ let env: DistributionOperation.env = {
|
||||||
xyPointLength: 100,
|
xyPointLength: 100,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let {
|
||||||
let {normalDist5, normalDist10, normalDist20, uniformDist} = module(GenericDist_Fixtures)
|
normalDist5,
|
||||||
|
normalDist10,
|
||||||
|
normalDist20,
|
||||||
|
normalDist,
|
||||||
|
uniformDist,
|
||||||
|
betaDist,
|
||||||
|
lognormalDist,
|
||||||
|
cauchyDist,
|
||||||
|
triangularDist,
|
||||||
|
exponentialDist,
|
||||||
|
} = module(GenericDist_Fixtures)
|
||||||
let {toFloat, toDist, toString, toError} = module(DistributionOperation.Output)
|
let {toFloat, toDist, toString, toError} = module(DistributionOperation.Output)
|
||||||
let {run} = module(DistributionOperation)
|
let {run} = module(DistributionOperation)
|
||||||
let {fmap} = module(DistributionOperation.Output)
|
let {fmap} = module(DistributionOperation.Output)
|
||||||
|
@ -42,6 +52,57 @@ describe("mixture", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("sparkline", () => {
|
||||||
|
let runTest = (
|
||||||
|
name: string,
|
||||||
|
dist: GenericDist_Types.genericDist,
|
||||||
|
expected: DistributionOperation.outputType,
|
||||||
|
) => {
|
||||||
|
test(name, () => {
|
||||||
|
let result = DistributionOperation.run(~env, FromDist(ToSparkline(20), dist))
|
||||||
|
expect(result)->toEqual(expected)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
runTest(
|
||||||
|
"normal",
|
||||||
|
normalDist,
|
||||||
|
String(`▁▁▁▁▁▂▄▆▇██▇▆▄▂▁▁▁▁▁`),
|
||||||
|
)
|
||||||
|
|
||||||
|
runTest(
|
||||||
|
"uniform",
|
||||||
|
uniformDist,
|
||||||
|
String(`████████████████████`),
|
||||||
|
)
|
||||||
|
|
||||||
|
runTest("beta", betaDist, String(`▁▄▇████▇▆▅▄▃▃▂▁▁▁▁▁▁`))
|
||||||
|
|
||||||
|
runTest(
|
||||||
|
"lognormal",
|
||||||
|
lognormalDist,
|
||||||
|
String(`▁█▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁`),
|
||||||
|
)
|
||||||
|
|
||||||
|
runTest(
|
||||||
|
"cauchy",
|
||||||
|
cauchyDist,
|
||||||
|
String(`▁▁▁▁▁▁▁▁▁██▁▁▁▁▁▁▁▁▁`),
|
||||||
|
)
|
||||||
|
|
||||||
|
runTest(
|
||||||
|
"triangular",
|
||||||
|
triangularDist,
|
||||||
|
String(`▁▁▂▃▄▅▆▇████▇▆▅▄▃▂▁▁`),
|
||||||
|
)
|
||||||
|
|
||||||
|
runTest(
|
||||||
|
"exponential",
|
||||||
|
exponentialDist,
|
||||||
|
String(`█▅▄▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁`),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
describe("toPointSet", () => {
|
describe("toPointSet", () => {
|
||||||
test("on symbolic normal distribution", () => {
|
test("on symbolic normal distribution", () => {
|
||||||
let result =
|
let result =
|
||||||
|
|
Loading…
Reference in New Issue
Block a user