MediaWiki REL1_32
ArrayUtilsTest.php
Go to the documentation of this file.
1<?php
7class ArrayUtilsTest extends PHPUnit\Framework\TestCase {
8
9 use MediaWikiCoversValidator;
10
16 $valueCallback, $valueCount, $comparisonCallback, $target, $expected
17 ) {
18 $this->assertSame(
19 ArrayUtils::findLowerBound(
20 $valueCallback, $valueCount, $comparisonCallback, $target
21 ), $expected
22 );
23 }
24
26 $indexValueCallback = function ( $size ) {
27 return function ( $val ) use ( $size ) {
28 $this->assertTrue( $val >= 0 );
29 $this->assertTrue( $val < $size );
30 return $val;
31 };
32 };
33 $comparisonCallback = function ( $a, $b ) {
34 return $a - $b;
35 };
36
37 return [
38 [
39 $indexValueCallback( 0 ),
40 0,
41 $comparisonCallback,
42 1,
43 false,
44 ],
45 [
46 $indexValueCallback( 1 ),
47 1,
48 $comparisonCallback,
49 -1,
50 false,
51 ],
52 [
53 $indexValueCallback( 1 ),
54 1,
55 $comparisonCallback,
56 0,
57 0,
58 ],
59 [
60 $indexValueCallback( 1 ),
61 1,
62 $comparisonCallback,
63 1,
64 0,
65 ],
66 [
67 $indexValueCallback( 2 ),
68 2,
69 $comparisonCallback,
70 -1,
71 false,
72 ],
73 [
74 $indexValueCallback( 2 ),
75 2,
76 $comparisonCallback,
77 0,
78 0,
79 ],
80 [
81 $indexValueCallback( 2 ),
82 2,
83 $comparisonCallback,
84 0.5,
85 0,
86 ],
87 [
88 $indexValueCallback( 2 ),
89 2,
90 $comparisonCallback,
91 1,
92 1,
93 ],
94 [
95 $indexValueCallback( 2 ),
96 2,
97 $comparisonCallback,
98 1.5,
99 1,
100 ],
101 [
102 $indexValueCallback( 3 ),
103 3,
104 $comparisonCallback,
105 1,
106 1,
107 ],
108 [
109 $indexValueCallback( 3 ),
110 3,
111 $comparisonCallback,
112 1.5,
113 1,
114 ],
115 [
116 $indexValueCallback( 3 ),
117 3,
118 $comparisonCallback,
119 2,
120 2,
121 ],
122 [
123 $indexValueCallback( 3 ),
124 3,
125 $comparisonCallback,
126 3,
127 2,
128 ],
129 ];
130 }
131
136 function testArrayDiffAssocRecursive( $expected ) {
137 $args = func_get_args();
138 array_shift( $args );
139 $this->assertEquals( call_user_func_array(
140 'ArrayUtils::arrayDiffAssocRecursive', $args
141 ), $expected );
142 }
143
145 return [
146 [
147 [],
148 [],
149 [],
150 ],
151 [
152 [],
153 [],
154 [],
155 [],
156 ],
157 [
158 [ 1 ],
159 [ 1 ],
160 [],
161 ],
162 [
163 [ 1 ],
164 [ 1 ],
165 [],
166 [],
167 ],
168 [
169 [],
170 [],
171 [ 1 ],
172 ],
173 [
174 [],
175 [],
176 [ 1 ],
177 [ 2 ],
178 ],
179 [
180 [ '' => 1 ],
181 [ '' => 1 ],
182 [],
183 ],
184 [
185 [],
186 [],
187 [ '' => 1 ],
188 ],
189 [
190 [ 1 ],
191 [ 1 ],
192 [ 2 ],
193 ],
194 [
195 [],
196 [ 1 ],
197 [ 2 ],
198 [ 1 ],
199 ],
200 [
201 [],
202 [ 1 ],
203 [ 1, 2 ],
204 ],
205 [
206 [ 1 => 1 ],
207 [ 1 => 1 ],
208 [ 1 ],
209 ],
210 [
211 [],
212 [ 1 => 1 ],
213 [ 1 ],
214 [ 1 => 1 ],
215 ],
216 [
217 [],
218 [ 1 => 1 ],
219 [ 1, 1, 1 ],
220 ],
221 [
222 [],
223 [ [] ],
224 [],
225 ],
226 [
227 [],
228 [ [ [] ] ],
229 [],
230 ],
231 [
232 [ 1, [ 1 ] ],
233 [ 1, [ 1 ] ],
234 [],
235 ],
236 [
237 [ 1 ],
238 [ 1, [ 1 ] ],
239 [ 2, [ 1 ] ],
240 ],
241 [
242 [],
243 [ 1, [ 1 ] ],
244 [ 2, [ 1 ] ],
245 [ 1, [ 2 ] ],
246 ],
247 [
248 [ 1 ],
249 [ 1, [] ],
250 [ 2 ],
251 ],
252 [
253 [],
254 [ 1, [] ],
255 [ 2 ],
256 [ 1 ],
257 ],
258 [
259 [ 1, [ 1 => 2 ] ],
260 [ 1, [ 1, 2 ] ],
261 [ 2, [ 1 ] ],
262 ],
263 [
264 [ 1 ],
265 [ 1, [ 1, 2 ] ],
266 [ 2, [ 1 ] ],
267 [ 2, [ 1 => 2 ] ],
268 ],
269 [
270 [ 1 => [ 1, 2 ] ],
271 [ 1, [ 1, 2 ] ],
272 [ 1, [ 2 ] ],
273 ],
274 [
275 [ 1 => [ [ 2, 3 ], 2 ] ],
276 [ 1, [ [ 2, 3 ], 2 ] ],
277 [ 1, [ 2 ] ],
278 ],
279 [
280 [ 1 => [ [ 2 ], 2 ] ],
281 [ 1, [ [ 2, 3 ], 2 ] ],
282 [ 1, [ [ 1 => 3 ] ] ],
283 ],
284 [
285 [ 1 => [ 1 => 2 ] ],
286 [ 1, [ [ 2, 3 ], 2 ] ],
287 [ 1, [ [ 1 => 3, 0 => 2 ] ] ],
288 ],
289 [
290 [ 1 => [ 1 => 2 ] ],
291 [ 1, [ [ 2, 3 ], 2 ] ],
292 [ 1, [ [ 1 => 3 ] ] ],
293 [ 1 => [ [ 2 ] ] ],
294 ],
295 [
296 [],
297 [ 1, [ [ 2, 3 ], 2 ] ],
298 [ 1 => [ 1 => 2, 0 => [ 1 => 3, 0 => 2 ] ], 0 => 1 ],
299 ],
300 [
301 [],
302 [ 1, [ [ 2, 3 ], 2 ] ],
303 [ 1 => [ 1 => 2 ] ],
304 [ 1 => [ [ 1 => 3 ] ] ],
305 [ 1 => [ [ 2 ] ] ],
306 [ 1 ],
307 ],
308 ];
309 }
310}
if( $line===false) $args
Definition cdb.php:64
Test class for ArrayUtils class.
testFindLowerBound( $valueCallback, $valueCount, $comparisonCallback, $target, $expected)
ArrayUtils::findLowerBound provideFindLowerBound.
testArrayDiffAssocRecursive( $expected)
ArrayUtils::arrayDiffAssocRecursive provideArrayDiffAssocRecursive.