1- import unittest
1+ import unittest
2+
23import numpy
4+
35from touchterrain .common .TouchTerrainGPX import plotLineWithThickness
46
57grid_width = 10
810height_offset = 5
911line_height = original_height + height_offset
1012
13+
1114class PlotLineTests (unittest .TestCase ):
1215
1316 def _print_points (self ):
1417 print (self .points )
15-
18+
1619 def _assert_expected_line_points (self , expected_line_points ):
1720 # iterate over the entire grid making sure only the expected line points have the increased height
1821 for x in range (grid_width ):
1922 for y in range (grid_height ):
2023 if [x , y ] in expected_line_points :
21- self .assertEqual (self .points [x ][y ], line_height , "Point [{},{}] expected to be on the line but actually isn't" .format (x , y ))
24+ self .assertEqual (
25+ self .points [x ][y ],
26+ line_height ,
27+ "Point [{},{}] expected to be on the line but actually isn't" .format (
28+ x , y
29+ ),
30+ )
2231 else :
23- self .assertEqual (self .points [x ][y ], original_height , "Point [{},{}] expected not to be on the line but actually is" .format (x , y ))
32+ self .assertEqual (
33+ self .points [x ][y ],
34+ original_height ,
35+ "Point [{},{}] expected not to be on the line but actually is" .format (
36+ x , y
37+ ),
38+ )
2439
2540 def setUp (self ):
26- self .points = numpy .full (shape = (grid_width , grid_height ),fill_value = original_height )
41+ self .points = numpy .full (
42+ shape = (grid_width , grid_height ), fill_value = original_height
43+ )
2744 self .pathed_points = {}
2845
2946 def test_plot_vertical_line_with_zero_thickness (self ):
30- plotLineWithThickness (3 , 2 , 3 , 6 , height_offset , self .points , self .pathed_points , 0 )
47+ plotLineWithThickness (
48+ 3 , 2 , 3 , 6 , height_offset , self .points , self .pathed_points , 0
49+ )
3150 # self._print_points()
32- self ._assert_expected_line_points ([[3 ,2 ], [3 ,3 ], [3 ,4 ], [3 ,5 ], [3 ,6 ]])
51+ self ._assert_expected_line_points ([[3 , 2 ], [3 , 3 ], [3 , 4 ], [3 , 5 ], [3 , 6 ]])
3352
3453 def test_plot_horizontal_line_with_zero_thickness (self ):
35- plotLineWithThickness (2 , 4 , 5 , 4 , height_offset , self .points , self .pathed_points , 0 )
54+ plotLineWithThickness (
55+ 2 , 4 , 5 , 4 , height_offset , self .points , self .pathed_points , 0
56+ )
3657 # self._print_points()
37- self ._assert_expected_line_points ([[2 ,4 ], [3 ,4 ], [4 ,4 ], [5 ,4 ]])
58+ self ._assert_expected_line_points ([[2 , 4 ], [3 , 4 ], [4 , 4 ], [5 , 4 ]])
3859
3960 def test_plot_vertical_line_with_nonzero_thickness (self ):
40- plotLineWithThickness (3 , 2 , 3 , 5 , height_offset , self .points , self .pathed_points , 3 )
61+ plotLineWithThickness (
62+ 3 , 2 , 3 , 5 , height_offset , self .points , self .pathed_points , 3
63+ )
4164 # self._print_points()
42- self ._assert_expected_line_points ([[2 ,2 ], [3 ,2 ], [4 ,2 ], [2 ,3 ], [3 ,3 ], [4 ,3 ], [2 ,4 ], [3 ,4 ], [4 ,4 ], [2 ,5 ], [3 ,5 ], [4 ,5 ]])
65+ self ._assert_expected_line_points (
66+ [
67+ [2 , 2 ],
68+ [3 , 2 ],
69+ [4 , 2 ],
70+ [2 , 3 ],
71+ [3 , 3 ],
72+ [4 , 3 ],
73+ [2 , 4 ],
74+ [3 , 4 ],
75+ [4 , 4 ],
76+ [2 , 5 ],
77+ [3 , 5 ],
78+ [4 , 5 ],
79+ ]
80+ )
4381
4482 def test_plot_horizontal_line_with_nonzero_thickness (self ):
45- plotLineWithThickness (2 , 4 , 6 , 4 , height_offset , self .points , self .pathed_points , 3 )
83+ plotLineWithThickness (
84+ 2 , 4 , 6 , 4 , height_offset , self .points , self .pathed_points , 3
85+ )
4686 # self._print_points()
47- self ._assert_expected_line_points ([[2 ,3 ], [2 ,4 ], [2 ,5 ], [3 ,3 ], [3 ,4 ], [3 ,5 ], [4 ,3 ], [4 ,4 ], [4 ,5 ], [5 ,3 ], [5 ,4 ], [5 ,5 ], [6 ,3 ], [6 ,4 ], [6 ,5 ]])
87+ self ._assert_expected_line_points (
88+ [
89+ [2 , 3 ],
90+ [2 , 4 ],
91+ [2 , 5 ],
92+ [3 , 3 ],
93+ [3 , 4 ],
94+ [3 , 5 ],
95+ [4 , 3 ],
96+ [4 , 4 ],
97+ [4 , 5 ],
98+ [5 , 3 ],
99+ [5 , 4 ],
100+ [5 , 5 ],
101+ [6 , 3 ],
102+ [6 , 4 ],
103+ [6 , 5 ],
104+ ]
105+ )
48106
49107 def test_plot_sw_ne_low_slope_diagonal_line_with_nonzero_thickness (self ):
50- plotLineWithThickness (1 , 3 , 6 , 5 , height_offset , self .points , self .pathed_points , 3 )
108+ plotLineWithThickness (
109+ 1 , 3 , 6 , 5 , height_offset , self .points , self .pathed_points , 3
110+ )
51111 # self._print_points()
52- self ._assert_expected_line_points ([[1 ,2 ], [1 ,3 ], [1 ,4 ], [2 ,2 ], [2 ,3 ], [2 ,4 ], [3 ,3 ], [3 ,4 ], [3 ,5 ], [4 ,3 ], [4 ,4 ], [4 ,5 ], [5 ,4 ], [5 ,5 ], [5 ,6 ], [6 ,4 ], [6 ,5 ], [6 ,6 ]])
112+ self ._assert_expected_line_points (
113+ [
114+ [1 , 2 ],
115+ [1 , 3 ],
116+ [1 , 4 ],
117+ [2 , 2 ],
118+ [2 , 3 ],
119+ [2 , 4 ],
120+ [3 , 3 ],
121+ [3 , 4 ],
122+ [3 , 5 ],
123+ [4 , 3 ],
124+ [4 , 4 ],
125+ [4 , 5 ],
126+ [5 , 4 ],
127+ [5 , 5 ],
128+ [5 , 6 ],
129+ [6 , 4 ],
130+ [6 , 5 ],
131+ [6 , 6 ],
132+ ]
133+ )
53134
54135 def test_plot_se_nw_high_slope_diagonal_line_with_nonzero_thickness (self ):
55- plotLineWithThickness (5 , 6 , 3 , 1 , height_offset , self .points , self .pathed_points , 3 )
136+ plotLineWithThickness (
137+ 5 , 6 , 3 , 1 , height_offset , self .points , self .pathed_points , 3
138+ )
56139 # self._print_points()
57- self ._assert_expected_line_points ([[4 ,6 ], [5 ,6 ], [6 ,6 ], [4 ,5 ], [5 ,5 ], [6 ,5 ], [3 ,4 ], [4 ,4 ], [5 ,4 ], [3 ,3 ], [4 ,3 ], [5 ,3 ], [2 ,2 ], [3 ,2 ], [4 ,2 ], [2 ,1 ], [3 ,1 ], [4 ,1 ]])
140+ self ._assert_expected_line_points (
141+ [
142+ [4 , 6 ],
143+ [5 , 6 ],
144+ [6 , 6 ],
145+ [4 , 5 ],
146+ [5 , 5 ],
147+ [6 , 5 ],
148+ [3 , 4 ],
149+ [4 , 4 ],
150+ [5 , 4 ],
151+ [3 , 3 ],
152+ [4 , 3 ],
153+ [5 , 3 ],
154+ [2 , 2 ],
155+ [3 , 2 ],
156+ [4 , 2 ],
157+ [2 , 1 ],
158+ [3 , 1 ],
159+ [4 , 1 ],
160+ ]
161+ )
58162
59163 def test_plot_line_with_nonzero_thickness_draws_flat_topped_line (self ):
60164 # Set some of the points either side of the centre to be higher - track should not just add the offset to
@@ -64,10 +168,30 @@ def test_plot_line_with_nonzero_thickness_draws_flat_topped_line(self):
64168 self .points [5 ][5 ] = original_height + 3
65169 self .points [5 ][6 ] = original_height + 4
66170
67- plotLineWithThickness (3 , 4 , 5 , 4 , height_offset , self .points , self .pathed_points , 5 )
171+ plotLineWithThickness (
172+ 3 , 4 , 5 , 4 , height_offset , self .points , self .pathed_points , 5
173+ )
68174 # self._print_points()
69- self ._assert_expected_line_points ([[3 ,2 ], [3 ,3 ], [3 ,4 ], [3 ,5 ], [3 ,6 ], [4 ,2 ], [4 ,3 ], [4 ,4 ], [4 ,5 ], [4 ,6 ], [5 ,2 ], [5 ,3 ], [5 ,4 ], [5 ,5 ], [5 ,6 ]])
175+ self ._assert_expected_line_points (
176+ [
177+ [3 , 2 ],
178+ [3 , 3 ],
179+ [3 , 4 ],
180+ [3 , 5 ],
181+ [3 , 6 ],
182+ [4 , 2 ],
183+ [4 , 3 ],
184+ [4 , 4 ],
185+ [4 , 5 ],
186+ [4 , 6 ],
187+ [5 , 2 ],
188+ [5 , 3 ],
189+ [5 , 4 ],
190+ [5 , 5 ],
191+ [5 , 6 ],
192+ ]
193+ )
70194
71195
72- if __name__ == ' __main__' :
196+ if __name__ == " __main__" :
73197 unittest .main (verbosity = 3 )
0 commit comments