|
| 1 | +import QuickSort from '../QuickSort'; |
| 2 | +import { |
| 3 | + equalArr, |
| 4 | + notSortedArr, |
| 5 | + reverseArr, |
| 6 | + sortedArr, |
| 7 | + SortTester, |
| 8 | +} from '../../SortTester'; |
| 9 | + |
| 10 | +// Complexity constants. |
| 11 | +const SORTED_ARRAY_VISITING_COUNT = 190; |
| 12 | +const NOT_SORTED_ARRAY_VISITING_COUNT = 62; |
| 13 | +const REVERSE_SORTED_ARRAY_VISITING_COUNT = 190; |
| 14 | +const EQUAL_ARRAY_VISITING_COUNT = 19; |
| 15 | + |
| 16 | +describe('QuickSort', () => { |
| 17 | + it('should sort array', () => { |
| 18 | + SortTester.testSort(QuickSort); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should sort array with custom comparator', () => { |
| 22 | + SortTester.testSortWithCustomComparator(QuickSort); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should do stable sorting', () => { |
| 26 | + SortTester.testSortStability(QuickSort); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should visit EQUAL array element specified number of times', () => { |
| 30 | + SortTester.testAlgorithmTimeComplexity( |
| 31 | + QuickSort, |
| 32 | + equalArr, |
| 33 | + EQUAL_ARRAY_VISITING_COUNT, |
| 34 | + ); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should visit SORTED array element specified number of times', () => { |
| 38 | + SortTester.testAlgorithmTimeComplexity( |
| 39 | + QuickSort, |
| 40 | + sortedArr, |
| 41 | + SORTED_ARRAY_VISITING_COUNT, |
| 42 | + ); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should visit NOT SORTED array element specified number of times', () => { |
| 46 | + SortTester.testAlgorithmTimeComplexity( |
| 47 | + QuickSort, |
| 48 | + notSortedArr, |
| 49 | + NOT_SORTED_ARRAY_VISITING_COUNT, |
| 50 | + ); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should visit REVERSE SORTED array element specified number of times', () => { |
| 54 | + SortTester.testAlgorithmTimeComplexity( |
| 55 | + QuickSort, |
| 56 | + reverseArr, |
| 57 | + REVERSE_SORTED_ARRAY_VISITING_COUNT, |
| 58 | + ); |
| 59 | + }); |
| 60 | +}); |
0 commit comments