Unit tests the Point data type.
(String[] args)
| 118 | * Unit tests the Point data type. |
| 119 | */ |
| 120 | public static void main(String[] args) { |
| 121 | Point a = new Point(1, 1); |
| 122 | Point b = new Point(1, 1); |
| 123 | StdOut.println(a.compareTo(b)); |
| 124 | StdOut.println(a.slopeTo(b)); |
| 125 | int n = 5; |
| 126 | Point[] p = new Point[n]; |
| 127 | for (int i = 0; i < n; i++) { |
| 128 | p[i] = new Point(StdRandom.uniformInt(n), StdRandom.uniformInt(n)); |
| 129 | } |
| 130 | StdOut.println("before sort"); |
| 131 | for (int i = 0; i < n; i++) StdOut.print(p[i] + " "); |
| 132 | StdOut.println(); |
| 133 | |
| 134 | Arrays.sort(p); |
| 135 | StdOut.println("sort by coord"); |
| 136 | for (int i = 0; i < n; i++) StdOut.print(p[i] + " "); |
| 137 | StdOut.println(); |
| 138 | |
| 139 | Arrays.sort(p, p[0].slopeOrder()); // sort by slope relative to (0, 0) |
| 140 | StdOut.println("sort by slope"); |
| 141 | for (int i = 0; i < n; i++) StdOut.print(p[i] + " "); |
| 142 | } |
| 143 | } |
nothing calls this directly
no test coverage detected