|
| 1 | +const { isPositiveInteger } = require('../lib/isPositiveInteger'); |
| 2 | + |
| 3 | +const MAX_SAFE_INTEGER = 9007199254740991; |
| 4 | +describe('IsPositiveInteger', () => { |
| 5 | + it('should return true for positive integers', () => { |
| 6 | + expect(isPositiveInteger(2, 4, 200)).toBe(true); |
| 7 | + expect(isPositiveInteger(MAX_SAFE_INTEGER, 4, 200)).toBe(true); |
| 8 | + expect(isPositiveInteger(34, 98, 225, 56)).toBe(true); |
| 9 | + }); |
| 10 | + |
| 11 | + it('should return false for negative numbers or 0', () => { |
| 12 | + expect(isPositiveInteger(0, 4, 200)).toBe(false); |
| 13 | + expect(isPositiveInteger(-3, -4, -200)).toBe(false); |
| 14 | + expect(isPositiveInteger(34, -98, 225, 56)).toBe(false); |
| 15 | + }); |
| 16 | + |
| 17 | + it('should return false for floats', () => { |
| 18 | + expect(isPositiveInteger(2.6, 4.9, 23.67)).toBe(false); |
| 19 | + expect(isPositiveInteger(2, 4, 23.67)).toBe(false); |
| 20 | + expect(isPositiveInteger(-10.2, -4.6, -200.4)).toBe(false); |
| 21 | + expect(isPositiveInteger(-32.7, 98, 225, 56)).toBe(false); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should return false for other values', () => { |
| 25 | + expect(isPositiveInteger({})).toBe(false); |
| 26 | + expect(isPositiveInteger(2, [])).toBe(false); |
| 27 | + expect(isPositiveInteger(1, 'S')).toBe(false); |
| 28 | + expect(isPositiveInteger(MAX_SAFE_INTEGER + 1)).toBe(false); |
| 29 | + }); |
| 30 | +}); |
0 commit comments