squiggle/packages/squiggle-lang/__tests__/E/splitContinuousAndDiscrete_test.res

48 lines
1.6 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
2022-04-28 11:36:53 +00:00
let prepareInputs = (ar, minWeight) =>
2022-10-05 20:02:10 +00:00
E.FloatArray.Sorted.splitContinuousAndDiscreteForMinWeight(
ar->E.FloatArray.make,
~minDiscreteWeight=minWeight,
) |> (((c, disc)) => (c->E.FloatArray.toArray, disc->E.FloatFloatMap.toArray))
2022-04-28 11:36:53 +00:00
describe("Continuous and discrete splits", () => {
2022-04-07 03:01:17 +00:00
makeTest(
2022-04-28 11:36:53 +00:00
"is empty, with no common elements",
prepareInputs([1.33455, 1.432, 2.0], 2),
2022-04-28 11:36:53 +00:00
([1.33455, 1.432, 2.0], []),
)
makeTest(
2022-04-28 11:36:53 +00:00
"only stores 3.5 as discrete when minWeight is 3",
prepareInputs([1.33455, 1.432, 2.0, 2.0, 3.5, 3.5, 3.5], 3),
([1.33455, 1.432, 2.0, 2.0], [(3.5, 3.0)]),
)
makeTest(
2022-04-28 11:36:53 +00:00
"doesn't store 3.5 as discrete when minWeight is 5",
prepareInputs([1.33455, 1.432, 2.0, 2.0, 3.5, 3.5, 3.5], 5),
([1.33455, 1.432, 2.0, 2.0, 3.5, 3.5, 3.5], []),
2022-04-07 03:01:17 +00:00
)
makeTest(
"more general test",
prepareInputs([10., 10., 11., 11., 11., 12., 13., 13., 13., 13., 13., 14.], 3),
([10., 10., 12., 14.], [(11., 3.), (13., 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)
}
2022-10-05 20:02:10 +00:00
let (_, toArr1) = prepareInputs(makeDuplicatedArray(10), 2)
makeTest("splitMedium at count=10", toArr1->Belt.Array.length, 10)
2022-04-07 03:01:17 +00:00
2022-10-05 20:02:10 +00:00
let (_, toArr2) = prepareInputs(makeDuplicatedArray(500), 2)
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
})