|
| 1 | +import { parityOutlier } from '../ParityOutlier' |
| 2 | + |
| 3 | +describe('Testing parityOutlier function', () => { |
| 4 | + it('should return the odd number in an array of even numbers', () => { |
| 5 | + expect(parityOutlier([1, 2, 16, -8848, 5126])).toBe(1) |
| 6 | + }) |
| 7 | + |
| 8 | + it('should return the even number in an array of odd numbers', () => { |
| 9 | + expect(parityOutlier([177, 5, 76, 1919])).toBe(76) |
| 10 | + }) |
| 11 | + |
| 12 | + it('should, if the given array has only one integer element, return the integer itself', () => { |
| 13 | + expect(parityOutlier([83])).toBe(83) |
| 14 | + expect(parityOutlier([54])).toBe(54) |
| 15 | + }) |
| 16 | + |
| 17 | + it('should, if the given array has only an odd and an even number, return the odd outlier', () => { |
| 18 | + expect(parityOutlier([1, 2])).toBe(1) |
| 19 | + expect(parityOutlier([4, 3])).toBe(3) |
| 20 | + }) |
| 21 | + |
| 22 | + it('should return null if the given array is empty, contains only one integer, contains non-interger elements or does not have a parity outlier', () => { |
| 23 | + expect(parityOutlier([])).toBe(null) |
| 24 | + expect(parityOutlier([2])).toBe(null) |
| 25 | + expect(parityOutlier([2, {}, 5, 'GitHub'])).toBe(null) |
| 26 | + expect(parityOutlier([1, 3, 5, 7, 9])).toBe(null) |
| 27 | + expect(parityOutlier([0, 2, 4, 6, 8])).toBe(null) |
| 28 | + expect(parityOutlier([1, 3, 5, 7, 2, 4, 6, 8])).toBe(null) |
| 29 | + }) |
| 30 | +}) |
0 commit comments