Refactor and rename checkOrdered

This commit is contained in:
Sam Nolan 2022-04-25 14:50:45 -04:00
parent d7151907d3
commit f9c02ba626
3 changed files with 8 additions and 2 deletions

View File

@ -4,7 +4,7 @@ open TestHelpers
describe("combine with discrete", () => {
makeTest(
"keep order when multiplying by negative number",
AlgebraicShapeCombination.checkOrdered(
AlgebraicShapeCombination.isOrdered(
AlgebraicShapeCombination.combineShapesContinuousDiscrete(
#Multiply,
{xs: [0., 1.], ys: [1., 1.]},

View File

@ -255,4 +255,4 @@ let combineShapesContinuousDiscrete = (
)
}
let checkOrdered = (a: XYShape.T.t): bool => a.xs[0] < a.xs[1]
let isOrdered = (a: XYShape.T.t): bool => E.A.Sorted.Floats.isSorted(a.xs)

View File

@ -363,6 +363,9 @@ module A = {
|> Rationale.Result.return
}
let tail = Belt.Array.sliceToEnd(_, 1)
let zip = Belt.Array.zip
// This zips while taking the longest elements of each array.
let zipMaxLength = (array1, array2) => {
let maxLength = Int.max(length(array1), length(array2))
@ -506,6 +509,9 @@ module A = {
}
module Floats = {
let isSorted = (ar: array<float>): bool =>
reduce(zip(ar, tail(ar)), true, (acc, (first, second)) => acc && first < second)
let makeIncrementalUp = (a, b) =>
Array.make(b - a + 1, a) |> Array.mapi((i, c) => c + i) |> Belt.Array.map(_, float_of_int)