def test_for_circle_and_circle5(self): """the fifth test for checking if a given circle is located inside another given circle with them intersecting """ circle1 = shapes.Circle(shapes.Point(0, 0), 1) circle2 = shapes.Circle(shapes.Point(10, 0), 1) self.assertFalse(operations.is_inside(circle1, circle2))
def test_equality(self): """testing the equality condition of Circle class""" c = shapes.Point(0, 0) d = 1 instance1 = shapes.Circle(c, d) instance2 = shapes.Circle(c, d) self.assertEqual(instance1, instance2)
def test_for_circle_and_circle2(self): """the second test for checking if a given circle is located inside another given circle with them fully overlap each other """ circle1 = shapes.Circle(shapes.Point(0, 0), 1) circle2 = shapes.Circle(shapes.Point(0, 0), 1) self.assertFalse(operations.is_inside(circle1, circle2))
def test_for_circle_and_circle3(self): """the third test for checking if a given circle is located inside another given circle with the second one being inside the first one """ circle1 = shapes.Circle(shapes.Point(0, 0), 2) circle2 = shapes.Circle(shapes.Point(0, 0), 1) self.assertFalse(operations.is_inside(circle1, circle2))
def test_move(self): """testing the 'move' method of the Circle class""" c1 = shapes.Point(0, 0) c2 = shapes.Point(1, 1) d = 1 instance1 = shapes.Circle(c1, d) instance2 = shapes.Circle(c2, d) instance1.move(1, 1) self.assertEqual(instance1, instance2)
def test_shape(self): """testing if the 'shape' attribute of the Sand instance is assigned correctly """ particle = base_classes.Sand(x=0, y=0, diameter=10) self.assertEqual(particle.shape, shapes.Circle(shapes.Point(0, 0), 10))
def __init__(self, *args, **kwargs): """initialize clay attributes Args: diameter (float): the diameter of the sand particle x (float): x coordinate of the particle in nanometers y (float): y coordinate of the particle in nanometers inclination (float): the inclination of the particle in radians, ranges from '0' to '2*pi', this is left unused if the shape of the partice is circular Exceptions: SizeOutOfBound (Exception): raises when the given diameter is outside the bounds specified as the class private attributes """ try: if kwargs["length"] < self.diameter_bounds[0]: raise RuntimeError("the given diameter is lower than expected") elif kwargs["length"] > self.diameter_bounds[1]: raise RuntimeError( "the given diameter is higher than expected") except AttributeError: pass self.length = kwargs.pop("length") x, y = kwargs["x"], kwargs["y"] kwargs["inclination"] = 0 self.shape = shapes.Circle(shapes.Point(x, y), self.length) super().__init__(*args, **kwargs)
def test_for_circle_and_point(self): """testing if a given circle is located inside a given point which should always return False """ circle = shapes.Circle(shapes.Point(0, 0), 1) point = shapes.Point(0, 0) self.assertFalse(operations.is_inside(circle, point))
def test_for_point_and_circle3(self): """the third test for checking if a given point is inside a given circle with the point being located outside the circle """ point = shapes.Point(5, 5) circle = shapes.Circle(shapes.Point(0, 0), 1) self.assertFalse(operations.is_inside(point, circle))
def test_for_circle_and_line(self): """testing if a given circle is located inside a given inifinite line which should always return False """ circle = shapes.Circle(shapes.Point(0, 0), 1) line = shapes.Line(1, 0) self.assertFalse(operations.is_inside(circle, line))
def test_perimeter(self): """testing the 'perimeter' method of Circle class""" c = shapes.Point(0, 0) d = 1 instance = shapes.Circle(c, d) expected = (np.pi) * (d) self.assertEqual(instance.perimeter, expected)
def test_shape(self): """testing if the 'shape' attribute of the Sand instance is assigned correctly; this behavior is inherited from the parent class 'Sand' """ particle = base_classes.Sand(x=1, y=1, diameter=10) self.assertEqual(particle.shape, shapes.Circle(shapes.Point(1, 1), 10))
def test_area(self): """testing the 'area' method of Circle class""" c = shapes.Point(0, 0) d = 1 instance = shapes.Circle(c, d) expected = ((np.pi) * (d) ** 2) / 4 self.assertEqual(instance.area, expected)
def test_for_point_and_circle1(self): """the first test for checking if a given point is inside a given circle, with the point being located inside the circle """ point = shapes.Point(0, 0) circle = shapes.Circle(shapes.Point(0, 0), 1) self.assertTrue(operations.is_inside(point, circle))
def test_for_point_and_circle2(self): """the second test for checking if a given point is inside a given circle, with the point being located on the perimeter of the circle """ point = shapes.Point(0, -1) circle = shapes.Circle(shapes.Point(0, 0), 1) self.assertFalse(operations.is_inside(point, circle))
def test_circumcircle(self): """testing the 'circumcircle' method of the LineSegment class""" point1 = shapes.Point(0, 0) point2 = shapes.Point(1, 1) instance = shapes.LineSegment(point1, point2) circle = shapes.Circle(shapes.Point(0.5, 0.5), np.sqrt(2)) res = instance.circumcircle self.assertEqual(res, circle)
def test_for_linesegment_and_circle3(self): """the third test for checking if a given line segment is located inside a given circle with them intersecting each other """ end1 = shapes.Point(0, 0) end2 = shapes.Point(3, 3) line = shapes.LineSegment(end1, end2) circle = shapes.Circle(shapes.Point(0, 0), 1) self.assertFalse(operations.is_inside(line, circle))
def test_for_circle_and_linesegment(self): """testing if a given circle is located inside a given line segment which should always return False """ circle = shapes.Circle(shapes.Point(0, 0), 1) end1 = shapes.Point(0, 0) end2 = shapes.Point(1, 1) line = shapes.LineSegment(end1, end2) self.assertFalse(operations.is_inside(circle, line))
def test_for_linesegment_and_circle4(self): """the fourth test for checking if a given line segment is located inside a given circle with them being fully apart """ end1 = shapes.Point(10, 10) end2 = shapes.Point(11, 11) line = shapes.LineSegment(end1, end2) circle = shapes.Circle(shapes.Point(0, 0), 1) self.assertFalse(operations.is_inside(line, circle))
def test_circumcircle(self): """testing the 'circumcircle' method of Rectangle class""" vertex1 = shapes.Point(0, 0) vertex2 = shapes.Point(1, 0) vertex3 = shapes.Point(1, 2) vertex4 = shapes.Point(0, 2) instance = shapes.Rectangle(vertex1, vertex2, vertex3, vertex4) expected = shapes.Circle(shapes.Point(0.5, 1), np.sqrt(5)) self.assertEqual(instance.circumcircle, expected)
def test_get_point_on_perimeter(self): """testing the 'get_point_on_perimeter' method of Circle class""" c = shapes.Point(0, 0) d = 2 instance = shapes.Circle(c, d) angle = (np.pi) / 2 res = instance.get_point_on_perimeter(angle) self.assertAlmostEqual(res.x, 0) self.assertAlmostEqual(res.y, 1)
def test_for_linesegment_and_circle1(self): """the first test for checking if a given line segment is located inside a given circle with the line segment being fully inside the circle """ end1 = shapes.Point(0, 0) end2 = shapes.Point(0, 0.4) line = shapes.LineSegment(end1, end2) circle = shapes.Circle(shapes.Point(0, 0), 1) self.assertTrue(operations.is_inside(line, circle))
def test_move(self): """testing if the Quartz instance moves correctly with the given derivatives; this is inherited from the parent class 'Particle' """ particle = base_classes.Sand(x=1, y=1, diameter=10) particle.move(delta_x=2, delta_y=2) self.assertEqual(particle.x, 3) self.assertEqual(particle.y, 3) self.assertEqual(particle.shape, shapes.Circle(shapes.Point(3, 3), 10))
def test_navigator2(self): """testing if the 'navigator' method of the Circle class terminates after the specified number of rounds""" c = shapes.Point(0, 0) d = 1 instance = shapes.Circle(c, d) gen = instance.navigator(0, np.pi / 4, 2) count = 0 for _ in gen: count += 1 self.assertEqual(count, 16)
def test_navigator(self): """testing the 'navigator' method of the Circle class""" c = shapes.Point(0, 0) d = 2 instance = shapes.Circle(c, d) gen = instance.navigator(0, np.pi / 4, 1) next(gen) expected = shapes.Point((np.sqrt(2) / 2), (np.sqrt(2) / 2)) p = next(gen) self.assertAlmostEqual(p.x, expected.x) self.assertAlmostEqual(p.y, expected.y)
def test_for_linesegment_and_circle2(self): """the second test for checking if a given line segment is located inisde a given circle with the line segment being inside the circle but with one of its ends touching the circle's perimeter """ end1 = shapes.Point(0, 0) end2 = shapes.Point(0, 1) line = shapes.LineSegment(end1, end2) circle = shapes.Circle(shapes.Point(0, 0), 1) self.assertFalse(operations.is_inside(line, circle))
def test_for_rectangle_and_circle5(self): """the fifth test for checking if a given rectangle is located inside a given circle with them being fully apart """ v1 = shapes.Point(-2, 0) v2 = shapes.Point(0, -2) v3 = shapes.Point(2, 0) v4 = shapes.Point(0, 2) rec = shapes.Rectangle(v1, v2, v3, v4) circle = shapes.Circle(shapes.Point(5, 5), 1) self.assertFalse(operations.is_inside(rec, circle))
def test_for_circle_and_rectangle4(self): """the fourth test for checking if a given circle is located inside a given rectangle with them being fully apart """ circle = shapes.Circle(shapes.Point(10, 10), 1) v1 = shapes.Point(-2, -2) v2 = shapes.Point(2, -2) v3 = shapes.Point(2, 2) v4 = shapes.Point(-2, 2) rec = shapes.Rectangle(v1, v2, v3, v4) self.assertFalse(operations.is_inside(circle, rec))
def test_for_circle_and_rectangle3(self): """the third test for checking if a given circle is located inside a given rectangle with the circle intersecting the rectangle """ circle = shapes.Circle(shapes.Point(0, -3), 2) v1 = shapes.Point(-2, -2) v2 = shapes.Point(2, -2) v3 = shapes.Point(2, 2) v4 = shapes.Point(-2, 2) rec = shapes.Rectangle(v1, v2, v3, v4) self.assertFalse(operations.is_inside(circle, rec))
def test_for_circle_and_rectangle2(self): """the second test for checking if a given circle is located inside a given rectangle with the circle being inside the rectangle but touching one of its edges """ circle = shapes.Circle(shapes.Point(0, -1), 2) v1 = shapes.Point(-2, -2) v2 = shapes.Point(2, -2) v3 = shapes.Point(2, 2) v4 = shapes.Point(-2, 2) rec = shapes.Rectangle(v1, v2, v3, v4) self.assertFalse(operations.is_inside(circle, rec))