Question: i implemeted the code that was suppodely fixed and so i ran it with the test cases and im still getting the same failures import

i implemeted the code that was suppodely fixed and so i ran it with the test cases and im still getting the same failures
import java.util.HashSet; public class Task2{// DO NOT change this field private HashSet strings; // DO NOT change this method public void setStrings(HashSet stringSet){ strings = stringSet; }// DO NOT change the signature for this method // This method does not need to be recursive public boolean stringSum(){ for (String string : strings){ if (isConstructable(string, string)){ return true; }} return false; }// This method MUST be recursive // You can change the name and parameters of this method private boolean isConstructable(String aim, String initial){ return isConstructableHelper(aim, new HashSet(), initial); } private boolean isConstructableHelper(String aim, HashSet visited, String initial){ if (aim.isEmpty()){ return true; } if (visited.contains(aim)){ return false; } visited.add(aim); for (String string : strings){ if (!string.equals(initial) && aim.startsWith(string)){ String remaining = aim.substring(string.length()); if (isConstructableHelper(remaining, visited, initial)){ return true; }}} visited.remove(aim); // Backtrack return false; }} public class Task3{// DO NOT change this field private int[][] map; // DO NOT change this method public void setMap(int[][] grid){ map = grid; }// DO NOT change the signature for this method // This method does not need to be recursive public int dig(int battery){ int maxGold =0; for (int col =0; col < map[0].length; col++){ maxGold = Math.max(maxGold, maximumGoldFrom(0, col, battery, new boolean[map.length][map[0].length])); } return maxGold; } private int maximumGoldFrom(int y, int x, int battery, boolean[][] visited){ if (battery <=0|| y <0|| y >= map.length || x <0|| x >= map[0].length || visited[y][x]){ return 0; } visited[y][x]= true; // Mark cell as visited int gold = map[y][x]; // Get gold at current cell int maxGold =0; // Explore all directions (Left, Right, Down, Up) maxGold = Math.max(maxGold, gold + maximumGoldFrom(y, x -1, battery -1, visited)); // Left maxGold = Math.max(maxGold, gold + maximumGoldFrom(y, x +1, battery -1, visited)); // Right maxGold = Math.max(maxGold, gold + maximumGoldFrom(y +1, x, battery -1, visited)); // Down maxGold = Math.max(maxGold, gold + maximumGoldFrom(y -1, x, battery -1, visited)); // Up visited[y][x]= false; // Backtrack return maxGold; }}
@Test
public void StringSumHelper3(){
Task2t2=new Task2();
HashSet strings =new HashSet<>();
strings.add("");
strings.add("SEAN");
t2.setStrings(strings);
boolean output =t2.stringSum();
assertEquals(false,output);
}
@Test
public void DigTest1(){
Task3t3=new Task3();
int[][]map =new int[][]{
new int[]{0,1,1,0,0},
new int[]{2,0,0,0,0},
new int[]{0,0,3,1,0},
new int[]{1,0,0,1,0},
new int[]{0,1,0,0,5}
};
t3.setMap(map);
assertEquals(13,t3.dig(6));
}
@Test
public void DigTest2(){
Task3t3=new Task3();
int[][]map ={
new int[]{2,3,1},
new int[]{0,0,0},
new int[]{5,4,3}
};
t3.setMap(map);
assertEquals(9,t3.dig(3));
}
public void DigTest3(){
Task3t3=new Task3();
int[][]map ={
new int[]{1,3,1,4},
new int[]{0,2,5,0},
new int[]{1,0,2,3}
};
t3.setMap(map);
assertEquals(21,t3.dig(5));
}
@Test
public void DigTest5(){
Task3t3=new Task3();
int[][]map ={
new int[]{1,2,3},
new int[]{4,5,6},
new int[]{7,8,9}
};
t3.setMap(map);
assertEquals(45,t3.dig(6));
}
all these are failing DigTest1()org.opentest4j.AssertionFailedError: Expected :13Actual :7DigTest2()org.opentest4j.AssertionFailedError: Expected :9Actual :7DigTest3()org.opentest4j.AssertionFailedError: Expected :21Actual :15DigTest5()org.opentest4j.AssertionFailedError: Expected :45Actual :37StringSumHelper3()org.opentest4j.AssertionFailedError: Expected :false Actual :true

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!