mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2025-07-06 17:44:08 +08:00
Add merge sort.
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import BubbleSort from '../MergeSort';
|
import MergeSort from '../MergeSort';
|
||||||
import {
|
import {
|
||||||
equalArr,
|
equalArr,
|
||||||
notSortedArr,
|
notSortedArr,
|
||||||
@ -15,20 +15,20 @@ const EQUAL_ARRAY_VISITING_COUNT = 79;
|
|||||||
|
|
||||||
describe('MergeSort', () => {
|
describe('MergeSort', () => {
|
||||||
it('should sort array', () => {
|
it('should sort array', () => {
|
||||||
SortTester.testSort(BubbleSort);
|
SortTester.testSort(MergeSort);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should sort array with custom comparator', () => {
|
it('should sort array with custom comparator', () => {
|
||||||
SortTester.testSortWithCustomComparator(BubbleSort);
|
SortTester.testSortWithCustomComparator(MergeSort);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should do stable sorting', () => {
|
it('should do stable sorting', () => {
|
||||||
SortTester.testSortStability(BubbleSort);
|
SortTester.testSortStability(MergeSort);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should visit EQUAL array element specified number of times', () => {
|
it('should visit EQUAL array element specified number of times', () => {
|
||||||
SortTester.testAlgorithmTimeComplexity(
|
SortTester.testAlgorithmTimeComplexity(
|
||||||
BubbleSort,
|
MergeSort,
|
||||||
equalArr,
|
equalArr,
|
||||||
EQUAL_ARRAY_VISITING_COUNT,
|
EQUAL_ARRAY_VISITING_COUNT,
|
||||||
);
|
);
|
||||||
@ -36,7 +36,7 @@ describe('MergeSort', () => {
|
|||||||
|
|
||||||
it('should visit SORTED array element specified number of times', () => {
|
it('should visit SORTED array element specified number of times', () => {
|
||||||
SortTester.testAlgorithmTimeComplexity(
|
SortTester.testAlgorithmTimeComplexity(
|
||||||
BubbleSort,
|
MergeSort,
|
||||||
sortedArr,
|
sortedArr,
|
||||||
SORTED_ARRAY_VISITING_COUNT,
|
SORTED_ARRAY_VISITING_COUNT,
|
||||||
);
|
);
|
||||||
@ -44,7 +44,7 @@ describe('MergeSort', () => {
|
|||||||
|
|
||||||
it('should visit NOT SORTED array element specified number of times', () => {
|
it('should visit NOT SORTED array element specified number of times', () => {
|
||||||
SortTester.testAlgorithmTimeComplexity(
|
SortTester.testAlgorithmTimeComplexity(
|
||||||
BubbleSort,
|
MergeSort,
|
||||||
notSortedArr,
|
notSortedArr,
|
||||||
NOT_SORTED_ARRAY_VISITING_COUNT,
|
NOT_SORTED_ARRAY_VISITING_COUNT,
|
||||||
);
|
);
|
||||||
@ -52,7 +52,7 @@ describe('MergeSort', () => {
|
|||||||
|
|
||||||
it('should visit REVERSE SORTED array element specified number of times', () => {
|
it('should visit REVERSE SORTED array element specified number of times', () => {
|
||||||
SortTester.testAlgorithmTimeComplexity(
|
SortTester.testAlgorithmTimeComplexity(
|
||||||
BubbleSort,
|
MergeSort,
|
||||||
reverseArr,
|
reverseArr,
|
||||||
REVERSE_SORTED_ARRAY_VISITING_COUNT,
|
REVERSE_SORTED_ARRAY_VISITING_COUNT,
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user