-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.test.ts
32 lines (22 loc) · 933 Bytes
/
sort.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { test, expect } from "vitest";
import { generateRandomNumbers } from "../src/lib/utils";
import { algorithms } from "../src/lib/implementations";
function finishGenerator(generator: Generator) {
let result = generator.next();
while (!result.done) {
result = generator.next();
}
return result.value;
}
test("Bubble sort result must be equal to default sort results", () => {
const sampleArray = generateRandomNumbers(100, 0, 100);
const defaultSort = sampleArray.slice().sort((a, b) => a - b);
finishGenerator(algorithms.bubbleSort.fn(sampleArray));
expect(sampleArray).toEqual(defaultSort);
});
test("Quick sort result must be equal to default sort results", () => {
const sampleArray = generateRandomNumbers(100, 0, 100);
const defaultSort = sampleArray.slice().sort((a, b) => a - b);
finishGenerator(algorithms.quickSort.fn(sampleArray));
expect(sampleArray).toEqual(defaultSort);
});