MCPcopy Create free account
hub / github.com/MolinDeng/Princeton-algs4 / main

Method main

LabEnv/03Lab/Point.java:120–142  ·  view source on GitHub ↗

Unit tests the Point data type.

(String[] args)

Source from the content-addressed store, hash-verified

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}

Callers

nothing calls this directly

Calls 3

compareToMethod · 0.95
slopeToMethod · 0.95
slopeOrderMethod · 0.45

Tested by

no test coverage detected