package ca.mokhan.test; import Q9.*; import java.io.*; import java.text.*; import java.util.*; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; public class RobotTest extends TestCase { private Robot subject; public RobotTest(String testName) { super(testName); this.subject = new Robot(0, 0); } public static Test suite() { return new TestSuite(RobotTest.class); } public void test_printGrid() { Robot r1 = new Robot(0, 0); Robot r2 = new Robot(9, 9); String sp = Robot.SPACE; String sr1 = Robot.R1; String sr2 = Robot.R2; String rn = System.lineSeparator(); String expected = String.format("|%3$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn, sr1) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%3$s|%2$s", sp, rn, sr2); String result = Robot.printGrid(r1, r2); System.out.println(expected); System.out.println(result); assertEquals(expected, result); } public void test_printGrid_withCollision() { Robot r1 = new Robot(5, 5); Robot r2 = new Robot(5, 5); String sp = Robot.SPACE; String x = Robot.COLLISION; String rn = System.lineSeparator(); String expected = String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%3$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn, x) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn) + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn); String result = Robot.printGrid(r1, r2); System.out.println(expected); System.out.println(result); assertEquals(expected, result); } }