forked from jbloch/effective-java-3e-source-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounterPointTest.java
More file actions
27 lines (21 loc) · 862 Bytes
/
Copy pathCounterPointTest.java
File metadata and controls
27 lines (21 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package effectivejava.chapter3.item10.inheritance;
import effectivejava.chapter3.item10.Point;
import java.util.*;
// Test program that uses CounterPoint as Point
public class CounterPointTest {
// Initialize unitCircle to contain all Points on the unit circle (Page 43)
private static final Set<Point> unitCircle = Set.of(
new Point( 1, 0), new Point( 0, 1),
new Point(-1, 0), new Point( 0, -1));
public static boolean onUnitCircle(Point p) {
return unitCircle.contains(p);
}
public static void main(String[] args) {
Point p1 = new Point(1, 0);
Point p2 = new CounterPoint(1, 0);
// Prints true
System.out.println(onUnitCircle(p1));
// Should print true, but doesn't if Point uses getClass-based equals
System.out.println(onUnitCircle(p2));
}
}