Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

private static void testCoordAlphaToNum() {// checks for different string value

ID: 3735414 • Letter: P

Question

private static void testCoordAlphaToNum() {// checks for different string value in the method CoordAlphaToNum
int numTests = 6;
int passed = numTests;
int res;
if((res = Battleship.coordAlphaToNum("BAAA")) != 17576) {
System.out.println("FAILED: Battleship.coordAlphaToNum("BAAA") != 17576, but " + res);
passed--;
}
if((res = Battleship.coordAlphaToNum("ZERTY")) != 11506714) {
System.out.println("FAILED: Battleship.coordAlphaToNum("ZERTY") != 11506714, but " + res);
passed--;
}
if((res = Battleship.coordAlphaToNum("zerty")) != 11506714) {
System.out.println("FAILED: Battleship.coordAlphaToNum("zerty") != 11506714, but " + res);
passed--;
}
if((res = Battleship.coordAlphaToNum("&é"")) != -14747) {
System.out.println("FAILED: Battleship.coordAlphaToNum("&é") != -14747, but " + res);
passed--;
}
if((res = Battleship.coordAlphaToNum("baaa")) != 17576) {
   System.out.println("FAILED: Battleship.coordAlphaToNum("baaa") != 17576, but " + res);
       passed--;
}
if((res = Battleship.coordAlphaToNum("b")) != 1)
{
       System.out.println("FAILED: Battleship.coordAlphaToNum("b") != 1, but " + res);
       passed--;
}
System.out.println("testCoordAlphatoNum: Passed " + passed + " of " + numTests + " tests.");
}


  

private static void testCheckWater() {
//FIXME
}
  
private static void testPlaceShip() {
//FIXME
}
  
private static void testTakeShot() {
//FIXME
}
  
private static void testCheckLost() {
//FIXME
}

}

Using the testCoordAlphaToNum method as template, Can you please help me write test methods with at least 2

tests in your test bench to test the checkWater and placeShip methods. I am very confused at the moment!!!!!!

Explanation / Answer

I have wriiten the test for checkWater and placeShip methods. Do Let me know if you have nay doubts about it.

private static void testCheckWater() {
        int numTests = 3;
        int passed = numTests;
        int res;

        if((res = Battleship.checkWater(boardDim, 5, 8, 2, true)) != 1) {
            System.out.println("FAILED: Battleship.checkWater( boardDim, 2, 4, 2, true)) != 1, but " + res);
            passed--;
        }
        if((res = Battleship.checkWater(boardDim, 2, 4, 2, false)) != 1) {
            System.out.println("FAILED: Battleship.checkWater( boardDim, 2, 4, 2, false)) != 1, but " + res);
            passed--;
        }
        if((res = Battleship.checkWater( boardDim, 2, 4, 5, false)) != -2) {
            System.out.println(" Battleship.checkWater( boardDim, 2, 4, 5, false)) != -2, but " + res);
            passed--;
}
System.out.println("testCheckWater: Passed " + passed + " of " + numTests + " tests.");
}

private static void testPlaceShip() {
        int numTests = 3;
        int passed = numTests;
        boolean res;

        if((res = Battleship.placeShip( boardDim, 2, 4, 2, true, 1)) != true) {
            System.out.println("FAILED: Battleship.placeShip( boardDim, 2, 4, 2, true)) != 1, but " + res);
            passed--;
        }
        if((res = Battleship.placeShip( boardDim, 2, 4, 2, false, 2)) != true) {
            System.out.println("FAILED: Battleship.placeShip( boardDim, 2, 4, 2, false)) != 1, but " + res);
            passed--;
        }
        if((res = Battleship.placeShip( boardDim, 4, 4, 5, false, 3)) != false) {
            System.out.println("FAILED: Battleship.placeShip( boardDim, 2, 4, 5, false)) != -2, but " + res);
            passed--;
        }
      
      
        System.out.println("testPlaceShip: Passed " + passed + " of " + numTests + " tests.");
      
        Battleship.printBoard(boardDim, "My Ship");
    }