Point implements Serializable { public static Point divide(Point p, double d) { return new Point(p.x / d, p.y / d); } Point(double pX, double pY); static double distance(Point p1, Point p2); static Point add(Point p1, Point p2); static Point diff(Point p1, Point p2); static Point multiply(Point p, double d); static Point divide(Point p, double d); static Point centroid(Iterable<Point> points); static Point parsePoint(String pointString); @Override int hashCode(); @Override boolean equals(@Nullable Object other); @Override String toString(); final double x; final double y; }
@Test public void testDivide() { final Point p1 = new Point(1, 2); final Point result = Point.divide(p1, 4); assertEquals(new Point(0.25, 0.5), result); }
@Test public void testDivideByZero() { final Point p1 = new Point(0, 2); final Point result = Point.divide(p1, 0); assertTrue(Double.isNaN(result.x)); assertTrue(Double.isInfinite(result.y)); }