|
| 1 | +import { litresToGallons, gallonsToLitres } from '../VolumeConversion.js' |
| 2 | + |
| 3 | +describe('litresToGallons', () => { |
| 4 | + test('litresToGallons(0) returns 0', () => { |
| 5 | + expect(litresToGallons(0)).toBe(0) |
| 6 | + }) |
| 7 | + |
| 8 | + test('litresToGallons(1) returns 0.264172', () => { |
| 9 | + expect(litresToGallons(1)).toBeCloseTo(0.264172) |
| 10 | + }) |
| 11 | + |
| 12 | + test('litresToGallons(10) returns 2.64172', () => { |
| 13 | + expect(litresToGallons(10)).toBeCloseTo(2.64172) |
| 14 | + }) |
| 15 | + |
| 16 | + test('litresToGallons(100) returns 26.4172', () => { |
| 17 | + expect(litresToGallons(100)).toBeCloseTo(26.4172) |
| 18 | + }) |
| 19 | + |
| 20 | + test('throws TypeError for non-number input', () => { |
| 21 | + expect(() => litresToGallons('10')).toThrow(TypeError) |
| 22 | + }) |
| 23 | + |
| 24 | + test('throws TypeError for NaN', () => { |
| 25 | + expect(() => litresToGallons(NaN)).toThrow(TypeError) |
| 26 | + }) |
| 27 | +}) |
| 28 | + |
| 29 | +describe('gallonsToLitres', () => { |
| 30 | + test('gallonsToLitres(0) returns 0', () => { |
| 31 | + expect(gallonsToLitres(0)).toBe(0) |
| 32 | + }) |
| 33 | + |
| 34 | + test('gallonsToLitres(1) returns 3.78541', () => { |
| 35 | + expect(gallonsToLitres(1)).toBeCloseTo(3.78541) |
| 36 | + }) |
| 37 | + |
| 38 | + test('gallonsToLitres(10) returns 37.8541', () => { |
| 39 | + expect(gallonsToLitres(10)).toBeCloseTo(37.8541) |
| 40 | + }) |
| 41 | + |
| 42 | + test('gallonsToLitres(5) returns 18.92705', () => { |
| 43 | + expect(gallonsToLitres(5)).toBeCloseTo(18.92705) |
| 44 | + }) |
| 45 | + |
| 46 | + test('throws TypeError for non-number input', () => { |
| 47 | + expect(() => gallonsToLitres('10')).toThrow(TypeError) |
| 48 | + }) |
| 49 | + |
| 50 | + test('throws TypeError for NaN', () => { |
| 51 | + expect(() => gallonsToLitres(NaN)).toThrow(TypeError) |
| 52 | + }) |
| 53 | +}) |
0 commit comments