import junit.framework.TestCase; /** * Tests the Circle class. * * @author Matt Boutell. * Created Mar 11, 2008. */ public class CircleTest extends TestCase { /** * Test method for {@link Circle#toString()}. */ public void testToString() { Circle c = new Circle(new Point(3,4), 5); assertEquals("[Circle: (3.00,4.00), 5.00]", c.toString()); } /** * Test method for {@link Circle#equals(java.lang.Object)}. */ public void testEqualsObject() { Point p1 = new Point(3, 8); Point p2 = new Point(4, 5); Circle c1 = new Circle(p1, 4); Circle c2 = new Circle(p1, 4); Circle c3 = new Circle(p2, 4); Circle c4 = new Circle(p1, 5); // assertEquals calls .equals assertEquals(c1,c2); // Unfortunately, there's no assertNotEquals; this code calls .equals // explicitly. assertFalse(c2.equals(c3)); // different centers assertFalse(c2.equals(c4)); // different radii } /** * Test method for {@link Circle#getArea()}. */ public void testGetArea() { Circle c = new Circle(new Point(0,0), 5); // I use string versions to handle rounding assertEquals("78.54", String.format("%.2f", c.getArea())); } /** * Test method for {@link Circle#intersects(Rectangle)}. */ public void testIntersectsRectangle() { // TODO as part of the BONUS, else you can delete. fail("Not yet implemented"); } /** * Test method for {@link Circle#intersects(Circle)}. */ public void testIntersectsCircle() { // TODO: write complete tests for this: a pair that don't intersect, // an overlapping pair (intersect), and a tangent pair (intersect) fail("Not yet implemented"); } /** * Test method for {@link Circle#translate(double, double)}. */ public void testTranslate() { // TODO: write a test to make sure it moves correctly fail("Not yet implemented"); } /** * Test method for {@link Circle#isInside(Point)}. */ public void testIsInside() { // TODO: Write 3 tests, similar to the 3 for testIntersects // (in, out, boundary) fail("Not yet implemented"); } /** * Test method for {@link Circle#boundingBox()}. */ public void testBoundingBox() { Circle c = new Circle(new Point(6,7), 4); Rectangle r = new Rectangle(new Point(2,3), new Point(10,11)); assertEquals(r, c.boundingBox()); } }