-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort.test.js.ts
47 lines (45 loc) · 1.82 KB
/
sort.test.js.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { describe, it } from 'mocha'
import { expect } from 'chai'
import { DirectSelectSort } from "./src/algorithm/sort/DirectSelect";
import { DirectInsertSort } from './src/algorithm/sort/DirectInsert';
import { ShellSort } from './src/algorithm/sort/ShellSort';
import { BubbleSort } from "./src/algorithm/sort/BubbleSort";
import {QuickSort} from "./src/algorithm/sort/QuickSort";
import {MergeSort} from "./src/algorithm/sort/MergeSort";
let arr = [1, 5, 7, 0, 10, -1];
let result = [-1, 0, 1, 5, 7, 10];
let arr1 = [1, 5, 7, 0, 10, -1, 12, 23, -5, 120, -120, 465, 13];
let result1 = [ -120, -5, -1, 0, 1, 5, 7, 10, 12, 13, 23, 120, 465 ];
let arr2 = [4, 6, 2]
let result2 = [2, 4, 6]
let arr3 = [4, 4, 6, 2, 1]
let result3 = [1, 2, 4, 4, 6]
describe('directSort', () => {
it('test directSelectSort', () => {
expect(DirectSelectSort([...arr]).join(',')).to.equal(result.join(','))
})
it('test directInsertSort', () => {
expect(DirectInsertSort([...arr]).join(',')).to.equal(result.join(','))
})
it('test ShellSort', () => {
expect(ShellSort([...arr]).join(',')).to.equal(result.join(','))
})
it('test BubbleSort', () => {
expect(BubbleSort([...arr]).join(',')).to.equal(result.join(','))
})
it('test QuickSort', () => {
expect(QuickSort([...arr]).join(',')).to.equal(result.join(','))
})
it('test QuickSort case 2', () => {
expect(QuickSort([...arr1]).join(',')).to.equal(result1.join(','))
})
it('test QuickSort case 3', () => {
expect(QuickSort([...arr2]).join(',')).to.equal(result2.join(','))
})
it('test QuickSort case 4', () => {
expect(QuickSort([...arr3]).join(',')).to.equal(result3.join(','))
})
it('test MergeSort', () => {
expect(MergeSort([...arr1]).join(',')).to.equal(result1.join(','))
})
});