4100d54313306d43fcc19c79cb788ebbbfa840763d4106c344c3f363781e64f95cfa491a09840792b47febf3ccae45ef14dfa27c847f0419eb40dd1e866679 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import mergeSort from 'handsontable/utils/sortingAlgorithms/mergeSort';
  2. /**
  3. * Refactored implementation of megeSort tests by Github user mgechev
  4. * (part of javascript-algorithms project - all project contributors at repository website)
  5. *
  6. * Link to repository: https://github.com/mgechev/javascript-algorithms
  7. */
  8. describe('mergeSort', () => {
  9. it('should work with sorted arrays', () => {
  10. expect(mergeSort([1, 2, 3, 4])).toEqual([1, 2, 3, 4]);
  11. });
  12. it('should work with empty array', () => {
  13. expect(mergeSort([])).toEqual([]);
  14. });
  15. it('should sort properly the array containg strings', () => {
  16. expect(mergeSort(['z', 'c', '', '1', 'a'])).toEqual(['', '1', 'a', 'c', 'z']);
  17. });
  18. it('should sort lexically the array containg numbers (by default)', () => {
  19. expect(mergeSort([3, 40, 100, 2000])).toEqual([100, 2000, 3, 40]);
  20. });
  21. it('should not change the order when such comparator is provided', () => {
  22. var compareFunction = function() {
  23. return 0;
  24. };
  25. expect(mergeSort([1, 2, 11, 3], compareFunction)).toEqual([1, 2, 11, 3]);
  26. });
  27. it('should sort the numbers in ascending order when such comparator is provided', () => {
  28. var compareFunction = function(a, b) {
  29. return a - b;
  30. };
  31. expect(mergeSort([1, 2, 11, 3], compareFunction)).toEqual([1, 2, 3, 11]);
  32. });
  33. it('should sort the numbers in descending order when such comparator is provided', () => {
  34. var compareFunction = function(a, b) {
  35. return b - a;
  36. };
  37. expect(mergeSort([1, 2, 11, 3], compareFunction)).toEqual([11, 3, 2, 1]);
  38. });
  39. });