コード例 #1
0
def test_dividing_points():
    """Check Points dividing LineSegment."""
    AB = LineSegment(Point(0, 0, 'A'), Point(5, 0, 'B'))
    p = AB.dividing_points(n=4)
    assert p == [
        Point(Number('1.25'), 0, 'a1'),
        Point(Number('2.5'), 0, 'a2'),
        Point(Number('3.75'), 0, 'a3')
    ]
    AB = LineSegment(Point(0, 0, 'A'), Point(0, 5, 'B'))
    p = AB.dividing_points(n=4)
    assert p == [
        Point(0, Number('1.25'), 'a1'),
        Point(0, Number('2.5'), 'a2'),
        Point(0, Number('3.75'), 'a3')
    ]
    AB = LineSegment(Point(0, 0, 'A'), Point(5, 5, 'B'))
    p = AB.dividing_points(n=4)
    assert p == [
        Point(Number('1.25'), Number('1.25'), 'a1'),
        Point(Number('2.5'), Number('2.5'), 'a2'),
        Point(Number('3.75'), Number('3.75'), 'a3')
    ]
    p = AB.dividing_points(n=1)
    assert p == []
    with pytest.raises(TypeError):
        p = AB.dividing_points(n='4')
    with pytest.raises(ValueError):
        p = AB.dividing_points(n=0)
コード例 #2
0
def test_dividing_points_errors(A, B):
    """Check LineSegment's instanciation exceptions."""
    AB = LineSegment(Point(0, 0, 'A'), Point(5, 0, 'B'))
    with pytest.raises(TypeError) as excinfo:
        AB.dividing_points(n=7.5)
    assert str(excinfo.value) == 'n must be an integer'