|
| 1 | +/* The purpose of the test here is to detect whether the correct result is generated |
| 2 | + under the legal input, not to test its robustness, because this is not considered |
| 3 | + in the implementation process of the algorithm. |
| 4 | +*/ |
| 5 | + |
| 6 | +/* eslint-disable no-undef */ |
| 7 | + |
| 8 | +import rexSort from './MSDRadixSort'; |
| 9 | + |
| 10 | +// Simple stub for the chunker |
| 11 | +const chunker = { |
| 12 | + add: () => {}, |
| 13 | +}; |
| 14 | + |
| 15 | +describe('rexsort', () => { |
| 16 | + it('sorts empty array', () => { |
| 17 | + expect(rexSort.run(chunker, { nodes: [] })).toEqual([]); |
| 18 | + }); |
| 19 | + it('sorts single element', () => { |
| 20 | + expect(rexSort.run(chunker, { nodes: [4] })).toEqual([4]); |
| 21 | + }); |
| 22 | + it('sorts two values', () => { |
| 23 | + expect(rexSort.run(chunker, { nodes: [1, 2] })).toEqual([1, 2]); |
| 24 | + }); |
| 25 | + it('sorts two values in reverse', () => { |
| 26 | + expect(rexSort.run(chunker, { nodes: [2, 1] })).toEqual([1, 2]); |
| 27 | + }); |
| 28 | + it('sorts odd list', () => { |
| 29 | + expect(rexSort.run(chunker, { nodes: [1, 4, 3] })).toEqual([1, 3, 4]); |
| 30 | + }); |
| 31 | + it('sorts even list', () => { |
| 32 | + expect(rexSort.run(chunker, { nodes: [1, 4, 3, 2] })).toEqual([1, 2, 3, 4]); |
| 33 | + }); |
| 34 | + it('sorts ordered elements', () => { |
| 35 | + expect(rexSort.run(chunker, { nodes: [1, 2, 3, 4, 5] })).toEqual([1, 2, 3, 4, 5]); |
| 36 | + }); |
| 37 | + it('sorts reversed elements', () => { |
| 38 | + expect(rexSort.run(chunker, { nodes: [5, 4, 3, 2, 1] })).toEqual([1, 2, 3, 4, 5]); |
| 39 | + }); |
| 40 | + it('sorts list with duplicates', () => { |
| 41 | + expect(rexSort.run(chunker, { nodes: [1, 3, 2, 5, 3, 2] })).toEqual([1, 2, 2, 3, 3, 5]); |
| 42 | + }); |
| 43 | +}); |
0 commit comments