|
1 | 1 | #!/usr/bin/env python |
2 | | -import logging |
3 | | -import unittest |
4 | | -from numpy.testing import assert_array_almost_equal |
5 | | -import subprocess |
6 | | -from pathlib import Path |
| 2 | +from numpy.testing import assert_array_almost_equal,run_module_suite |
7 | 3 | # |
8 | | -from pylineclip import cohensutherland |
| 4 | +import pylineclip as plc |
9 | 5 |
|
10 | | -path=Path(__file__).parents[1] |
11 | 6 |
|
12 | | -class BasicTests(unittest.TestCase): |
13 | | - def test_lineclip(self): |
14 | | - """ |
15 | | - make box with corners LL/UR (1,3) (4,5) |
16 | | - and line segment with ends (0,0) (4,6) |
17 | | - """ |
18 | | - #%% LOWER to UPPER test |
19 | | - x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, |
20 | | - 0, 0, 4, 6) |
| 7 | +def test_lineclip(): |
| 8 | + """ |
| 9 | + make box with corners LL/UR (1,3) (4,5) |
| 10 | + and line segment with ends (0,0) (4,6) |
| 11 | + """ |
| 12 | + #%% LOWER to UPPER test |
| 13 | + x1, y1, x2, y2 = plc.cohensutherland(1, 5, 4, 3, |
| 14 | + 0, 0, 4, 6) |
21 | 15 |
|
22 | | - assert_array_almost_equal([x1,y1,x2,y2],[2, 3, 3.3333333333333,5]) |
23 | | - #%% no intersection test |
24 | | - x1,y1,x2,y2 = cohensutherland(1,5, 4,3, |
25 | | - 0,0.1,0,0.1) |
26 | | - assert x1==y1==x2==y2==None |
27 | | - #%% left to right test |
28 | | - x1,y1,x2,y2 = cohensutherland(1,5,4,3, |
29 | | - 0,4,5,4) |
30 | | - assert_array_almost_equal([x1,y1,x2,y2],[1, 4, 4, 4]) |
| 16 | + assert_array_almost_equal([x1,y1,x2,y2],[2, 3, 3.3333333333333,5]) |
| 17 | + #%% no intersection test |
| 18 | + x1,y1,x2,y2 = plc.cohensutherland(1,5, 4,3, |
| 19 | + 0,0.1,0,0.1) |
| 20 | + assert x1==y1==x2==y2==None |
| 21 | + #%% left to right test |
| 22 | + x1,y1,x2,y2 = plc.cohensutherland(1,5,4,3, |
| 23 | + 0,4,5,4) |
| 24 | + assert_array_almost_equal([x1,y1,x2,y2],[1, 4, 4, 4]) |
31 | 25 |
|
32 | | - def test_fortran_lineclip(self): |
33 | | - |
34 | | - subprocess.check_call([str(path / 'bin/RunLineclip')]) |
35 | 26 |
|
36 | 27 |
|
37 | 28 | if __name__ == '__main__': |
38 | | - unittest.main() |
| 29 | + run_module_suite() |
0 commit comments