public void TestMethod1() { Circle c1 = new Circle(10, 10, 10); Circle c2 = new Circle(0, 0, 5); Circle c3 = new Circle(-10, -10, 10); Assert.AreEqual(true, c1.Overlap(c2), "C1 should overlap C2"); Assert.AreEqual(false, c1.Overlap(c3), "C1 should not overlap C2"); Assert.AreEqual(true, c2.Overlap(c3), "C2 should overlap C3"); Assert.AreEqual(false, c1.Overlap(c3), "C1 should not overlap C3"); }
public void RunExercise() { // Quick test for your Point class: Point pt1 = new Point(10, 20); // Pt1 is located at (10,20) Point pt2 = new Point(0, 0); // Pt2 is at the origin pt1.Print(); // Prints out something like (10, 20) pt2.Print(); // Prints out something like (0, 0) pt1.SetX(-10); pt1.Print(); // Now prints out (-10, 20) pt2.SetY(10); pt2.Print(); // Prints out something like (0, 10) Console.WriteLine("pt1 is at {0} and {1}", pt1.GetX(), pt1.GetY()); // prints out: pt1 is at -10 and 20 // Note that even though c1 & c2 are using Point // objects to store the location, we're still passing // in the x & y values separately Circle c1 = new Circle(10, 20, 3); // c1 is located at (10,20), with radius = 3 Circle c2 = new Circle(0, 0, 4); // c2 is at the origin, radius is 4 c1.Print(); // Prints out something like (10, 20) radius=3 c2.Print(); // Prints out something like (0, 0) radius=4 c1.SetX(-10); c1.Print(); // Now prints out (-10, 20) radius=3 c2.SetY(10); c2.SetRadius(10); c2.Print(); // Prints out something like (0, 10) radius=10 Console.WriteLine("c1 is at {0} and {1}, with radius of {2}", c1.GetX(), c1.GetY(), c1.GetRadius()); // prints out c1 is at -10 and 20, with radius of 3 }
/// <summary> /// Determine if the otherCircle overlaps by /// calculating the distace between their centers /// and declaring overlap if the distance is less than /// the sum of their radii. If the distance is equal, /// they are touching. /// </summary> /// <param name="otherCircle"></param> /// <returns>True if the circles overlap</returns> public bool Overlap(Circle otherCircle) { double dist = center.GetDistance(otherCircle.GetCenter()); return (dist < (radius + otherCircle.GetRadius())); }