it string in tests

This commit is contained in:
Quinn Dougherty 2022-09-01 12:54:04 +08:00
parent 9366ce61f3
commit ab5b54413b
2 changed files with 8 additions and 4 deletions

View File

@ -7,10 +7,14 @@ let makeTest = (~only=false, str, item1, item2) =>
: test(str, () => expect(item1)->toEqual(item2))
describe("Stdlib", () => {
makeTest("min", Stdlib.Random.sample([1.0, 2.0], {probs: [0.5, 0.5], size: 10}) |> E.A.length, 10)
makeTest(
"min",
Stdlib.Random.sample([1.0, 2.0], {probs: [0.5, 0.5], size: 10}) |> E.A.uniq |> E.A.Floats.sort,
"Length of Random.sample",
Stdlib.Random.sample([1.0, 2.0], {probs: [0.5, 0.5], size: 10})->E.A.length,
10,
)
makeTest(
"Random.sample returns elements from input array (will fail with very slim probability)",
Stdlib.Random.sample([1.0, 2.0], {probs: [0.5, 0.5], size: 10})->E.A.uniq->E.A.Floats.sort,
[1.0, 2.0],
)
})

View File

@ -226,6 +226,6 @@ module T = Dist({
})
let sampleN = (t: t, n): array<float> => {
let normalized = t |> T.normalize |> getShape
let normalized = t->T.normalize->getShape
Stdlib.Random.sample(normalized.xs, {probs: normalized.ys, size: n})
}