Commit 725e4ff

mo khan <mo@mokhan.ca>
2019-08-05 20:08:12
show collision in grid with X
1 parent 223504b
Changed files (2)
src/Q9/Robot.java
@@ -54,7 +54,8 @@ public class Robot {
         boolean r1InCell = r1.atPosition(row, column);
         boolean r2InCell = r2.atPosition(row, column);
 
-        if (r1InCell) grid += "|1";
+        if (r1InCell && r2InCell) grid += "|X";
+        else if (r1InCell) grid += "|1";
         else if (r2InCell) grid += "|2";
         else grid += "| ";
       }
src/Q9/RobotTest.java
@@ -42,4 +42,27 @@ public class RobotTest extends TestCase {
 
     assertEquals(expected, result);
   }
+
+  public void test_printGrid_withCollision() {
+    Robot r1 = new Robot(5, 5);
+    Robot r2 = new Robot(5, 5);
+
+    String expected =
+        "| | | | | | | | | | |\n"
+            + "| | | | | | | | | | |\n"
+            + "| | | | | | | | | | |\n"
+            + "| | | | | | | | | | |\n"
+            + "| | | | | | | | | | |\n"
+            + "| | | | | |X| | | | |\n"
+            + "| | | | | | | | | | |\n"
+            + "| | | | | | | | | | |\n"
+            + "| | | | | | | | | | |\n"
+            + "| | | | | | | | | | |\n";
+    String result = Robot.printGrid(r1, r2);
+
+    System.out.println(expected);
+    System.out.println(result);
+
+    assertEquals(expected, result);
+  }
 }