-
Notifications
You must be signed in to change notification settings - Fork 13
/
test_bresenham.py
32 lines (27 loc) · 1.51 KB
/
test_bresenham.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pytest
from bresenham import bresenham
@pytest.mark.parametrize(('x0', 'y0', 'x1', 'y1', 'result'), (
(0, 0, 0, 0, ((0, 0), )),
(0, 0, 5, 0, ((0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0))),
(0, 0, -5, 0, ((0, 0), (-1, 0), (-2, 0), (-3, 0), (-4, 0), (-5, 0))),
(0, 0, 0, 5, ((0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5))),
(0, 0, 0, -5, ((0, 0), (0, -1), (0, -2), (0, -3), (0, -4), (0, -5))),
(0, 0, 2, 3, ((0, 0), (1, 1), (1, 2), (2, 3))),
(0, 0, -2, 3, ((0, 0), (-1, 1), (-1, 2), (-2, 3))),
(0, 0, 2, -3, ((0, 0), (1, -1), (1, -2), (2, -3))),
(0, 0, -2, -3, ((0, 0), (-1, -1), (-1, -2), (-2, -3))),
(-1, -3, 3, 3, ((-1, -3), (0, -2), (0, -1),
(1, 0), (2, 1), (2, 2), (3, 3))),
(0, 0, 11, 1, ((0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0),
(6, 1), (7, 1), (8, 1), (9, 1), (10, 1), (11, 1))),
))
def test_bresenham(x0, y0, x1, y1, result):
assert tuple(bresenham(x0, y0, x1, y1)) == result
assert tuple(bresenham(x1, y1, x0, y0)) == tuple(reversed(result))
def test_min_slope_two_way():
assert tuple(bresenham(0, 0, 10, 1)) == ((0, 0), (1, 0), (2, 0), (3, 0),
(4, 0), (5, 1), (6, 1), (7, 1),
(8, 1), (9, 1), (10, 1))
assert tuple(bresenham(10, 1, 0, 0)) == ((10, 1), (9, 1), (8, 1), (7, 1),
(6, 1), (5, 0), (4, 0), (3, 0),
(2, 0), (1, 0), (0, 0))