|
1 |
| -import { canMeasureWater } from '../WaterJugProblem' |
| 1 | +// WaterJugProblem.test.js |
| 2 | +import { canMeasureWater } from '../WaterJugProblem'; // Adjust the path as necessary |
2 | 3 |
|
3 | 4 | describe('Water Jug Problem', () => {
|
4 |
| - |
5 |
| - // Test case 1: Valid input where water can be measured |
6 |
| - it('should return true for values x=3, y=5, z=4', () => { |
7 |
| - expect(canMeasureWater(3, 5, 4)).toBe(true) |
8 |
| - }) |
| 5 | + it('should return true for values jug1=3, jug2=5, target=4', () => { |
| 6 | + expect(canMeasureWater(3, 5, 4)).toBe(true); |
| 7 | + }); |
9 | 8 |
|
10 |
| - // Test case 2: Valid input where water cannot be measured |
11 |
| - it('should return false for values x=2, y=6, z=5', () => { |
12 |
| - expect(canMeasureWater(2, 6, 5)).toBe(false) |
13 |
| - }) |
| 9 | + it('should return false for values jug1=2, jug2=6, target=5', () => { |
| 10 | + expect(canMeasureWater(2, 6, 5)).toBe(false); |
| 11 | + }); |
14 | 12 |
|
15 |
| - // Test case 3: Measure exact amount of water in one jug |
16 |
| - it('should return true for values x=5, y=3, z=5', () => { |
17 |
| - expect(canMeasureWater(5, 3, 5)).toBe(true) |
18 |
| - }) |
| 13 | + it('should return true for values jug1=5, jug2=3, target=5', () => { |
| 14 | + expect(canMeasureWater(5, 3, 5)).toBe(true); |
| 15 | + }); |
19 | 16 |
|
20 |
| - // Test case 4: Invalid inputs (negative or non-integer) |
21 |
| - it('Throw Error for Invalid Input', () => { |
22 |
| - expect(() => canMeasureWater(-3, 5, 4)).toThrow( |
23 |
| - 'Input should be non-negative whole numbers' |
24 |
| - ) |
25 |
| - expect(() => canMeasureWater(3, null, 4)).toThrow( |
26 |
| - 'Input should be non-negative whole numbers' |
27 |
| - ) |
28 |
| - expect(() => canMeasureWater(3, 5, 2.5)).toThrow( |
29 |
| - 'Input should be non-negative whole numbers' |
30 |
| - ) |
31 |
| - expect(() => canMeasureWater('a', 5, 4)).toThrow( |
32 |
| - 'Input should be non-negative whole numbers' |
33 |
| - ) |
34 |
| - }) |
| 17 | + it('should return true for values jug1=3, jug2=5, target=0', () => { |
| 18 | + expect(canMeasureWater(3, 5, 0)).toBe(true); |
| 19 | + }); |
35 | 20 |
|
36 |
| - // Test case 5: Edge case where z is 0 |
37 |
| - it('should return true for values x=3, y=5, z=0', () => { |
38 |
| - expect(canMeasureWater(3, 5, 0)).toBe(true) |
39 |
| - }) |
| 21 | + it('should return true for values jug1=3, jug2=5, target=8', () => { |
| 22 | + expect(canMeasureWater(3, 5, 8)).toBe(true); |
| 23 | + }); |
40 | 24 |
|
41 |
| - // Test case 6: Edge case where z equals the sum of both jugs |
42 |
| - it('should return true for values x=3, y=5, z=8', () => { |
43 |
| - expect(canMeasureWater(3, 5, 8)).toBe(true) |
44 |
| - }) |
45 |
| - |
46 |
| -}) |
| 25 | + it('should throw an error for invalid input', () => { |
| 26 | + expect(() => canMeasureWater(-1, 5, 3)).toThrow('Invalid input: capacities must be non-negative.'); |
| 27 | + expect(() => canMeasureWater(3, -2, 1)).toThrow('Invalid input: capacities must be non-negative.'); |
| 28 | + expect(() => canMeasureWater(3, 5, -1)).toThrow('Invalid input: target amount must be non-negative.'); |
| 29 | + }); |
| 30 | +}); |
0 commit comments