def test_equality(self): """testing the equality condition of the LineSegment object""" point1 = shapes.Point(0, 0) point2 = shapes.Point(1, 1) instance1 = shapes.LineSegment(point1, point2) instance2 = shapes.LineSegment(point1, point2) self.assertEqual(instance1, instance2)
def test_move1(self): """testing the 'move' method of the LineSegment class""" point1 = shapes.Point(0, 0) point2 = shapes.Point(1, 1) instance1 = shapes.LineSegment(point1, point2) point3 = shapes.Point(1, 1) point4 = shapes.Point(2, 2) instance2 = shapes.LineSegment(point3, point4) instance1.move(1, 1) self.assertEqual(instance1, instance2)
def test_for_linesegment_and_linesegment(self): """testing if a given line segment is located inside another given line segment which should always return False """ end1 = shapes.Point(0, 0) end2 = shapes.Point(1, 1) line1 = shapes.LineSegment(end1, end2) end3 = shapes.Point(1, 0) end4 = shapes.Point(2, 1) line2 = shapes.LineSegment(end3, end4) self.assertFalse(operations.is_inside(line1, line2))
def test_move2(self): """testing the 'move' method of the LineSegment class with a full rotation """ point1 = shapes.Point(0, 0) point2 = shapes.Point(1, 1) line = shapes.LineSegment(point1, point2) line.move(delta_theta = np.math.pi) self.assertEqual(line, shapes.LineSegment(point1, point2)) line.move(delta_theta = np.math.pi*2) self.assertEqual(line, shapes.LineSegment(point1, point2))
def test_diagonals(self): """testing the 'diagonals' method of Rectangle class""" vertex1 = shapes.Point(0, 0) vertex2 = shapes.Point(1, 0) vertex3 = shapes.Point(1, 1) vertex4 = shapes.Point(0, 1) instance = shapes.Rectangle(vertex1, vertex2, vertex3, vertex4) diagonal1 = shapes.LineSegment(end1=shapes.Point(0, 0), end2=shapes.Point(1, 1)) diagonal2 = shapes.LineSegment(end1=shapes.Point(1, 0), end2=shapes.Point(0, 1)) expected = (diagonal1, diagonal2) self.assertEqual(instance.diagonals, expected)
def test_move3(self): """testing the 'move' method of LineSegment class with all the coordinates changing """ point1 = shapes.Point(-1*np.sqrt(2), 0) point2 = shapes.Point(np.sqrt(2), 0) line1 = shapes.LineSegment(point1, point2) line1.move(delta_x = 5, delta_y = 5, delta_theta = 3*np.math.pi/4) point3 = shapes.Point(4, 6) point4 = shapes.Point(6, 4) line2 = shapes.LineSegment(point3, point4) self.assertEqual(line1, line2)
def test_midlines(self): """testing the 'midlines' method of Rectangle class""" v1 = shapes.Point(0, 0) v2 = shapes.Point(1, 0) v3 = shapes.Point(1, 2) v4 = shapes.Point(0, 2) rec = shapes.Rectangle(v1, v2, v3, v4) midline1 = shapes.LineSegment(end1 = shapes.Point(0.5, 0), end2 = shapes.Point(0.5, 2)) midline2 = shapes.LineSegment(end1 = shapes.Point(0, 1), end2 = shapes.Point(1, 1)) expected = [midline1, midline2] res = rec.midlines self.assertEqual(set(res), set(expected))
def test_edges(self): """Testing the 'edges' method from Polygon class""" p1 = shapes.Point(0, 0) p2 = shapes.Point(1, 0) p3 = shapes.Point(1, 1) p4 = shapes.Point(0, 1) instance = shapes.Polygon(p1, p2, p3, p4) expected = ( shapes.LineSegment(p4, p1), shapes.LineSegment(p1, p2), shapes.LineSegment(p2, p3), shapes.LineSegment(p3, p4), ) self.assertEqual(instance.edges, expected)
def test_move(self): """testing if the Montmorillonite instance moves correctly with the given derivatives; this is inherited from the parent class 'Particle' """ particle = base_classes.Kaolinite( x=0, y=0, inclination=np.math.pi / 4, thickness=2, length=6000 * np.sqrt(2), ) particle.move(delta_x=1000, delta_y=1000, delta_theta=np.math.pi / 4) self.assertEqual(particle.x, 1000) self.assertEqual(particle.y, 1000) self.assertEqual(particle.inclination, np.math.pi / 2) self.assertEqual(particle.midpoint, shapes.Point(1000, 1000)) self.assertEqual( particle.midline, shapes.LineSegment(shapes.Point(1000, 1000 + 3000 * np.sqrt(2)), shapes.Point(1000, 1000 - 3000 * np.sqrt(2)))) v1 = shapes.Point(1001, 1000 + 3000 * np.sqrt(2)) v2 = shapes.Point(999, 1000 + 3000 * np.sqrt(2)) v3 = shapes.Point(999, 1000 - 3000 * np.sqrt(2)) v4 = shapes.Point(1001, 1000 - 3000 * np.sqrt(2)) self.assertEqual(particle.shape, shapes.Rectangle(v1, v2, v3, v4))
def test_segmentalize(self): """testing if the 'segments' attribute of the Montmorillonite instance is created correctly using the 'segmentalize' method of the parent class 'Clay'; it should generate three segments which all have the same 'num' attribute and are all instances of 'Montmorillonite' class; also testing if the next created particle comes with a correct 'num' attribute regardless of its type """ particle = base_classes.Kaolinite( x=0, y=0, inclination=np.math.pi / 4, thickness=1, length=6000 * np.sqrt(2), ) self.assertEqual(len(particle.segments), 3) for seg in particle.segments: self.assertTrue(seg.is_segment) self.assertEqual(particle.segments[1].midpoint, shapes.Point(0, 0)) self.assertAlmostEqual(particle.segments[0].length, 2000 * np.sqrt(2)) self.assertEqual( particle.segments[2].midline, shapes.LineSegment(shapes.Point(1000, 1000), shapes.Point(3000, 3000)))
def test_get_y(self): """testing the 'get_y' method of the LineSegment class""" point1 = shapes.Point(0, 0) point2 = shapes.Point(1, 1) instance = shapes.LineSegment(point1, point2) self.assertEqual(instance.get_x(0.5), 0.5)
def test_midpoint2(self): """testing the 'midpoint' method of the LineSegment class given an invalid ratio""" p1 = shapes.Point(0, 0) p2 = shapes.Point(1, 1) instance = shapes.LineSegment(p1, p2) self.assertRaises(RuntimeError, instance.midpoint, 2)
def test_infinite(self): """testing the 'infinite' method of the LineSegment class""" point1 = shapes.Point(0, 0) point2 = shapes.Point(1, 1) instance1 = shapes.LineSegment(point1, point2) instance2 = shapes.Line(1, 0) self.assertEqual(instance1.infinite, instance2)
def test_slope(self): """testing the 'slope' method of the LineSegment class""" point1 = shapes.Point(0, 0) point2 = shapes.Point(1, 1) instance = shapes.LineSegment(point1, point2) expected = 1 self.assertEqual(instance.slope, expected)
def test_length(self): """testing the 'length' method of the LineSegment class""" point1 = shapes.Point(0, 0) point2 = shapes.Point(1, 1) instance = shapes.LineSegment(point1, point2) expected = np.sqrt(2) self.assertEqual(instance.length, expected)
def test_inclination(self): """testing the 'inclination' method of the LineSegment class""" point1 = shapes.Point(0, 0) point2 = shapes.Point(1, 1) instance = shapes.LineSegment(point1, point2) expected = (np.pi) / 4 self.assertEqual(instance.inclination, expected)
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_slope2(self): """testing the 'slope' method of the LineSegment class for a vertical LineSegment""" point1 = shapes.Point(0, 0) point2 = shapes.Point(0, 1) instance = shapes.LineSegment(point1, point2) expected = np.tan(np.pi / 2) self.assertEqual(instance.slope, expected)
def test_get_y2(self): """testing the 'get_y' method of the LineSegment class expecting an error asking for coordinates that isn't loacated on the LineSegment instance""" point1 = shapes.Point(0, 0) point2 = shapes.Point(1, 1) instance = shapes.LineSegment(point1, point2) self.assertRaises(RuntimeError, instance.get_y, 2)
def test_for_point_and_linesegment(self): """testing if a given point is located inside a given line segment """ point = shapes.Point(0, 0) end1 = shapes.Point(0, 1) end2 = shapes.Point(0, -1) line = shapes.LineSegment(end1, end2) self.assertFalse(operations.is_inside(point, line))
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_linesegment_and_point(self): """testing if a given line segment is located inside a given point which should always return False """ end1 = shapes.Point(0, 0) end2 = shapes.Point(1, 1) line = shapes.LineSegment(end1, end2) point = shapes.Point(0, 0) self.assertFalse(operations.is_inside(line, point))
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_line_and_linesegment(self): """testing if a given infinite line is located inside a given line segment which should always return False """ line1 = shapes.Line(1, 0) end1 = shapes.Point(0, 0) end2 = shapes.Point(1, 1) line2 = shapes.LineSegment(end1, end2) self.assertFalse(operations.is_inside(line1, line2))
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_midpoint(self): """testing the 'midpoint' method of the LineSegment class""" p1 = shapes.Point(0, 0) p2 = shapes.Point(1, 1) instance = shapes.LineSegment(p1, p2) expected = shapes.Point(0.5, 0.5) res = instance.midpoint(0.5) self.assertAlmostEqual(res.x, expected.x) self.assertAlmostEqual(res.y, expected.y)
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_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_from_diagonal1(self): """testing the 'from_diagonal' method of Rectangle class""" end1 = shapes.Point(0, 0) end2 = shapes.Point(1, 1) instance1 = shapes.Rectangle.from_diagonal(diagonal=shapes.LineSegment(end1, end2)) vertex1 = shapes.Point(0, 0) vertex2 = shapes.Point(1, 0) vertex3 = shapes.Point(1, 1) vertex4 = shapes.Point(0, 1) instance2 = shapes.Rectangle(vertex1, vertex2, vertex3, vertex4) self.assertEqual(instance1, instance2)
def test_shape(self): """testing if the 'shape' attribute is assigned correctly """ wall = base_classes.Wall(x=5000, y=0, inclination=np.math.pi / 2, is_fixed=True, length=10000) end1 = shapes.Point(5000, -5000) end2 = shapes.Point(5000, 5000) exp = shapes.LineSegment(end1, end2) self.assertEqual(wall.shape, exp)