1 import compare from './compare';
3 describe('compare()', () => {
4 it('returns 1 if a is greater than b', () => {
5 const result = compare(2, 1);
7 expect(result).toBe(1);
10 it('returns -1 if a is greater than b', () => {
11 const result = compare(1, 2);
13 expect(result).toBe(-1);
16 it('returns 0 if a is equal to b', () => {
17 const result = compare(1, 1);
19 expect(result).toBe(0);
22 it('acts as a numeric comparator between two values, consistent with the array.prototype.sort api', () => {
23 const input = [3, 8, 9, 1, 4, 6, 7, 5, 2];
25 const output = input.sort(compare);
27 const expected = [1, 2, 3, 4, 5, 6, 7, 8, 9];
29 expect(output).toEqual(expected);