Beispiel #1
0
    def testValidConstruction(self):
        p1 = Point(1, 2)
        p2 = Point(1, 1)
        p3 = Point(2, 1)
        t1 = Triangle(p1, p2, p3)

        self.assertEqual(p1, t1.point1)
        self.assertEqual(p2, t1.point2)
        self.assertEqual(p3, t1.point3)

        l1 = Line(4.33, 8, -4, 3.67)
        l2 = Line(-4, 3.67, 2.19, -5)
        l3 = Line(2.19, -5, 4.33, 8)
        t2 = Triangle(l1, l2, l3)

        self.assertEqual(l1, t2.line1)
        self.assertEqual(l2, t2.line2)
        self.assertEqual(l3, t2.line3)

        t3 = Triangle(1, 2, 5, 1, 3, 3)
        self.assertEqual(1, t3.point1.x)
        self.assertEqual(2, t3.point1.y)
        self.assertEqual(5, t3.point2.x)
        self.assertEqual(1, t3.point2.y)
        self.assertEqual(3, t3.point3.x)
        self.assertEqual(3, t3.point3.y)
 def setUp(self):
     """
     Create a few test objects.
     """
     self.isosceles_triangle = Triangle(5, 5, 5, 7.07)
     self.equilateral_triangle = Triangle(6.93, 8, 8, 8)
     self.triangle = Triangle(24, 50, 30, 40)
Beispiel #3
0
 def setUp(self):
     """
     Create a few test objects.
     """
     self.side8side10side15 = Triangle(8, 10, 15)
     self.side10side12side15 = Triangle(10, 12, 15)
     self.side5side5side5 = Triangle(5, 5, 5)
Beispiel #4
0
 def setUp(self):
     """
     Create a few test objects.
     """
     self.equilateral = Triangle(7, 7, 7)
     self.isosceles = Triangle(4, 6, 6)
     self.right = Triangle(5, 4, 3)
     self.scalene = Triangle(5, 4, 6)
Beispiel #5
0
 def setUp(self):
     """
     Create a few test objects.
     """
     self.sidea7sideb8sidec9 = Triangle(7, 8, 9)
     self.sidea3sideb4sidec5 = Triangle(3, 4, 5)
     self.sidea9sideb9sidec9 = Triangle(9, 9, 9)
     self.sidea1sideb100sidec3 = Triangle(1, 100, 3)
     self.sidea0sideb10sidec3 = Triangle(0, 10, 3)
Beispiel #6
0
    def testComputeArea(self):
        t1 = Triangle(1, 1, 2, 1, 1, 2)
        self.assertAlmostEqual(.5, t1.computeArea(), places=4)

        t2 = Triangle(1, 2, 5, 1, 3, 3)
        self.assertAlmostEqual(3, t2.computeArea(), places=4)

        t3 = Triangle(-3, 3, 2, 4, 3, -1)
        self.assertAlmostEqual(13, t3.computeArea(), places=4)
Beispiel #7
0
def test_triangle():
    """
    Defines tests on some specific triangle objects.
    """
    h2b3sA4sB5 = Triangle(2,3,4,5)
    h9b10sA12sB9 = Triangle(9,10,12,9)
    assert h2b3sA4sB5.area() == 3
    assert h2b3sA4sB5.perimeter() == 12
    assert h2b3sA4sB5.righttriangle() == True
    assert h9b10sA12sB9.area() == 45
    assert h9b10sA12sB9.perimeter() == 31
    assert h9b10sA12sB9.righttriangle() == False
Beispiel #8
0
    def test_valid(self):
        """
        Confirm or deny if the triangle is a valid configuration.
        """
        with self.assertRaises(ValueError):
            Triangle(5, 1, 1)

        with self.assertRaises(ValueError):
            Triangle(5, 1, 4)

        self.assertTrue(self.equilateral.is_valid())
        self.assertTrue(self.scalene.is_valid())
        self.assertTrue(self.isosceles.is_valid())
        self.assertTrue(self.right.is_valid())
