|
| 1 | +const { isComposit } = require('../lib/isComposit'); |
| 2 | + |
| 3 | +describe('IsComposit', () => { |
| 4 | + it('should return true when all parameters evaluate to composit numbers', () => { |
| 5 | + const result = isComposit(4, 6, 20 / 2, +'8'); |
| 6 | + expect(result).toBe(true); |
| 7 | + }); |
| 8 | + |
| 9 | + it('should return false when at least one parameter does not evaluate to a composit number', () => { |
| 10 | + const result = isComposit(2, 8, 10, 28); |
| 11 | + expect(result).toBe(false); |
| 12 | + }); |
| 13 | + |
| 14 | + it('should return false when at least one parameter does not evaluate to an integer', () => { |
| 15 | + const result = isComposit(2.5, 8, 10, 20); |
| 16 | + expect(result).toBe(false); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should return false when at least one parameter evaluates to a number less than 2', () => { |
| 20 | + const result = isComposit(-2, 8, 10, 20); |
| 21 | + expect(result).toBe(false); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should return false when the least factor of a number is not composit', () => { |
| 25 | + const result = isComposit(15485863); |
| 26 | + expect(result).toBe(false); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should throw an error when no parameters are provided', () => { |
| 30 | + expect(isComposit).toThrow(); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should throw an error when at least one parameter does not evaluate to a number', () => { |
| 34 | + expect(() => isComposit('yo')).toThrow(); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should throw an error when at least one parameter evaluates to a number larger than Number.MAX_SAFE_INTEGER', () => { |
| 38 | + expect(() => isComposit(9949370777987917)).toThrow(); |
| 39 | + }); |
| 40 | +}); |
0 commit comments