Ejemplo n.º 1
0
  private static boolean testConvexPolygonArch() {
    boolean pass = true;
    int test = 1;
    int cnt;
    ConvexPolygon poly;
    Class cl;
    Class[] temp;

    System.out.println("ConvexPolygon architecture tests...");

    Point a = new Point(7, 7);
    Point b = new Point(0, 9);
    Point c = new Point(-3, -5);
    Point d = new Point(2, -6);
    Point e = new Point(12, 0);
    Point[] vertices = new Point[5];
    vertices[0] = new Point(a);
    vertices[1] = new Point(b);
    vertices[2] = new Point(c);
    vertices[3] = new Point(d);
    vertices[4] = new Point(e);

    poly = new ConvexPolygon(vertices, Color.cyan, false);

    cl = poly.getClass();

    pass &= test(cl.getConstructors().length == 1, test++);
    pass &= test((temp = cl.getInterfaces()).length == 1, test++);
    pass &= test(temp[0].getName().equals("Shape"), test++);
    pass &= test(verifyEqualsMethodSignature(cl), test++);

    cnt = countModifiers(cl.getDeclaredMethods(), Modifier.PUBLIC);
    pass &= test(cnt == 9, test++);

    cnt = cl.getFields().length;
    pass &= test(cnt == 0, test++);

    cnt = countModifiers(cl.getDeclaredFields(), Modifier.PROTECTED);
    pass &= test(cnt == 0, test++);

    cnt = countModifiers(cl.getDeclaredFields(), Modifier.PRIVATE);
    pass &= test(cnt == 3, test++);

    // Count and test number of of PACKAGE fields
    cnt =
        cl.getDeclaredFields().length
            - countModifiers(cl.getDeclaredFields(), Modifier.PRIVATE)
            - countModifiers(cl.getDeclaredFields(), Modifier.PROTECTED)
            - countModifiers(cl.getDeclaredFields(), Modifier.PUBLIC);
    pass &= test(cnt == 0, test++);

    return pass;
  }
Ejemplo n.º 2
0
  private static boolean testConvexPolygon() {
    boolean pass = true;
    int test = 1;
    ConvexPolygon poly;
    Point a = new Point(7, 7);
    Point b = new Point(0, 9);
    Point c = new Point(-3, -5);
    Point d = new Point(2, -6);
    Point e = new Point(12, 0);
    Point[] vertices = new Point[5];
    vertices[0] = new Point(a);
    vertices[1] = new Point(b);
    vertices[2] = new Point(c);
    vertices[3] = new Point(d);
    vertices[4] = new Point(e);

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

    poly = new ConvexPolygon(deepCopy(vertices), Color.cyan, false);

    pass &= test(approx(poly.getArea(), 137.0, 0.000001), test++);
    pass &= test(poly.getColor().equals(Color.cyan), test++);

    poly.setColor(Color.black);

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

    poly.setFilled(true);

    pass &= test(poly.getFilled(), test++);
    pass &= test(poly.getVertex(0).equals(a), test++);
    pass &= test(poly.getVertex(1).equals(b), test++);
    pass &= test(poly.getVertex(2).equals(c), test++);
    pass &= test(poly.getVertex(3).equals(d), test++);
    pass &= test(poly.getVertex(4).equals(e), test++);

    poly.setVertex(0, new Point(8, 9));

    pass &= test(poly.getVertex(0).equals(new Point(8, 9)), test++);

    poly.setVertex(1, new Point(1, 11));

    pass &= test(poly.getVertex(1).equals(new Point(1, 11)), test++);

    poly.setVertex(2, new Point(-2, -3));

    pass &= test(poly.getVertex(2).equals(new Point(-2, -3)), test++);

    poly.setVertex(3, new Point(3, -4));

    pass &= test(poly.getVertex(3).equals(new Point(3, -4)), test++);

    poly.setVertex(4, new Point(13, 2));

    pass &= test(poly.getVertex(4).equals(new Point(13, 2)), test++);

    poly.move(new Point(-1, -2));

    pass &= test(poly.getVertex(0).equals(new Point(7, 7)), test++);
    pass &= test(poly.getVertex(1).equals(new Point(0, 9)), test++);
    pass &= test(poly.getVertex(2).equals(new Point(-3, -5)), test++);
    pass &= test(poly.getVertex(3).equals(new Point(2, -6)), test++);
    pass &= test(poly.getVertex(4).equals(new Point(12, 0)), test++);

    ConvexPolygon poly2 = new ConvexPolygon(deepCopy(vertices), Color.black, false);

    pass &= test(!poly.equals(poly2), test++);

    poly2.setFilled(true);
    pass &= test(poly.equals(poly2), test++);

    ConvexPolygon poly3 = new ConvexPolygon(deepCopy(vertices), Color.black, false);
    poly3.setFilled(true);
    poly3.setVertex(0, new Point(7, 8));

    pass &= test(!poly2.equals(poly3), test++);

    poly3 = new ConvexPolygon(deepCopy(vertices), Color.black, false);
    poly3.setVertex(1, new Point(1, 9));

    pass &= test(!poly2.equals(poly3), test++);

    poly3 = new ConvexPolygon(deepCopy(vertices), Color.black, false);
    poly3.setVertex(4, new Point(13, 1));

    pass &= test(!poly2.equals(poly3), test++);

    poly3 = new ConvexPolygon(deepCopy(vertices), Color.red, false);

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

    return pass;
  }