|
1 | | -import compas |
2 | | -import pytest |
3 | | -from compas.geometry import Polyline, Point |
4 | 1 | import math |
| 2 | +import pytest |
| 3 | + |
| 4 | +from compas.geometry import Point |
| 5 | +from compas.geometry import Polyline |
| 6 | +from compas.utilities import pairwise |
| 7 | + |
| 8 | + |
| 9 | +def test_polyline(): |
| 10 | + points = [[0, 0, x] for x in range(5)] |
| 11 | + polyline = Polyline(points) |
| 12 | + assert polyline.points == points |
| 13 | + assert polyline.lines == [(a, b) for a, b in pairwise(points)] |
| 14 | + |
| 15 | + |
| 16 | +def test_equality(): |
| 17 | + points1 = [[0, 0, x] for x in range(5)] |
| 18 | + polyline1 = Polyline(points1) |
| 19 | + points2 = [[0, 0, x] for x in range(6)] |
| 20 | + polyline2 = Polyline(points2) |
| 21 | + assert polyline1 == polyline1 |
| 22 | + assert polyline1 == points1 |
| 23 | + assert points1 == polyline1 |
| 24 | + assert polyline1 != polyline2 |
| 25 | + assert polyline2 != polyline1 |
| 26 | + assert polyline1 != points2 |
| 27 | + assert points2 != polyline1 |
| 28 | + assert polyline1 != 1 |
| 29 | + |
| 30 | + |
| 31 | +def test___repr__(): |
| 32 | + points = [[0, 0, x] for x in range(5)] |
| 33 | + polyline = Polyline(points) |
| 34 | + assert polyline == eval(repr(polyline)) |
| 35 | + |
| 36 | + |
| 37 | +def test___getitem__(): |
| 38 | + points = [[0, 0, x] for x in range(5)] |
| 39 | + polyline = Polyline(points) |
| 40 | + for x in range(5): |
| 41 | + assert polyline[x] == [0, 0, x] |
| 42 | + with pytest.raises(IndexError): |
| 43 | + polyline[6] = [0, 0, 6] |
| 44 | + |
| 45 | + |
| 46 | +def test___setitem__(): |
| 47 | + points = [[0, 0, x] for x in range(5)] |
| 48 | + polyline = Polyline(points) |
| 49 | + point = [1, 1, 4] |
| 50 | + polyline[4] = point |
| 51 | + assert polyline[4] == point |
| 52 | + assert isinstance(polyline[4], Point) |
| 53 | + assert polyline.lines[-1].end == point |
5 | 54 |
|
6 | 55 |
|
7 | 56 | @pytest.mark.parametrize('coords,expected', [ |
|
0 commit comments