]> gitweb.factorcode.org Git - factor.git/blob - extra/ui/gadgets/charts/lines/lines-tests.factor
extra: remove some unneeded IN: in -tests.
[factor.git] / extra / ui / gadgets / charts / lines / lines-tests.factor
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
7 { -2/3 } [ { 1 3 } { -2 5 } calc-line-slope ] unit-test
8 [ { 5 0 } { 5 5 } calc-line-slope ] [ division-by-zero? ] must-fail-with
9 { 3 } [ -2/3 1 { 1 3 } calc-y ] unit-test
10 { 5 } [ -2/3 -2 { 1 3 } calc-y ] unit-test
11 { 3 } [ -2/3 1 { -2 5 } calc-y ] unit-test
12 { 5 } [ -2/3 -2 { -2 5 } calc-y ] unit-test
13 { 5 } [ -2 { 1 3 } { -2 5 } y-at ] unit-test
14 { 3 } [ 1 { 1 3 } { -2 5 } y-at ] unit-test
15 { 1 } [ 4 { -2 5 } { 1 3 } y-at ] unit-test
16 { 0.0 } [ 5.5 { -2 5 } { 1 3 } y-at ] unit-test
17 { 1 } [ -2/3 3 { 1 3 } calc-x ] unit-test
18 { -2 } [ -2/3 5 { 1 3 } calc-x ] unit-test
19 { 1 } [ -2/3 3 { -2 5 } calc-x ] unit-test
20 { -2 } [ -2/3 5 { -2 5 } calc-x ] unit-test
21
22 { 2 3 } [ { 1 2 3 } last2 ] unit-test
23 { 1 2 } [ { 1 2 } last2 ] unit-test
24 [ { 1 } last2 ] must-fail
25 [ { } last2 ] must-fail
26
27 ! 2-point-chunk upwards
28 {
29     { { -3 -3 } { 3 3 } }
30 } [
31     { { -6 0 } { -5 -5 } } { { 5 5 } { 6 0 } }
32     -3 3 2-point-chunk
33 ] unit-test
34
35 ! 2-point-chunk downwards
36 {
37     { { -3 3 } { 3 -3 } }
38 } [
39     { { -6 0 } { -5 5 } } { { 5 -5 } { 6 0 } }
40     -3 3 2-point-chunk
41 ] unit-test
42
43 ! 2-point-chunk: same x coord
44 {
45     { { -5 -3 } { -5 3 } }
46 } [
47     { { -6 0 } { -5 -5 } } { { -5 5 } { 6 0 } }
48     -3 3 2-point-chunk
49 ] unit-test
50
51 ! fix-left-chunk: y coord = top limit
52 {
53     { { -6 0 } { -3 3 } }
54 } [
55     { { -6 0 } { -3 3 } } { { 5 5 } { 6 6 } }
56     -3 3 fix-left-chunk
57 ] unit-test
58
59 ! fix-left-chunk: y coord = bottom limit
60 {
61     { { -6 0 } { -3 -3 } }
62 } [
63     { { -6 0 } { -3 -3 } } { { 5 -5 } { 6 -6 } }
64     -3 3 fix-left-chunk
65 ] unit-test
66
67 ! fix-left-chunk: going upwards
68 {
69     { { -6 0 } { 2 2 } { 3 3 } }
70 } [
71     { { -6 0 } { 2 2 } } { { 5 5 } { 6 6 } }
72     -3 3 fix-left-chunk
73 ] unit-test
74
75 ! fix-left-chunk: going downwards
76 {
77     { { -6 0 } { -2 -2 } { -1 -3 } }
78 } [
79     { { -6 0 } { -2 -2 } } { { 0 -4 } { 6 -6 } }
80     -3 3 fix-left-chunk
81 ] unit-test
82
83 ! TODO: add more tests for the recently discovered bugs in fix-left-chunk and fix-right-chunk
84
85 ! fix-right-chunk: y coord = top limit
86 {
87     { { 5 3 } { 6 0 } }
88 } [
89     { { -6 6 } { -3 4 } } { { 5 3 } { 6 0 } }
90     -3 3 fix-right-chunk
91 ] unit-test
92
93 ! fix-right-chunk: y coord = bottom limit
94 {
95     { { 5 -3 } { 6 0 } }
96 } [
97     { { -6 -6 } { -3 -4 } } { { 5 -3 } { 6 0 } }
98     -3 3 fix-right-chunk
99 ] unit-test
100
101 ! fix-right-chunk: going upwards
102 {
103     { { -3 -3 } { -2 -2 } { 6 0 } }
104 } [
105     { { -6 -6 } { -4 -4 } } { { -2 -2 } { 6 0 } }
106     -3 3 fix-right-chunk
107 ] unit-test
108
109 ! fix-right-chunk: going downwards
110 {
111     { { -3 3 } { -2 2 } { 6 0 } }
112 } [
113     { { -6 6 } { -4 4 } } { { -2 2 } { 6 0 } }
114     -3 3 fix-right-chunk
115 ] unit-test
116
117 ! tight bounds
118 {
119     { { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } }
120 } [
121     { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { 0 5 }
122     drawable-chunks [ { } like ] map
123 ] unit-test
124
125 ! loose bounds
126 {
127     { { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } }
128 } [
129     { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { -1 6 }
130     drawable-chunks [ { } like ] map
131 ] unit-test
132
133 ! only bottom element accepted
134 {
135     { { { 0 0 } } }
136 } [
137     { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { -1 0 }
138     drawable-chunks [ { } like ] map
139 ] unit-test
140
141 ! only top element accepted
142 {
143     { { { 2 5 } } }
144 } [
145     { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { 5 10 }
146     drawable-chunks [ { } like ] map
147 ] unit-test
148
149 ! top half of the elements accepted
150 {
151     { { { 1 2 } { 1 3 } { 2 5 } } }
152 } [
153     { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { 2 10 }
154     drawable-chunks [ { } like ] map
155 ] unit-test
156
157 ! bottom half of the elements accepted
158 {
159     { { { 0 0 } { 0 1 } { 1 2 } } }
160 } [
161     { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { -2 2 }
162     drawable-chunks [ { } like ] map
163 ] unit-test
164
165 ! middle section of the elements accepted
166 {
167     { { { 0 1 } { 1 2 } { 1 3 } } }
168 } [
169     { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { 1 3 }
170     drawable-chunks [ { } like ] map
171 ] unit-test
172
173 ! two sections, including first but not last
174 {
175     {
176         { { 0 0 } { 1 2 } { 2 3 } }
177         { { 5 3 } { 6 2 } { 7 0 } }
178     }
179 } [
180     { { 0 0 } { 1 2 } { 2 3 } { 3 5 } { 4 5 } { 5 3 } { 6 2 } { 7 0 } { 8 -1 } { 9 -2 } } { 0 3 }
181     drawable-chunks [ { } like ] map
182 ] unit-test
183
184 ! two sections, including last but not first
185 {
186     {
187         { { 2 0 } { 3 3 } { 4 3 } }
188         { { 7 3 } { 8 2 } { 9 0 } }
189     }
190 } [
191     { { 0 -2 } { 1 -1 } { 2 0 } { 3 3 } { 4 3 } { 5 5 } { 6 9 } { 7 3 } { 8 2 } { 9 0 } } { 0 3 }
192     drawable-chunks [ { } like ] map
193 ] unit-test
194
195 ! single-element sequences, same x coord
196 {
197     {
198         { { 0 0 } { 0 3 } }
199         { { 0 3 } { 0 0 } }
200     }
201 } [
202     { { 0 -2 } { 0 0 } { 0 5 } { 0 3 } { 0 -1 } } { 0 3 }
203     drawable-chunks [ { } like ] map
204 ] unit-test
205
206 ! single point sticks out to within the limits from below
207 {
208     {
209         { { 1 1 } { 2 2 } { 3 1 } }
210     }
211 } [
212     { { 0 0 } { 2 2 } { 4 0 } } { 1 5 }
213     drawable-chunks [ { } like ] map
214 ] unit-test
215
216 ! single point sticks out to within the limits from above
217 {
218     {
219         { { 1 3 } { 2 2 } { 3 3 } }
220     }
221 } [
222     { { 0 4 } { 2 2 } { 4 4 } } { 1 3 }
223     drawable-chunks [ { } like ] map
224 ] unit-test
225
226 {
227     { { { 0 300 } { 1 200 } { 2 150 } { 3 100 } { 4 0 } } }
228 } [
229     { { { 0 0 } { 1 100 } { 2 150 } { 3 200 } { 4 300 } } }
230     { 0 300 } flip-y-axis
231 ] unit-test
232
233 {
234     { 0 30 60 90 120 150 180 210 240 270 300 }
235 } [
236     11 <iota> [ 10 + ] map [ 300 swap 20 10 scale ] map
237 ] unit-test
238
239 { { } }
240 [ { } { } clip-data ] unit-test
241
242 { { } }
243 [ { { 0 1 } { 0 5 } } { } clip-data ] unit-test
244
245 ! Adjustment after search is required in both directions.
246 {
247     {
248         { 1 3 } { 1 4 } { 1 5 }
249         { 2 6 } { 3 7 } { 4 8 }
250         { 5 9 } { 5 10 } { 5 11 } { 5 12 }
251     }
252 } [
253     { { 1 5 } { 0 14 } }
254     {
255         { 0 1 } { 0 2 }
256         { 1 3 } { 1 4 } { 1 5 }
257         { 2 6 } { 3 7 } { 4 8 }
258         { 5 9 } { 5 10 } { 5 11 } { 5 12 }
259         { 6 13 } { 7 14 }
260     } clip-data
261 ] unit-test
262
263 ! no points within the viewport, complete calculation
264 {
265     { { 1 1 } { 4 4 } }
266 } [
267     { { 1 4 } { 1 4 } }
268     { { 0 0 } { 5 5 } } clip-data
269 ] unit-test
270
271 ! no points within the viewport, complete calculation
272 {
273     { { 1 4 } { 4 1 } }
274 } [
275     { { 1 4 } { 1 4 } }
276     { { 0 5 } { 5 0 } } clip-data
277 ] unit-test
278
279 ! no points within the viewport, complete calculation
280 {
281     { { 1 3 } { 4 3 } }
282 } [
283     { { 1 4 } { 1 4 } }
284     { { 0 3 } { 5 3 } } clip-data
285 ] unit-test
286
287 ! all data are to the left of viewport
288 {
289     { }
290 } [
291     { { 1 4 } { 1 4 } }
292     { { -1 0 } { 0 1 } { 0.5 1 } } clip-data
293 ] unit-test
294
295 ! all data are to the right of viewport
296 {
297     { }
298 } [
299     { { 1 4 } { 1 4 } }
300     { { 4.5 0 } { 5 1 } { 6 1 } } clip-data
301 ] unit-test
302
303 ! just a little off the top
304 { t } [
305     { 0 99 }
306     { { 0 100 } { 100 0 } { 100 50 } { 150 50 } { 200 100 } }
307     y-in-bounds?
308 ] unit-test
309
310 ! TODO: add tests where after search there is no adjustment necessary, so that extra adjustment would take bad elements.