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:
somebody1234 2023-11-01 23:07:18 +10:00 committed by GitHub
parent f37ec96149
commit 8bc17bd370
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)