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

58 lines
1.8 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)",
E.A.Sorted.Floats.splitContinuousAndDiscreteForMinWeight([1.432, 1.33455, 2.0], 2),
([1.33455, 1.432, 2.0], E.FloatFloatMap.empty()),
2022-04-07 03:01:17 +00:00
)
makeTest(
2022-04-07 22:38:49 +00:00
"splits (2)",
E.A.Sorted.Floats.splitContinuousAndDiscreteForMinWeight(
[1.432, 1.33455, 2.0, 2.0, 2.0, 2.0],
2,
) |> (((c, disc)) => (c, disc |> E.FloatFloatMap.toArray)),
([1.33455, 1.432], [(2.0, 4.0)]),
)
makeTest(
"splits (3)",
E.A.Sorted.Floats.splitContinuousAndDiscreteForMinWeight(
[1.432, 1.33455, 2.0, 2.0, 3.5, 3.5, 3.5],
3,
) |> (((c, disc)) => (c, disc |> E.FloatFloatMap.toArray)),
([1.33455, 1.432, 2.0, 2.0], [(3.5, 3.0)]),
)
makeTest(
"splits (3)",
E.A.Sorted.Floats.splitContinuousAndDiscreteForMinWeight(
[1.432, 1.33455, 2.0, 2.0, 3.5, 3.5, 3.5],
5,
) |> (((c, disc)) => (c, disc |> E.FloatFloatMap.toArray)),
([1.33455, 1.432, 2.0, 2.0, 3.5, 3.5, 3.5], []),
2022-04-07 03:01:17 +00:00
)
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 (_, discrete1) = E.A.Sorted.Floats.splitContinuousAndDiscreteForMinWeight(
2022-04-07 03:01:17 +00:00
makeDuplicatedArray(10),
2,
2022-04-07 03:01:17 +00:00
)
2022-04-08 00:13:08 +00:00
let toArr1 = discrete1 |> E.FloatFloatMap.toArray
makeTest("splitMedium at count=10", toArr1 |> Belt.Array.length, 10)
2022-04-07 03:01:17 +00:00
let (_c, discrete2) = E.A.Sorted.Floats.splitContinuousAndDiscreteForMinWeight(
2022-04-07 03:01:17 +00:00
makeDuplicatedArray(500),
2,
2022-04-07 03:01:17 +00:00
)
2022-04-08 00:13:08 +00:00
let toArr2 = discrete2 |> E.FloatFloatMap.toArray
makeTest("splitMedium at count=500", toArr2 |> Belt.Array.length, 500)
2022-04-26 15:59:07 +00:00
// makeTest("foo", [] |> Belt.Array.length, 500)
2022-04-07 03:01:17 +00:00
})