def main():
    t1=Triangle() 
    t1.create(3,4,5) # can call using object reference
    test_shape(t1)

    t2=Triangle() #change this
    Triangle.create(t2,3,4,12) # can also call using class reference
    test_shape(t2)

    c=Circle.create(7) # can be called only using class refernce
    test_shape(c)

    c2=Circle.create(-3)
    test_shape(c2)
Beispiel #10
0
def get_triangles(filename):
    """
    Read in from the JSON file supplied and create
    a list of triangles based on the input data.
    """
    with open(filename, 'r') as handle:
        try:
            data = json.load(handle)
        except json.decoder.JSONDecodeError as error:
            print(error)
            raise

    # Manually iterate over the JSON dictionaries in the list
    # of rectangles. Create a new Rectangle object for each one
    # and add it to the list.
    triangle_objects = []
    for triangle in data['triangle_list']:
        side1 = triangle['side1']
        side2 = triangle['side2']
        side3 = triangle['side3']
        new_triangle = Triangle(side1, side2, side3)
        triangle_objects.append(new_triangle)

    # Return the list of Rectangle objects
    return triangle_objects
Beispiel #11
0
 def _init(self):
     self.n = len(self.sides)
     assert (self.n < 4), 'No support for sides > 3'
     if self.n == 3:
         self.shape = Triangle(*self.sides)
     elif self.n == 2:
         self.shape = Rectangle(*self.sides)
Beispiel #12
0
def get_triangles(filename):
    """
    Read in from the JSON file supplied and create
    a list of triangles based on the input data.
    """
    with open(filename, "r") as handle:
        try:
            data = json.load(handle)
        except json.decoder.JSONDecodeError as error:
            print(error)
            raise

    # Manually iterate over the JSON dictionaries in the list
    # of triangles. Create a new triangle object for each one
    # and add it to the list.
    triangle_objects = []
    for tri in data["triangle_list"]:
        a = tri["a"]
        b = tri["b"]
        c = tri["c"]
        new_triangle = Triangle(a, b, c)
        triangle_objects.append(new_triangle)

    # Return the list of triangle objects
    return triangle_objects
Beispiel #13
0
def get_triangles(filename):
    """
    Read in from the JSON file supplied and create
    a list of rectangles based on the input data.
    """
    with open(filename, "r") as handle:
        try:
            data = json.load(handle)
        except json.decoder.JSONDecodeError as error:
            print(error)
            raise

    # Manually iterate over the JSON dictionaries in the list
    # of rectangles. Create a new Rectangle object for each one
    # and add it to the list.
    triangle_objects = []
    for tria in data["triangle_list"]:
        lengthA = tria["lengthA"]
        lengthB = tria["lengthB"]
        lengthC = tria["lengthC"]
        height = tria["height"]
        new_triangle = Triangle(lengthA, lengthB, lengthC, height)
        triangle_objects.append(new_triangle)

    # Return the list of Rectangle objects
    return triangle_objects
Beispiel #14
0
    def testMove(self):
        t1 = Triangle(1, 2, 5, 1, 3, 3)

        t1.move(3, 4)
        self.assertEqual(4, t1.point1.x)
        self.assertEqual(6, t1.point1.y)
        self.assertEqual(8, t1.point2.x)
        self.assertEqual(5, t1.point2.y)
        self.assertEqual(6, t1.point3.x)
        self.assertEqual(7, t1.point3.y)

        t1.move(.4321, .7654)
        self.assertEqual(4.4321, t1.point1.x)
        self.assertEqual(6.7654, t1.point1.y)
        self.assertEqual(8.4321, t1.point2.x)
        self.assertEqual(5.7654, t1.point2.y)
        self.assertEqual(6.4321, t1.point3.x)
        self.assertEqual(7.7654, t1.point3.y)

        t1.move(-.4321, -.7654)
        self.assertEqual(4, t1.point1.x)
        self.assertEqual(6, t1.point1.y)
        self.assertEqual(8, t1.point2.x)
        self.assertEqual(5, t1.point2.y)
        self.assertEqual(6, t1.point3.x)
        self.assertEqual(7, t1.point3.y)
