Skip to content

Commit

Permalink
test: improve coverage for array/fixedarray_sort_by.mbt
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l authored and bobzhang committed Dec 19, 2024
1 parent 1fae2a3 commit 408334e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions array/fixedarray_sort_by.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,19 @@ test "sort_by" {
arr.sort_by_key(fn(x) { -x })
assert_eq!(arr, [5, 4, 3, 2, 1])
}

test "sort_by_fallback" {
// Creating a large array that will trigger heap sort
let arr = FixedArray::makei(100, fn(i) { if i % 2 == 0 { 1 } else { 0 } })
arr.sort_by(fn(a, b) {
// this comparison function always returns -1 or 1
// which creates many imbalanced partitions
// and eventually triggers heap sort when limit reaches 0
if a < b {
-1
} else {
1
}
})
assert_true!(arr.is_sorted())
}

0 comments on commit 408334e

Please sign in to comment.