Skip to content

Commit 50825fa

Browse files
authored
Create WaterJugProblem.test.js
test cases for water jug problem
1 parent ff16d60 commit 50825fa

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Diff for: Recursive/test/WaterJugProblem.test.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const canMeasureWater = require('../Recursive/WaterJugProblem');
2+
3+
describe('Water Jug Problem', () => {
4+
test('should return true when target amount is achievable', () => {
5+
expect(canMeasureWater(3, 5, 4)).toBe(true); // Known solution exists
6+
});
7+
8+
test('should return false when target amount is not achievable', () => {
9+
expect(canMeasureWater(2, 6, 5)).toBe(false); // Impossible to measure 5 using 2 and 6
10+
});
11+
12+
test('should return true when one of the jugs exactly matches the target', () => {
13+
expect(canMeasureWater(3, 5, 5)).toBe(true); // Exact match with jug 2
14+
});
15+
16+
test('should return true when both jugs are enough to make the target', () => {
17+
expect(canMeasureWater(4, 3, 7)).toBe(true); // Combined total equals target
18+
});
19+
20+
test('should return false when target amount exceeds both jug capacities combined', () => {
21+
expect(canMeasureWater(3, 5, 9)).toBe(false); // 9 exceeds the total capacity (3 + 5)
22+
});
23+
24+
test('should return true for zero target', () => {
25+
expect(canMeasureWater(3, 5, 0)).toBe(true); // It's always possible to measure 0
26+
});
27+
});

0 commit comments

Comments
 (0)