Skip to content

Commit 0b36004

Browse files
committed
update unit test
1 parent 27f10de commit 0b36004

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/lib/sorts/quick/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ async function quick_sort(
4242

4343
let animate: boolean = false
4444

45-
// base case
4645
if (n <= 0 || !isSorting()) {
4746
return { arr, key, order, n, execTime: 0, animate: false }
4847
}
@@ -86,6 +85,7 @@ function helper(helperInput: HelperInput) {
8685
animate,
8786
} = helperInput
8887

88+
// base case
8989
// the leaf workers either 1 or 0
9090
if (startIdx >= endIdx) return
9191

test/sorts/quick/index.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,22 @@ describe('quick sort', () => {
8383
// expect(arrOfNums).toEqual(sorted().arr.numbers)
8484
// expect(animate).toEqual(false)
8585
// })
86+
test('cases[8]: should sort correctly when switching partition type to "hoare"', async () => {
87+
const partitionType = 'hoare'
88+
const obj = {
89+
arr: unsorted().arr.numbers,
90+
}
91+
const { arr: arrOfNums } = await quick(obj, partitionType)
92+
expect(arrOfNums).toEqual(sorted().arr.numbers)
93+
94+
let key = 'height',
95+
order = 'desc'
96+
const obj1 = {
97+
arr: unsorted({ key }).arr.objects,
98+
key,
99+
order,
100+
}
101+
const { arr: arrOfObjs } = await quick(obj1, partitionType)
102+
expect(arrOfObjs).toEqual(sorted({ key, order }).arr.objects)
103+
})
86104
})

0 commit comments

Comments
 (0)