master
1package ca.mokhan.test;
2
3import Q9.*;
4import java.io.*;
5import java.text.*;
6import java.util.*;
7import junit.framework.Test;
8import junit.framework.TestCase;
9import junit.framework.TestSuite;
10
11public class RobotTest extends TestCase {
12 private Robot subject;
13
14 public RobotTest(String testName) {
15 super(testName);
16 this.subject = new Robot(0, 0);
17 }
18
19 public static Test suite() {
20 return new TestSuite(RobotTest.class);
21 }
22
23 public void test_printGrid() {
24 Robot r1 = new Robot(0, 0);
25 Robot r2 = new Robot(9, 9);
26 String sp = Robot.SPACE;
27 String sr1 = Robot.R1;
28 String sr2 = Robot.R2;
29 String rn = System.lineSeparator();
30
31 String expected =
32 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)
33 + 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)
34 + 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)
35 + 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)
36 + 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)
37 + 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)
38 + 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)
39 + 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)
40 + 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)
41 + 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);
42 String result = Robot.printGrid(r1, r2);
43
44 // System.out.println(expected);
45 // System.out.println(result);
46
47 assertEquals(expected, result);
48 }
49
50 public void test_printGrid_withCollision() {
51 Robot r1 = new Robot(5, 5);
52 Robot r2 = new Robot(5, 5);
53 String sp = Robot.SPACE;
54 String x = Robot.COLLISION;
55 String rn = System.lineSeparator();
56
57 String expected =
58 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)
59 + 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)
60 + 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)
61 + 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)
62 + 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)
63 + 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)
64 + 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)
65 + 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)
66 + 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)
67 + 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);
68 String result = Robot.printGrid(r1, r2);
69
70 // System.out.println(expected);
71 // System.out.println(result);
72
73 assertEquals(expected, result);
74 }
75}