Esempio n. 1
0
def test_sum_with_incorrect_class(sides, fixture_incorrect_type,
                                  fixture_test_class):
    a, b, c = sides
    triangle = Triangle(a, b, c)
    print(fixture_test_class)
    with pytest.raises(TypeError) as excinfo:
        triangle.add_square(fixture_test_class())
        del triangle
    assert str(excinfo.value) == fixture_incorrect_type
Esempio n. 2
0
    square = Square(sides)
    assert square.perimeter == perimeter
    del square


@pytest.mark.parametrize("sides, area", [((2, 2, 2, 2), 4),
                                         ((2.3, 2.3, 2.3, 2.3), 5.3)])
def test_area(sides, area):
    a, b, c, d = sides
    square = Square(a, b, c, d)
    assert square.area == area
    del square


@pytest.mark.parametrize("sides, class_to_sum, result_sum",
                         [(2, Triangle(2, 3, 4), 6.9),
                          (2, Rectangle(1, 2, 1, 2), 6), (2, Circle(4), 16.6)])
def test_sum_areas(sides, class_to_sum, result_sum):
    square = Square(sides)
    assert square.add_square(class_to_sum) == result_sum
    del square


@pytest.mark.parametrize("sides", [(-2, 2, 2, 2), (2, -2, 2, 2), (2, 2, -2, 2),
                                   (2, 2, 2, -2), (0, 2, 2, 2), (2, 0, 2, 2),
                                   (2, 2, 0, 2), (2, 2, 2, 0)])
def test_negative_value_of_side(sides, fixture_negative_side):
    a, b, c, d = sides
    with pytest.raises(ValueError) as excinfo:
        square = Square(a, b, c, d)
        del square
Esempio n. 3
0
def test_angles():
    assert Triangle(2, 3, 4).angles == 3
Esempio n. 4
0
def test_negative_value_of_side(sides, fixture_negative_side):
    a, b, c = sides
    with pytest.raises(ValueError) as excinfo:
        triangle = Triangle(a, b, c)
        del triangle
    assert str(excinfo.value) == fixture_negative_side
Esempio n. 5
0
def test_not_triangle(sides, fixture_triangle_not_exists):
    a, b, c = sides
    with pytest.raises(ValueError) as excinfo:
        triangle = Triangle(a, b, c)
        del triangle
    assert str(excinfo.value) == fixture_triangle_not_exists
Esempio n. 6
0
def test_area(sides, area):
    a, b, c = sides
    triangle = Triangle(a, b, c)
    assert triangle.area == area
    del triangle
Esempio n. 7
0
def test_sum_areas(sides, class_to_sum, result_sum):
    a, b, c = sides
    triangle = Triangle(a, b, c)
    assert triangle.add_square(class_to_sum) == result_sum
    del triangle
Esempio n. 8
0
def test_perimeter(sides, perimeter):
    a, b, c = sides
    triangle = Triangle(a, b, c)
    assert triangle.perimeter == perimeter
    del triangle
Esempio n. 9
0
def test_name():
    assert Triangle(2, 3, 4).name == "Triangle"
Esempio n. 10
0
def test_isosceles_triangle(fixture_triangle_isosceles):
    a, b, c = fixture_triangle_isosceles
    triangle = Triangle(a, b, c)
    assert triangle.check_type_of_triangle() == "Isosceles"
    del triangle
Esempio n. 11
0
def test_equilateral_triangle(fixture_triangle_equilateral):
    a, b, c = fixture_triangle_equilateral
    triangle = Triangle(a, b, c)
    assert triangle.check_type_of_triangle() == "Equilateral"
    del triangle
Esempio n. 12
0
def test_scalene_triangle(fixture_triangle_scalene):
    a, b, c = fixture_triangle_scalene
    triangle = Triangle(a, b, c)
    assert triangle.check_type_of_triangle() == "Scalene"
    del triangle
Esempio n. 13
0
@pytest.mark.parametrize("diameter, length", [(4, 12.6), (4.2, 13.2)])
def test_perimeter(diameter, length):
    circle = Circle(diameter)
    assert circle.perimeter == length
    del circle


@pytest.mark.parametrize("diameter, area", [(4, 12.6), (2.34, 4.3)])
def test_area(diameter, area):
    circle = Circle(diameter)
    assert circle.area == area
    del circle


@pytest.mark.parametrize("diameter, class_to_sum, result_sum",
                         [(4, Triangle(2, 3, 4), 15.5),
                          (4, Rectangle(1, 2, 1, 2), 14.6),
                          (4, Square(4), 28.6)])
def test_sum_areas(diameter, class_to_sum, result_sum):
    circle = Circle(diameter)
    assert circle.add_square(class_to_sum) == result_sum
    del circle


@pytest.mark.parametrize("diameter", [-2, 0])
def test_negative_value_of_side(diameter, fixture_negative_side):
    with pytest.raises(ValueError) as excinfo:
        circle = Circle(diameter)
        del circle
    assert str(excinfo.value) == fixture_negative_side
Esempio n. 14
0
    rectangle = Rectangle(a, b, c, d)
    assert rectangle.perimeter == perimeter
    del rectangle


@pytest.mark.parametrize("sides, area", [((2, 3, 2, 3), 6),
                                         ((2.3, 2.4, 2.4, 2.3), 5.5)])
def test_area(sides, area):
    a, b, c, d = sides
    rectangle = Rectangle(a, b, c, d)
    assert rectangle.area == area
    del rectangle


@pytest.mark.parametrize("sides, class_to_sum, result_sum",
                         [((1, 2, 1, 2), Triangle(2, 3, 4), 4.9),
                          ((1, 2, 1, 2), Square(2), 6),
                          ((1, 2, 1, 2), Circle(4), 14.6)])
def test_sum_areas(sides, class_to_sum, result_sum):
    a, b, c, d = sides
    rectangle = Rectangle(a, b, c, d)
    assert rectangle.add_square(class_to_sum) == result_sum
    del rectangle


@pytest.mark.parametrize("sides", [(-2, 3, 2, 3), (2, -3, 2, 3), (2, 3, -2, 3),
                                   (2, 3, 2, -3), (0, 2, 3, 4), (2, 0, 4, 1),
                                   (2, 3, 0, 1), (2, 3, 2, 0)])
def test_negative_value_of_side(sides, fixture_negative_side):
    a, b, c, d = sides
    with pytest.raises(ValueError) as excinfo: