private static boolean testCircleArch() { boolean pass = true; int test = 1; int cnt; Circle circle; Class cl; Class[] temp; System.out.println("Circle architecture tests..."); circle = new Circle(5.6789, new Point(-99, 66), Color.cyan, false); cl = circle.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 == 10, 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 == 4, 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; }
private static boolean testCircle() { boolean pass = true; int test = 1; Circle circle; System.out.println("Circle tests..."); circle = new Circle(5.6789, new Point(-99, 66), Color.cyan, false); pass &= test(approx(circle.getArea(), Math.PI * 5.6789 * 5.6789, 0.000001), test++); pass &= test(circle.getColor().equals(Color.cyan), test++); circle.setColor(Color.black); pass &= test(circle.getColor().equals(Color.black), test++); pass &= test(!circle.getFilled(), test++); circle.setFilled(true); pass &= test(circle.getFilled(), test++); pass &= test(circle.getRadius() == 5.6789, test++); circle.setRadius(4.321); pass &= test(circle.getRadius() == 4.321, 7); pass &= test(approx(circle.getArea(), Math.PI * 4.321 * 4.321, 0.000001), test++); pass &= test(circle.getPosition().equals(new Point(-99, 66)), test++); circle.move(new Point(-5, -7)); pass &= test(circle.getPosition().equals(new Point(-104, 59)), test++); Circle circle2 = new Circle(4.321, new Point(-104, 59), Color.black, true); pass &= test(circle.equals(circle2), test++); Circle circle3 = new Circle(4.3219, new Point(-104, 59), Color.black, false); pass &= test(!circle2.equals(circle3), test++); circle3 = new Circle(4.321, new Point(-104, 59), Color.red, false); pass &= test(!circle2.equals(circle3), test++); circle3 = new Circle(4.321, new Point(104, 59), Color.black, false); pass &= test(!circle2.equals(circle3), test++); pass &= test(!circle2.equals(null), test++); pass &= test(!circle2.equals(new String("Whatever")), test++); return pass; }