예제 #1
0
 @Test
 public void getBoundedRectangleTest() {
   Point point1 = new Point(5.0, 5.0);
   Point point2 = new Point(0.0, 0.0);
   Circle circle = new Circle(point1, 5.0);
   Rectangle bound = new Rectangle(point2, 10.0, 10.0);
   assertEquals(
       "failure - bounded rectangle does not match",
       true,
       bound.equals(circle.getBoundedRectangle()));
 }
  private static boolean testRectangle() {
    boolean pass = true;
    int test = 1;
    Rectangle rect;

    System.out.println("Rectangle tests...");

    rect = new Rectangle(4.3, 5.6, new Point(-99, 66), Color.cyan, false);
    pass &= test(approx(rect.getArea(), 4.3 * 5.6, 0.000001), test++);
    pass &= test(rect.getColor().equals(Color.cyan), test++);

    rect.setColor(Color.black);
    pass &= test(rect.getColor().equals(Color.black), test++);
    pass &= test(!rect.getFilled(), test++);

    rect.setFilled(true);
    pass &= test(rect.getFilled(), test++);
    pass &= test(rect.getWidth() == 4.3, test++);
    pass &= test(rect.getHeight() == 5.6, test++);

    rect.setWidth(4.321);
    pass &= test(rect.getWidth() == 4.321, test++);

    rect.setHeight(89.21);
    pass &= test(rect.getHeight() == 89.21, test++);
    pass &= test(approx(rect.getArea(), 4.321 * 89.21, 0.000001), test++);
    pass &= test(rect.getPosition().equals(new Point(-99, 66)), test++);

    rect.move(new Point(-5, -7));
    pass &= test(rect.getPosition().equals(new Point(-104, 59)), test++);

    Rectangle rect2 = new Rectangle(4.321, 89.21, new Point(-104, 59), Color.black, true);
    pass &= test(rect.equals(rect2), test++);

    Rectangle rect3 = new Rectangle(4.3219, 89.21, new Point(-104, 59), Color.black, false);
    pass &= test(!rect2.equals(rect3), test++);

    rect3 = new Rectangle(4.321, 89.219, new Point(-104, 59), Color.black, false);
    pass &= test(!rect2.equals(rect3), test++);

    rect3 = new Rectangle(4.321, 89.21, new Point(-104, 59), Color.red, false);
    pass &= test(!rect2.equals(rect3), test++);

    rect3 = new Rectangle(4.321, 89.21, new Point(104, 59), Color.black, false);
    pass &= test(!rect2.equals(rect3), test++);

    pass &= test(!rect2.equals(null), test++);
    pass &= test(!rect2.equals(new String("Whatever")), test++);

    return pass;
  }