1 ! Copyright (C) 2017 Alexander Ilin.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math math.ratios sequences tools.test
4 ui.gadgets.charts.lines ui.gadgets.charts.lines.private
5 ui.gadgets.charts.utils ;
6 IN: ui.gadgets.charts.lines.tests
8 { -2/3 } [ { 1 3 } { -2 5 } calc-line-slope ] unit-test
9 [ { 5 0 } { 5 5 } calc-line-slope ] [ division-by-zero? ] must-fail-with
10 { 3 } [ -2/3 1 { 1 3 } calc-y ] unit-test
11 { 5 } [ -2/3 -2 { 1 3 } calc-y ] unit-test
12 { 3 } [ -2/3 1 { -2 5 } calc-y ] unit-test
13 { 5 } [ -2/3 -2 { -2 5 } calc-y ] unit-test
14 { 5 } [ -2 { 1 3 } { -2 5 } y-at ] unit-test
15 { 3 } [ 1 { 1 3 } { -2 5 } y-at ] unit-test
16 { 1 } [ 4 { -2 5 } { 1 3 } y-at ] unit-test
17 { 0.0 } [ 5.5 { -2 5 } { 1 3 } y-at ] unit-test
18 { 1 } [ -2/3 3 { 1 3 } calc-x ] unit-test
19 { -2 } [ -2/3 5 { 1 3 } calc-x ] unit-test
20 { 1 } [ -2/3 3 { -2 5 } calc-x ] unit-test
21 { -2 } [ -2/3 5 { -2 5 } calc-x ] unit-test
23 { 2 3 } [ { 1 2 3 } last2 ] unit-test
24 { 1 2 } [ { 1 2 } last2 ] unit-test
25 [ { 1 } last2 ] must-fail
26 [ { } last2 ] must-fail
28 ! 2-point-chunk upwards
32 { { -6 0 } { -5 -5 } } { { 5 5 } { 6 0 } }
36 ! 2-point-chunk downwards
40 { { -6 0 } { -5 5 } } { { 5 -5 } { 6 0 } }
44 ! 2-point-chunk: same x coord
46 { { -5 -3 } { -5 3 } }
48 { { -6 0 } { -5 -5 } } { { -5 5 } { 6 0 } }
52 ! fix-left-chunk: y coord = top limit
56 { { -6 0 } { -3 3 } } { { 5 5 } { 6 6 } }
60 ! fix-left-chunk: y coord = bottom limit
62 { { -6 0 } { -3 -3 } }
64 { { -6 0 } { -3 -3 } } { { 5 -5 } { 6 -6 } }
68 ! fix-left-chunk: going upwards
70 { { -6 0 } { 2 2 } { 3 3 } }
72 { { -6 0 } { 2 2 } } { { 5 5 } { 6 6 } }
76 ! fix-left-chunk: going downwards
78 { { -6 0 } { -2 -2 } { -1 -3 } }
80 { { -6 0 } { -2 -2 } } { { 0 -4 } { 6 -6 } }
84 ! TODO: add more tests for the recently discovered bugs in fix-left-chunk and fix-right-chunk
86 ! fix-right-chunk: y coord = top limit
90 { { -6 6 } { -3 4 } } { { 5 3 } { 6 0 } }
94 ! fix-right-chunk: y coord = bottom limit
98 { { -6 -6 } { -3 -4 } } { { 5 -3 } { 6 0 } }
102 ! fix-right-chunk: going upwards
104 { { -3 -3 } { -2 -2 } { 6 0 } }
106 { { -6 -6 } { -4 -4 } } { { -2 -2 } { 6 0 } }
110 ! fix-right-chunk: going downwards
112 { { -3 3 } { -2 2 } { 6 0 } }
114 { { -6 6 } { -4 4 } } { { -2 2 } { 6 0 } }
120 { { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } }
122 { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { 0 5 }
123 drawable-chunks [ { } like ] map
128 { { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } }
130 { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { -1 6 }
131 drawable-chunks [ { } like ] map
134 ! only bottom element accepted
138 { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { -1 0 }
139 drawable-chunks [ { } like ] map
142 ! only top element accepted
146 { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { 5 10 }
147 drawable-chunks [ { } like ] map
150 ! top half of the elements accepted
152 { { { 1 2 } { 1 3 } { 2 5 } } }
154 { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { 2 10 }
155 drawable-chunks [ { } like ] map
158 ! bottom half of the elements accepted
160 { { { 0 0 } { 0 1 } { 1 2 } } }
162 { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { -2 2 }
163 drawable-chunks [ { } like ] map
166 ! middle section of the elements accepted
168 { { { 0 1 } { 1 2 } { 1 3 } } }
170 { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { 1 3 }
171 drawable-chunks [ { } like ] map
174 ! two sections, including first but not last
177 { { 0 0 } { 1 2 } { 2 3 } }
178 { { 5 3 } { 6 2 } { 7 0 } }
181 { { 0 0 } { 1 2 } { 2 3 } { 3 5 } { 4 5 } { 5 3 } { 6 2 } { 7 0 } { 8 -1 } { 9 -2 } } { 0 3 }
182 drawable-chunks [ { } like ] map
185 ! two sections, including last but not first
188 { { 2 0 } { 3 3 } { 4 3 } }
189 { { 7 3 } { 8 2 } { 9 0 } }
192 { { 0 -2 } { 1 -1 } { 2 0 } { 3 3 } { 4 3 } { 5 5 } { 6 9 } { 7 3 } { 8 2 } { 9 0 } } { 0 3 }
193 drawable-chunks [ { } like ] map
196 ! single-element sequences, same x coord
203 { { 0 -2 } { 0 0 } { 0 5 } { 0 3 } { 0 -1 } } { 0 3 }
204 drawable-chunks [ { } like ] map
207 ! single point sticks out to within the limits from below
210 { { 1 1 } { 2 2 } { 3 1 } }
213 { { 0 0 } { 2 2 } { 4 0 } } { 1 5 }
214 drawable-chunks [ { } like ] map
217 ! single point sticks out to within the limits from above
220 { { 1 3 } { 2 2 } { 3 3 } }
223 { { 0 4 } { 2 2 } { 4 4 } } { 1 3 }
224 drawable-chunks [ { } like ] map
228 { { { 0 300 } { 1 200 } { 2 150 } { 3 100 } { 4 0 } } }
230 { { { 0 0 } { 1 100 } { 2 150 } { 3 200 } { 4 300 } } }
231 { 0 300 } flip-y-axis
235 { 0 30 60 90 120 150 180 210 240 270 300 }
237 11 iota [ 10 + ] map [ 300 swap 20 10 scale ] map
241 [ { } { } clip-data ] unit-test
244 [ { { 0 1 } { 0 5 } } { } clip-data ] unit-test
246 ! Adjustment after search is required in both directions.
249 { 1 3 } { 1 4 } { 1 5 }
250 { 2 6 } { 3 7 } { 4 8 }
251 { 5 9 } { 5 10 } { 5 11 } { 5 12 }
257 { 1 3 } { 1 4 } { 1 5 }
258 { 2 6 } { 3 7 } { 4 8 }
259 { 5 9 } { 5 10 } { 5 11 } { 5 12 }
264 ! no points within the viewport, complete calculation
269 { { 0 0 } { 5 5 } } clip-data
272 ! no points within the viewport, complete calculation
277 { { 0 5 } { 5 0 } } clip-data
280 ! no points within the viewport, complete calculation
285 { { 0 3 } { 5 3 } } clip-data
288 ! all data are to the left of viewport
293 { { -1 0 } { 0 1 } { 0.5 1 } } clip-data
296 ! all data are to the right of viewport
301 { { 4.5 0 } { 5 1 } { 6 1 } } clip-data
304 ! just a little off the top
307 { { 0 100 } { 100 0 } { 100 50 } { 150 50 } { 200 100 } }
311 ! TODO: add tests where after search there is no adjustment necessary, so that extra adjustment would take bad elements.