Beispiel #15
0
    def testValidateTriangle(self):
        t1 = Triangle(1, 1, -1, -5, -3, -2)
        Validator.validateTriangle(t1, "Triangle unexpectedly invalid")

        self.assertRaises(
            ShapeException, Validator.validateLine, "(1, 1, -1, -5, -3, -2)",
            "String \'(1, 1, -1, -5, -3, -2)\' is not a valid triangle")
        self.assertRaises(ShapeException, Validator.validateLine, Point(1, 1),
                          "Point is not a valid triangle")
def test_triangle():
    """
    Defines tests on some specific triangle objects
    """
    side8side10side15 = Triangle(8, 10, 15)
    side10side12side15 = Triangle(10, 12, 15)
    side5side5side5 = Triangle(5, 5, 5)

    # Test areas, parameters, and equivalateral triangle
    assert round(side8side10side15.area()) == 37
    assert round(side10side12side15.area()) == 60
    assert round(side5side5side5.area()) == 11

    assert side8side10side15.perimeter() == 33
    assert side10side12side15.perimeter() == 37
    assert side5side5side5.perimeter() == 15
    assert not side8side10side15.is_equilateral()
    assert not side10side12side15.is_equilateral()
    assert side5side5side5.is_equilateral()
Beispiel #17
0
 def __init__(self, menu_items, font_name, font_size=None, x=0, y=0):
     self.x = x
     self.y = y
     self.items = menu_items
     self.labels = [None] * len(self.items)
     for index, item in enumerate(self.items):
         label = Label(item.name, font_name=font_name, font_size=font_size)
         self.labels[index] = label
         # if label not in self.labels:
         #     self.labels.append(label)
     self.set_label_coordinates()
     self.pointer = Triangle(0, 0, 10, 10)
     self.update_pointer()
def get_triangles(filename):
    """
    Read in from the YAML file supplied and create
    a list of triangles based on the input data.
    """
    try:
        handle = open(filename, 'r')
        data = yaml.load(handle)
    except yaml.YAMLError as error:
        print(error)
    finally:
        handle.close()

    # Use a list comprehension to create a new triangle
    # object for each radius integer found in the triangle_list.
    triangle_objects = [Triangle(length) for length in data['triangle_list']]

    # Return the list of triangle objects
    return triangle_objects
def get_triangles(filename):
    """
        Read in from the JSON file supplied and create
        a list of triangles based on the input data.
        """
    with open(filename, "r") as handle:
        try:
            data = json.load(handle)
        except json.decoder.JSONDecodeError as error:
            print(error)
            raise

    # Manually iterate over the JSON dictionaries in the list
    # of triangles. Create a new Triangle object for each one
    # and add it to the list.
    triangle_objects = [
        Triangle(tr["side_a"], tr["side_b"], tr["side_c"]) for
        tr in data["triangle_list"]]

    # Return the list of Triangle objects
    return triangle_objects
Beispiel #20
0
def paint(canvas):
    text = read_file()
    for line in text:
        if "rcl" in line or "va" in line:
            prop = line.split(", ")
            Oval(canvas, prop[1], prop[2], prop[3], prop[4], prop[5], prop[6],
                 prop[7])
        elif "ua" in line or "rect" in line:
            prop = line.split(", ")
            Rectangle(canvas, prop[1], prop[2], prop[3], prop[4], prop[5],
                      prop[6], prop[7])
        elif "tri" in line:
            prop = line.split(", ")
            Triangle(canvas, prop[1], prop[2], prop[3], prop[4], prop[5],
                     prop[6], prop[7], prop[8], prop[9])
        elif "in" in line:
            prop = line.split(", ")
            Line(canvas, prop[1], prop[2], prop[3], prop[4], prop[5], prop[6])
        elif "arc" in line:
            prop = line.split(", ")
            Arc(canvas, prop[1], prop[2], prop[3], prop[4], prop[5], prop[6],
                prop[7], prop[8], prop[9])
