squiggle/packages/squiggle-lang/__tests__/Distributions/Samples_test.res

42 lines
1.2 KiB
Plaintext
Raw Normal View History

2022-04-07 03:01:17 +00:00
open Jest
2022-04-07 22:38:49 +00:00
open TestHelpers
2022-04-07 03:01:17 +00:00
describe("Continuous and discrete splits", () => {
makeTest(
2022-04-07 22:38:49 +00:00
"splits (1)",
2022-04-07 03:01:17 +00:00
SampleSet.Internals.T.splitContinuousAndDiscrete([1.432, 1.33455, 2.0]),
([1.432, 1.33455, 2.0], E.FloatFloatMap.empty()),
)
makeTest(
2022-04-07 22:38:49 +00:00
"splits (2)",
2022-04-07 03:01:17 +00:00
SampleSet.Internals.T.splitContinuousAndDiscrete([
1.432,
1.33455,
2.0,
2.0,
2.0,
2.0,
]) |> (((c, disc)) => (c, disc |> E.FloatFloatMap.toArray)),
([1.432, 1.33455], [(2.0, 4.0)]),
)
let makeDuplicatedArray = count => {
let arr = Belt.Array.range(1, count) |> E.A.fmap(float_of_int)
let sorted = arr |> Belt.SortArray.stableSortBy(_, compare)
E.A.concatMany([sorted, sorted, sorted, sorted]) |> Belt.SortArray.stableSortBy(_, compare)
}
let (_, discrete) = SampleSet.Internals.T.splitContinuousAndDiscrete(
makeDuplicatedArray(10),
)
let toArr = discrete |> E.FloatFloatMap.toArray
makeTest("splitMedium at count=10", toArr |> Belt.Array.length, 10)
let (_c, discrete) = SampleSet.Internals.T.splitContinuousAndDiscrete(
makeDuplicatedArray(500),
)
let toArr = discrete |> E.FloatFloatMap.toArray
makeTest("splitMedium at count=500", toArr |> Belt.Array.length, 500)
})