File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments