Skip to content

Commit

Permalink
Fix flaky partitionPoint test (#8198)
Browse files Browse the repository at this point in the history
The tests for `partitionPoint` were previously failing when `NaN` or duplicates were present in the array.

# Important Notes
None
  • Loading branch information
somebody1234 authored Nov 1, 2023
1 parent f37ec96 commit 8bc17bd
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions app/gui2/src/util/__tests__/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8bc17bd

Please sign in to comment.