|
| 1 | +import { alphaNumericalSort } from '../AlphaNumericalSort' |
| 2 | + |
| 3 | +describe('alphaNumericalComparer', () => { |
| 4 | + test('given array of eng symbols return correct sorted array', () => { |
| 5 | + const src = ['b', 'a', 'c'] |
| 6 | + src.sort(alphaNumericalSort) |
| 7 | + expect(src).toEqual(['a', 'b', 'c']) |
| 8 | + }) |
| 9 | + |
| 10 | + test('given array of numbers return correct sorted array', () => { |
| 11 | + const src = ['15', '0', '5'] |
| 12 | + src.sort(alphaNumericalSort) |
| 13 | + expect(src).toEqual(['0', '5', '15']) |
| 14 | + }) |
| 15 | + |
| 16 | + test('correct sort with numbers and strings', () => { |
| 17 | + const src = ['3', 'a1b15c', 'z', 'a1b14c'] |
| 18 | + src.sort(alphaNumericalSort) |
| 19 | + expect(src).toEqual(['3', 'a1b14c', 'a1b15c', 'z']) |
| 20 | + }) |
| 21 | + |
| 22 | + test('correct sort with long numbers', () => { |
| 23 | + const src = ['abc999999999999999999999999999999999cba', 'abc999999999999999999999999999999990cba', 'ab'] |
| 24 | + src.sort(alphaNumericalSort) |
| 25 | + expect(src).toEqual(['ab', 'abc999999999999999999999999999999990cba', 'abc999999999999999999999999999999999cba']) |
| 26 | + }) |
| 27 | + |
| 28 | + test('correct sort with z prefix', () => { |
| 29 | + const src = ['z', 'abc003def', 'abc1def', 'a'] |
| 30 | + src.sort(alphaNumericalSort) |
| 31 | + expect(src).toEqual(['a', 'abc1def', 'abc003def', 'z']) |
| 32 | + }) |
| 33 | + |
| 34 | + test('correct sort with other language', () => { |
| 35 | + const src = ['а10б', 'а2б', 'в10г', 'в05г'] |
| 36 | + src.sort(alphaNumericalSort) |
| 37 | + expect(src).toEqual(['а2б', 'а10б', 'в05г', 'в10г']) |
| 38 | + }) |
| 39 | +}) |
0 commit comments