Exemplo n.º 1
0
    def test_construction1(self):
        """testing the construction of the object with less than three
        vertices given"""

        p1 = shapes.Point(0, 0)
        p2 = shapes.Point(1, 1)
        self.assertRaises(RuntimeError, shapes.Polygon, p1, p2)
Exemplo n.º 2
0
    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)))
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
 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))
Exemplo n.º 5
0
 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))
Exemplo n.º 6
0
 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))
Exemplo n.º 7
0
 def test_for_point_and_point(self):
     """testing if a point is located inside another point with the
     same coordinates
     """
     
     point1 = shapes.Point(0, 0)
     point2 = shapes.Point(0, 0)
     self.assertFalse(operations.is_inside(point1, point2))
Exemplo n.º 8
0
 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))
Exemplo n.º 9
0
    def test_get_x2(self):
        """testing the 'get_x' method of the Line class with the Line
        object having the slope of infinity"""

        point1 = shapes.Point(1, 0)
        point2 = shapes.Point(1, 1)
        instance = shapes.Line.from_points(point1, point2)
        self.assertEqual(instance.get_x(1), 1)
Exemplo n.º 10
0
 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))
Exemplo n.º 11
0
    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)
Exemplo n.º 12
0
    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)
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
    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)
Exemplo n.º 15
0
    def test_construction1(self):
        """testing the construction of Rectangle instance with less
        than four vertices given"""

        p1 = shapes.Point(0, 0)
        p2 = shapes.Point(1, 1)
        p3 = shapes.Point(0, 1)
        self.assertRaises(RuntimeError, shapes.Rectangle, p1, p2, p3)
Exemplo n.º 16
0
    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)
Exemplo n.º 17
0
    def test_construction2(self):
        """testing the constuction of the object with the same vetex
        given twice"""

        p1 = shapes.Point(0, 0)
        p2 = shapes.Point(0, 1)
        p3 = shapes.Point(0, 0)
        self.assertRaises(RuntimeError, shapes.Polygon, p1, p2, p3)
Exemplo n.º 18
0
    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)
Exemplo n.º 19
0
 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))
Exemplo n.º 20
0
    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)
Exemplo n.º 21
0
    def test_number_of_vertices(self):
        """testing the number_of_vertices 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)
        self.assertEqual(instance.number_of_vertices, 4)
Exemplo n.º 22
0
    def test_navigator2(self):
        """testing the 'navigator' method of the Line class with an invalid
        start point given, which is not located on the Line"""

        instance = shapes.Line(1, 0)
        start = shapes.Point(0, 1)
        end = shapes.Point(1, 1)
        gen = instance.navigator(start, end, 0)
        self.assertRaises(RuntimeError, next, gen)
Exemplo n.º 23
0
 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))
Exemplo n.º 24
0
    def test_from_points(self):
        """testing the construction of the Line object via from_points
        method"""

        point1 = shapes.Point(0, 0)
        point2 = shapes.Point(1, 1)
        instance = shapes.Line.from_points(point1, point2)
        self.assertEqual(instance.slope, 1)
        self.assertEqual(instance.width, 0)
Exemplo n.º 25
0
    def test_area(self):
        """testing the 'area' 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)
        self.assertEqual(instance.area, 1)
Exemplo n.º 26
0
    def test_construction3(self):
        """testing the construction of Rectangle instance with the
        vertices given in a way that the edges won't be perpendecular"""

        p1 = shapes.Point(0, 0)
        p2 = shapes.Point(1, 0)
        p3 = shapes.Point(2, 1)
        p4 = shapes.Point(1, 0)
        self.assertRaises(RuntimeError, shapes.Rectangle, p1, p2, p3, p4)
Exemplo n.º 27
0
    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)
Exemplo n.º 28
0
    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)
Exemplo n.º 29
0
    def test_construction3(self):
        """testing the construction of the object with vertices given
        in a way that edges intersect one another"""

        p1 = shapes.Point(0, 0)
        p2 = shapes.Point(1, 1)
        p3 = shapes.Point(1, 0)
        p4 = shapes.Point(0, 1)
        self.assertRaises(RuntimeError, shapes.Polygon, p1, p2, p3, p4)
Exemplo n.º 30
0
    def test_perimeter(self):
        """Testing the 'perimeter' method of 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)
        self.assertEqual(instance.perimeter, 4)