|
| 1 | +const { range } = require('../lib/range'); |
| 2 | + |
| 3 | +describe('range', () => { |
| 4 | + it('should return either 0 or a positive number', () => { |
| 5 | + const result = range(-296.028, 296.028, 42, +'-42'); |
| 6 | + expect(result >= 0).toBe(true); |
| 7 | + }); |
| 8 | + |
| 9 | + it('should return the difference between the largest and smallest values', () => { |
| 10 | + const result = range(1.6, -2.3325, 596960, 3938475.31589, +'-395757.326518'); |
| 11 | + expect(result).toEqual(4334232.642408); |
| 12 | + }); |
| 13 | + |
| 14 | + it('should return 0 when all there numbers are identical', () => { |
| 15 | + const result = range(296.028, 296.028, 296.028, 296.028); |
| 16 | + expect(result).toEqual(0); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should return 0 when only one number is provided', () => { |
| 20 | + const result = range(296.028); |
| 21 | + expect(result).toEqual(0); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should throw an error when no parameters are provided', () => { |
| 25 | + expect(range).toThrow(); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should throw an error when at least one parameter does not evaluate to a number', () => { |
| 29 | + expect(() => range(42, 'foo', 'bar')).toThrow(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should throw an error when at least one parameter evaluates to a number larger than Number.MAX_SAFE_INTEGER', () => { |
| 33 | + expect(() => range(Number.MAX_SAFE_INTEGER + 1)).toThrow(); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should throw an error when at least one parameter evaluates to a number smaller than Number.MIN_SAFE_INTEGER', () => { |
| 37 | + expect(() => range(Number.MIN_SAFE_INTEGER - 1)).toThrow(); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should throw an error when result is number larger than Number.MAX_SAFE_INTEGER', () => { |
| 41 | + expect(() => range(1.6, -2.3325, 9007199254740990, 596960, -3938475)).toThrow(); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should throw an error when result is number smaller than Number.MIN_SAFE_INTEGER', () => { |
| 45 | + expect(() => range(1.6, -2.3325, -9007199254740990, 596960, 3938475)).toThrow(); |
| 46 | + }); |
| 47 | +}); |
0 commit comments