Refactor and rename checkOrdered
This commit is contained in:
parent
d7151907d3
commit
f9c02ba626
|
@ -4,7 +4,7 @@ open TestHelpers
|
||||||
describe("combine with discrete", () => {
|
describe("combine with discrete", () => {
|
||||||
makeTest(
|
makeTest(
|
||||||
"keep order when multiplying by negative number",
|
"keep order when multiplying by negative number",
|
||||||
AlgebraicShapeCombination.checkOrdered(
|
AlgebraicShapeCombination.isOrdered(
|
||||||
AlgebraicShapeCombination.combineShapesContinuousDiscrete(
|
AlgebraicShapeCombination.combineShapesContinuousDiscrete(
|
||||||
#Multiply,
|
#Multiply,
|
||||||
{xs: [0., 1.], ys: [1., 1.]},
|
{xs: [0., 1.], ys: [1., 1.]},
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -363,6 +363,9 @@ module A = {
|
||||||
|> Rationale.Result.return
|
|> Rationale.Result.return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let tail = Belt.Array.sliceToEnd(_, 1)
|
||||||
|
|
||||||
|
let zip = Belt.Array.zip
|
||||||
// This zips while taking the longest elements of each array.
|
// This zips while taking the longest elements of each array.
|
||||||
let zipMaxLength = (array1, array2) => {
|
let zipMaxLength = (array1, array2) => {
|
||||||
let maxLength = Int.max(length(array1), length(array2))
|
let maxLength = Int.max(length(array1), length(array2))
|
||||||
|
@ -506,6 +509,9 @@ module A = {
|
||||||
}
|
}
|
||||||
|
|
||||||
module Floats = {
|
module Floats = {
|
||||||
|
let isSorted = (ar: array<float>): bool =>
|
||||||
|
reduce(zip(ar, tail(ar)), true, (acc, (first, second)) => acc && first < second)
|
||||||
|
|
||||||
let makeIncrementalUp = (a, b) =>
|
let makeIncrementalUp = (a, b) =>
|
||||||
Array.make(b - a + 1, a) |> Array.mapi((i, c) => c + i) |> Belt.Array.map(_, float_of_int)
|
Array.make(b - a + 1, a) |> Array.mapi((i, c) => c + i) |> Belt.Array.map(_, float_of_int)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user