mirror of
https://github.com/enso-org/enso.git
synced 2024-11-26 08:52:58 +03:00
Fix flaky partitionPoint
test (#8198)
The tests for `partitionPoint` were previously failing when `NaN` or duplicates were present in the array. # Important Notes None
This commit is contained in:
parent
f37ec96149
commit
8bc17bd370
@ -14,18 +14,26 @@ fcTest.prop({
|
||||
})
|
||||
|
||||
fcTest.prop({
|
||||
arr: fc
|
||||
.array(fc.float())
|
||||
.map((a) => ({ arr: a.sort((a, b) => a - b), i: Math.floor(Math.random() * a.length) })),
|
||||
arr: fc.array(fc.float({ noNaN: true })).chain((a) => {
|
||||
const sorted = a.sort((a, b) => a - b)
|
||||
return fc.record({
|
||||
arr: fc.constant(sorted),
|
||||
i: fc.nat({ max: Math.max(sorted.length - 1, 0) }).map((i) => Math.max(0, a.indexOf(a[i]!))),
|
||||
})
|
||||
}),
|
||||
})('partitionPoint (ascending)', ({ arr: { arr, i } }) => {
|
||||
const target = arr[i]!
|
||||
expect(partitionPoint(arr, (n) => n < target)).toEqual(i)
|
||||
})
|
||||
|
||||
fcTest.prop({
|
||||
arr: fc
|
||||
.array(fc.float())
|
||||
.map((a) => ({ arr: a.sort((a, b) => b - a), i: Math.floor(Math.random() * a.length) })),
|
||||
arr: fc.array(fc.float({ noNaN: true })).chain((a) => {
|
||||
const sorted = a.sort((a, b) => b - a)
|
||||
return fc.record({
|
||||
arr: fc.constant(sorted),
|
||||
i: fc.nat({ max: Math.max(sorted.length - 1, 0) }).map((i) => Math.max(0, a.indexOf(a[i]!))),
|
||||
})
|
||||
}),
|
||||
})('partitionPoint (descending)', ({ arr: { arr, i } }) => {
|
||||
const target = arr[i]!
|
||||
expect(partitionPoint(arr, (n) => n > target)).toEqual(i)
|
||||
|
Loading…
Reference in New Issue
Block a user