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