Beispiel #21
0
def get_triangles(filename):
    """
    Read in from the JSON file supplied and create
    a list of triangles based on the input data.
    """
    triangle_objects = []
    with open(filename, 'r') as handle:
        try:
            data = json.load(handle)
        except json.decoder.JSONDecodeError as error:
            print(error)
            raise
    # Manually iterate over the JSON dictionaries in the list
    # of triangles. Create a new Triangle object for each one
    # and add it to the list.
    for item in data['triangles']:
        height = item['height']
        base = item['base']
        sideA = item['sideA']
        sideB = item['sideB']
        new_triangle = Triangle(height, base, sideA, sideB)
        triangle_objects.append(new_triangle)

    return triangle_objects
Beispiel #22
0
 def generator(sides: typing.Tuple[int, ...] = ()):
     assert len(sides) == 3
     side_set = [Side(s) for s in sides]
     side_set = (*side_set, )
     return Triangle(side_set)
Beispiel #23
0
 def __init__(self, vertices: Mat, connectivity_matrix: Mat,
              quadrature_order: int):
     """
     ================================================================================================================
     Class :
     ================================================================================================================
     
     ================================================================================================================
     Parameters :
     ================================================================================================================
     
     ================================================================================================================
     Attributes :
     ================================================================================================================
     
     """
     # --------------------------------------------------------------------------------------------------------------
     # Building the cell
     # --------------------------------------------------------------------------------------------------------------
     cell_shape = Cell.get_cell_shape(vertices)
     if cell_shape == "SEGMENT":
         c = Segment(vertices, quadrature_order)
         centroid = c.centroid
         volume = c.volume
         diameter = c.diameter
         quadrature_points = c.quadrature_points
         quadrature_weights = c.quadrature_weights
         del c
     if cell_shape == "TRIANGLE":
         c = Triangle(vertices, quadrature_order)
         centroid = c.centroid
         volume = c.volume
         diameter = c.diameter
         quadrature_points = c.quadrature_points
         quadrature_weights = c.quadrature_weights
         del c
     if cell_shape == "POLYGON":
         c = Polygon(vertices, quadrature_order)
         centroid = c.centroid
         volume = c.volume
         diameter = c.diameter
         quadrature_points = c.quadrature_points
         quadrature_weights = c.quadrature_weights
         del c
     if cell_shape == "TETRAHEDRON":
         c = Tetrahedron(vertices, quadrature_order)
         centroid = c.centroid
         volume = c.volume
         diameter = c.diameter
         quadrature_points = c.quadrature_points
         quadrature_weights = c.quadrature_weights
         del c
     if cell_shape == "POLYHEDRON":
         c = Polyhedron(vertices, connectivity_matrix, quadrature_order)
         centroid = c.centroid
         volume = c.volume
         diameter = c.diameter
         quadrature_points = c.quadrature_points
         quadrature_weights = c.quadrature_weights
         del c
     super().__init__(centroid, volume, diameter, quadrature_points,
                      quadrature_weights)
Beispiel #24
0
def main():
    t1=Triangle()
    print(id(t1))
    is_of_type(t1, Triangle)
    is_of_type(t1, str)
    is_of_type('hello',Triangle)
Beispiel #25
0
def test_squares_equals_area_after_add_area():
    square_1 = Square(4, 2)
    triangle_2 = Triangle(6, 2)
    assert square_1.add_area(triangle_2) == triangle_2.add_area(square_1)
Beispiel #26
0
 def test_triangle(self):
     t = Triangle(3, 2, 3)
     self.assertEqual(t.perimeter(), 8)
     self.assertLess(abs(t.area() - 2.828427), 0.000001)
Beispiel #27
0
def test_rectangles_equals_area_after_add_area():
    rectangle_1 = Rectangle(5, 2)
    triangle_2 = Triangle(6, 3)
    assert rectangle_1.add_area(triangle_2) == triangle_2.add_area(rectangle_1)
Beispiel #28
0
 def test_name(self):
     triangle = Triangle(1, 1, 1)
     assert triangle.name == 'Треугольник_3'
Beispiel #29
0
 def test_add_square(self):
     triangle = Triangle(1, 1, 1)
     print(triangle.area)
     print(self.triangle.area)
     assert self.triangle.add_square(triangle) == sqrt(
         11 * 4 * 1 * 6) + sqrt(1.5 * 0.5 * 0.5 * 0.5)
Beispiel #30
0
 def setup_class(self):
     self.triangle = Triangle(7, 10, 5)