[go: nahoru, domu]

blob: cd430c90def78df8e8371f5a61fb31df06442d04 [file] [log] [blame]
George Mountfa688412023-08-31 09:01:24 -07001/*
2 * Copyright 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package androidx.collection
17
18import kotlin.test.Test
19import kotlin.test.assertEquals
20import kotlin.test.assertFailsWith
21import kotlin.test.assertFalse
22import kotlin.test.assertNotEquals
23import kotlin.test.assertTrue
24
25// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
26// DO NOT MAKE CHANGES to the kotlin source file.
27//
28// This file was generated from a template in the template directory.
29// Make a change to the original template and run the generateCollections.sh script
30// to ensure the change is available on all versions of the map.
31// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
32
33class PKeyListTest {
34 private val list: MutablePKeyList = mutablePKeyListOf(1KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix)
35
36 @Test
37 fun emptyConstruction() {
38 val l = mutablePKeyListOf()
39 assertEquals(0, l.size)
40 assertEquals(16, l.capacity)
41 }
42
43 @Test
44 fun sizeConstruction() {
45 val l = MutablePKeyList(4)
46 assertEquals(4, l.capacity)
47 }
48
49 @Test
50 fun contentConstruction() {
51 val l = mutablePKeyListOf(1KeySuffix, 2KeySuffix, 3KeySuffix)
52 assertEquals(3, l.size)
53 assertEquals(1KeySuffix, l[0])
54 assertEquals(2KeySuffix, l[1])
55 assertEquals(3KeySuffix, l[2])
56 assertEquals(3, l.capacity)
57 repeat(2) {
58 val l2 = mutablePKeyListOf(1KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix)
59 assertEquals(list, l2)
60 l2.removeAt(0)
61 }
62 }
63
64 @Test
65 fun hashCodeTest() {
66 val l2 = mutablePKeyListOf(1KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix)
67 assertEquals(list.hashCode(), l2.hashCode())
68 l2.removeAt(4)
69 assertNotEquals(list.hashCode(), l2.hashCode())
70 l2.add(5KeySuffix)
71 assertEquals(list.hashCode(), l2.hashCode())
72 l2.clear()
73 assertNotEquals(list.hashCode(), l2.hashCode())
74 }
75
76 @Test
77 fun equalsTest() {
78 val l2 = mutablePKeyListOf(1KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix)
79 assertEquals(list, l2)
80 assertNotEquals(list, mutablePKeyListOf())
81 l2.removeAt(4)
82 assertNotEquals(list, l2)
83 l2.add(5KeySuffix)
84 assertEquals(list, l2)
85 l2.clear()
86 assertNotEquals(list, l2)
87 }
88
89 @Test
90 fun string() {
91 assertEquals("[${1KeySuffix}, ${2KeySuffix}, ${3KeySuffix}, ${4KeySuffix}, ${5KeySuffix}]", list.toString())
92 assertEquals("[]", mutablePKeyListOf().toString())
93 }
94
95 @Test
George Mount8d374032023-09-11 11:10:49 -070096 fun joinToString() {
97 assertEquals("${1KeySuffix}, ${2KeySuffix}, ${3KeySuffix}, ${4KeySuffix}, ${5KeySuffix}", list.joinToString())
98 assertEquals(
99 "x${1KeySuffix}, ${2KeySuffix}, ${3KeySuffix}...",
100 list.joinToString(prefix = "x", postfix = "y", limit = 3)
101 )
102 assertEquals(
103 ">${1KeySuffix}-${2KeySuffix}-${3KeySuffix}-${4KeySuffix}-${5KeySuffix}<",
104 list.joinToString(separator = "-", prefix = ">", postfix = "<")
105 )
106 assertEquals("one, two, three...", list.joinToString(limit = 3) {
107 when (it.toInt()) {
108 1 -> "one"
109 2 -> "two"
110 3 -> "three"
111 else -> "whoops"
112 }
113 })
114 }
115
116 @Test
George Mountfa688412023-08-31 09:01:24 -0700117 fun size() {
118 assertEquals(5, list.size)
119 assertEquals(5, list.count())
120 val l2 = mutablePKeyListOf()
121 assertEquals(0, l2.size)
122 assertEquals(0, l2.count())
123 l2 += 1KeySuffix
124 assertEquals(1, l2.size)
125 assertEquals(1, l2.count())
126 }
127
128 @Test
129 fun get() {
130 assertEquals(1KeySuffix, list[0])
131 assertEquals(5KeySuffix, list[4])
132 assertEquals(1KeySuffix, list.elementAt(0))
133 assertEquals(5KeySuffix, list.elementAt(4))
134 }
135
136 @Test
137 fun getOutOfBounds() {
138 assertFailsWith(IndexOutOfBoundsException::class) {
139 list[5]
140 }
141 }
142
143 @Test
144 fun getOutOfBoundsNegative() {
145 assertFailsWith(IndexOutOfBoundsException::class) {
146 list[-1]
147 }
148 }
149
150 @Test
151 fun elementAtOfBounds() {
152 assertFailsWith(IndexOutOfBoundsException::class) {
153 list.elementAt(5)
154 }
155 }
156
157 @Test
158 fun elementAtOfBoundsNegative() {
159 assertFailsWith(IndexOutOfBoundsException::class) {
160 list.elementAt(-1)
161 }
162 }
163
164 @Test
165 fun elementAtOrElse() {
166 assertEquals(1KeySuffix, list.elementAtOrElse(0) {
167 assertEquals(0, it)
168 0KeySuffix
169 })
170 assertEquals(0KeySuffix, list.elementAtOrElse(-1) {
171 assertEquals(-1, it)
172 0KeySuffix
173 })
174 assertEquals(0KeySuffix, list.elementAtOrElse(5) {
175 assertEquals(5, it)
176 0KeySuffix
177 })
178 }
179
180 @Test
181 fun count() {
182 assertEquals(1, list.count { it < 2KeySuffix })
183 assertEquals(0, list.count { it < 0KeySuffix })
184 assertEquals(5, list.count { it < 10KeySuffix })
185 }
186
187 @Test
188 fun isEmpty() {
189 assertFalse(list.isEmpty())
190 assertFalse(list.none())
191 assertTrue(mutablePKeyListOf().isEmpty())
192 assertTrue(mutablePKeyListOf().none())
193 }
194
195 @Test
196 fun isNotEmpty() {
197 assertTrue(list.isNotEmpty())
198 assertTrue(list.any())
199 assertFalse(mutablePKeyListOf().isNotEmpty())
200 }
201
202 @Test
203 fun indices() {
204 assertEquals(IntRange(0, 4), list.indices)
205 assertEquals(IntRange(0, -1), mutablePKeyListOf().indices)
206 }
207
208 @Test
209 fun any() {
210 assertTrue(list.any { it == 5KeySuffix })
211 assertTrue(list.any { it == 1KeySuffix })
212 assertFalse(list.any { it == 0KeySuffix })
213 }
214
215 @Test
216 fun reversedAny() {
217 val reversedList = mutablePKeyListOf()
218 assertFalse(
219 list.reversedAny {
220 reversedList.add(it)
221 false
222 }
223 )
224 val reversedContent = mutablePKeyListOf(5KeySuffix, 4KeySuffix, 3KeySuffix, 2KeySuffix, 1KeySuffix)
225 assertEquals(reversedContent, reversedList)
226
227 val reversedSublist = mutablePKeyListOf()
228 assertTrue(
229 list.reversedAny {
230 reversedSublist.add(it)
231 reversedSublist.size == 2
232 }
233 )
234 assertEquals(reversedSublist, mutablePKeyListOf(5KeySuffix, 4KeySuffix))
235 }
236
237 @Test
238 fun forEach() {
239 val copy = mutablePKeyListOf()
240 list.forEach { copy += it }
241 assertEquals(list, copy)
242 }
243
244 @Test
245 fun forEachReversed() {
246 val copy = mutablePKeyListOf()
247 list.forEachReversed { copy += it }
248 assertEquals(copy, mutablePKeyListOf(5KeySuffix, 4KeySuffix, 3KeySuffix, 2KeySuffix, 1KeySuffix))
249 }
250
251 @Test
252 fun forEachIndexed() {
253 val copy = mutablePKeyListOf()
254 val indices = mutablePKeyListOf()
255 list.forEachIndexed { index, item ->
256 copy += item
257 indices += index.toPKey()
258 }
259 assertEquals(list, copy)
260 assertEquals(indices, mutablePKeyListOf(0KeySuffix, 1KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix))
261 }
262
263 @Test
264 fun forEachReversedIndexed() {
265 val copy = mutablePKeyListOf()
266 val indices = mutablePKeyListOf()
267 list.forEachReversedIndexed { index, item ->
268 copy += item
269 indices += index.toPKey()
270 }
271 assertEquals(copy, mutablePKeyListOf(5KeySuffix, 4KeySuffix, 3KeySuffix, 2KeySuffix, 1KeySuffix))
272 assertEquals(indices, mutablePKeyListOf(4KeySuffix, 3KeySuffix, 2KeySuffix, 1KeySuffix, 0KeySuffix))
273 }
274
275 @Test
276 fun indexOfFirst() {
277 assertEquals(0, list.indexOfFirst { it == 1KeySuffix })
278 assertEquals(4, list.indexOfFirst { it == 5KeySuffix })
279 assertEquals(-1, list.indexOfFirst { it == 0KeySuffix })
280 assertEquals(0, mutablePKeyListOf(8KeySuffix, 8KeySuffix).indexOfFirst { it == 8KeySuffix })
281 }
282
283 @Test
284 fun indexOfLast() {
285 assertEquals(0, list.indexOfLast { it == 1KeySuffix })
286 assertEquals(4, list.indexOfLast { it == 5KeySuffix })
287 assertEquals(-1, list.indexOfLast { it == 0KeySuffix })
288 assertEquals(1, mutablePKeyListOf(8KeySuffix, 8KeySuffix).indexOfLast { it == 8KeySuffix })
289 }
290
291 @Test
292 fun contains() {
293 assertTrue(list.contains(5KeySuffix))
294 assertTrue(list.contains(1KeySuffix))
295 assertFalse(list.contains(0KeySuffix))
296 }
297
298 @Test
299 fun containsAllList() {
300 assertTrue(list.containsAll(mutablePKeyListOf(2KeySuffix, 3KeySuffix, 1KeySuffix)))
301 assertFalse(list.containsAll(mutablePKeyListOf(2KeySuffix, 3KeySuffix, 6KeySuffix)))
302 }
303
304 @Test
305 fun lastIndexOf() {
306 assertEquals(4, list.lastIndexOf(5KeySuffix))
307 assertEquals(1, list.lastIndexOf(2KeySuffix))
308 val copy = mutablePKeyListOf()
309 copy.addAll(list)
310 copy.addAll(list)
311 assertEquals(5, copy.lastIndexOf(1KeySuffix))
312 }
313
314 @Test
315 fun first() {
316 assertEquals(1KeySuffix, list.first())
317 }
318
319 @Test
320 fun firstException() {
321 assertFailsWith(NoSuchElementException::class) {
322 mutablePKeyListOf().first()
323 }
324 }
325
326 @Test
327 fun firstWithPredicate() {
328 assertEquals(5KeySuffix, list.first { it == 5KeySuffix })
329 assertEquals(1KeySuffix, mutablePKeyListOf(1KeySuffix, 5KeySuffix).first { it != 0KeySuffix })
330 }
331
332 @Test
333 fun firstWithPredicateException() {
334 assertFailsWith(NoSuchElementException::class) {
335 mutablePKeyListOf().first { it == 8KeySuffix }
336 }
337 }
338
339 @Test
340 fun last() {
341 assertEquals(5KeySuffix, list.last())
342 }
343
344 @Test
345 fun lastException() {
346 assertFailsWith(NoSuchElementException::class) {
347 mutablePKeyListOf().last()
348 }
349 }
350
351 @Test
352 fun lastWithPredicate() {
353 assertEquals(1KeySuffix, list.last { it == 1KeySuffix })
354 assertEquals(5KeySuffix, mutablePKeyListOf(1KeySuffix, 5KeySuffix).last { it != 0KeySuffix })
355 }
356
357 @Test
358 fun lastWithPredicateException() {
359 assertFailsWith(NoSuchElementException::class) {
360 mutablePKeyListOf().last { it == 8KeySuffix }
361 }
362 }
363
364 @Test
365 fun fold() {
366 assertEquals("12345", list.fold("") { acc, i -> acc + i.toInt().toString() })
367 }
368
369 @Test
370 fun foldIndexed() {
371 assertEquals(
372 "01-12-23-34-45-",
373 list.foldIndexed("") { index, acc, i ->
374 "$acc$index${i.toInt()}-"
375 }
376 )
377 }
378
379 @Test
380 fun foldRight() {
381 assertEquals("54321", list.foldRight("") { i, acc -> acc + i.toInt().toString() })
382 }
383
384 @Test
385 fun foldRightIndexed() {
386 assertEquals(
387 "45-34-23-12-01-",
388 list.foldRightIndexed("") { index, i, acc ->
389 "$acc$index${i.toInt()}-"
390 }
391 )
392 }
393
394 @Test
395 fun add() {
396 val l = mutablePKeyListOf(1KeySuffix, 2KeySuffix, 3KeySuffix)
397 l += 4KeySuffix
398 l.add(5KeySuffix)
399 assertEquals(list, l)
400 }
401
402 @Test
403 fun addAtIndex() {
404 val l = mutablePKeyListOf(2KeySuffix, 4KeySuffix)
405 l.add(2, 5KeySuffix)
406 l.add(0, 1KeySuffix)
407 l.add(2, 3KeySuffix)
408 assertEquals(list, l)
409 assertFailsWith(IndexOutOfBoundsException::class) {
410 l.add(-1, 2KeySuffix)
411 }
412 assertFailsWith(IndexOutOfBoundsException::class) {
413 l.add(6, 2KeySuffix)
414 }
415 }
416
417 @Test
418 fun addAllListAtIndex() {
419 val l = mutablePKeyListOf(4KeySuffix)
420 val l2 = mutablePKeyListOf(1KeySuffix, 2KeySuffix)
421 val l3 = mutablePKeyListOf(5KeySuffix)
422 val l4 = mutablePKeyListOf(3KeySuffix)
423 assertTrue(l4.addAll(1, l3))
424 assertTrue(l4.addAll(0, l2))
425 assertTrue(l4.addAll(3, l))
426 assertFalse(l4.addAll(0, mutablePKeyListOf()))
427 assertEquals(list, l4)
428 assertFailsWith(IndexOutOfBoundsException::class) {
429 l4.addAll(6, mutablePKeyListOf())
430 }
431 assertFailsWith(IndexOutOfBoundsException::class) {
432 l4.addAll(-1, mutablePKeyListOf())
433 }
434 }
435
436 @Test
437 fun addAllList() {
438 val l = MutablePKeyList()
439 l.add(3KeySuffix)
440 l.add(4KeySuffix)
441 l.add(5KeySuffix)
442 val l2 = mutablePKeyListOf(1KeySuffix, 2KeySuffix)
443 assertTrue(l2.addAll(l))
444 assertEquals(list, l2)
445 assertFalse(l2.addAll(mutablePKeyListOf()))
446 }
447
448 @Test
449 fun plusAssignList() {
450 val l = MutablePKeyList()
451 l.add(3KeySuffix)
452 l.add(4KeySuffix)
453 l.add(5KeySuffix)
454 val l2 = mutablePKeyListOf(1KeySuffix, 2KeySuffix)
455 l2 += l
456 assertEquals(list, l2)
457 }
458
459 @Test
460 fun addAllArrayAtIndex() {
461 val a1 = pKeyArrayOf(4KeySuffix)
462 val a2 = pKeyArrayOf(1KeySuffix, 2KeySuffix)
463 val a3 = pKeyArrayOf(5KeySuffix)
464 val l = mutablePKeyListOf(3KeySuffix)
465 assertTrue(l.addAll(1, a3))
466 assertTrue(l.addAll(0, a2))
467 assertTrue(l.addAll(3, a1))
468 assertFalse(l.addAll(0, pKeyArrayOf()))
469 assertEquals(list, l)
470 assertFailsWith(IndexOutOfBoundsException::class) {
471 l.addAll(6, pKeyArrayOf())
472 }
473 assertFailsWith(IndexOutOfBoundsException::class) {
474 l.addAll(-1, pKeyArrayOf())
475 }
476 }
477
478 @Test
479 fun addAllArray() {
480 val a = pKeyArrayOf(3KeySuffix, 4KeySuffix, 5KeySuffix)
481 val v = mutablePKeyListOf(1KeySuffix, 2KeySuffix)
482 v.addAll(a)
483 assertEquals(5, v.size)
484 assertEquals(3KeySuffix, v[2])
485 assertEquals(4KeySuffix, v[3])
486 assertEquals(5KeySuffix, v[4])
487 }
488
489 @Test
490 fun plusAssignArray() {
491 val a = pKeyArrayOf(3KeySuffix, 4KeySuffix, 5KeySuffix)
492 val v = mutablePKeyListOf(1KeySuffix, 2KeySuffix)
493 v += a
494 assertEquals(list, v)
495 }
496
497 @Test
498 fun clear() {
499 val l = mutablePKeyListOf()
500 l.addAll(list)
501 assertTrue(l.isNotEmpty())
502 l.clear()
503 assertTrue(l.isEmpty())
504 }
505
506 @Test
507 fun trim() {
508 val l = mutablePKeyListOf(1KeySuffix)
509 l.trim()
510 assertEquals(1, l.capacity)
511 l += pKeyArrayOf(1KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix)
512 l.trim()
513 assertEquals(6, l.capacity)
514 assertEquals(6, l.size)
515 l.clear()
516 l.trim()
517 assertEquals(0, l.capacity)
518 l.trim(100)
519 assertEquals(0, l.capacity)
520 l += pKeyArrayOf(1KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix)
521 l -= 5KeySuffix
522 l.trim(5)
523 assertEquals(5, l.capacity)
524 l.trim(4)
525 assertEquals(4, l.capacity)
526 l.trim(3)
527 assertEquals(4, l.capacity)
528 }
529
530 @Test
531 fun remove() {
532 val l = mutablePKeyListOf(1KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix)
533 l.remove(3KeySuffix)
534 assertEquals(mutablePKeyListOf(1KeySuffix, 2KeySuffix, 4KeySuffix, 5KeySuffix), l)
535 }
536
537 @Test
538 fun removeAt() {
539 val l = mutablePKeyListOf(1KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix)
540 l.removeAt(2)
541 assertEquals(mutablePKeyListOf(1KeySuffix, 2KeySuffix, 4KeySuffix, 5KeySuffix), l)
542 assertFailsWith(IndexOutOfBoundsException::class) {
543 l.removeAt(6)
544 }
545 assertFailsWith(IndexOutOfBoundsException::class) {
546 l.removeAt(-1)
547 }
548 }
549
550 @Test
551 fun set() {
552 val l = mutablePKeyListOf(0KeySuffix, 0KeySuffix, 0KeySuffix, 0KeySuffix, 0KeySuffix)
553 l[0] = 1KeySuffix
554 l[4] = 5KeySuffix
555 l[2] = 3KeySuffix
556 l[1] = 2KeySuffix
557 l[3] = 4KeySuffix
558 assertEquals(list, l)
559 assertFailsWith<IndexOutOfBoundsException> {
560 l.set(-1, 1KeySuffix)
561 }
562 assertFailsWith<IndexOutOfBoundsException> {
563 l.set(6, 1KeySuffix)
564 }
565 assertEquals(4KeySuffix, l.set(3, 1KeySuffix));
566 }
567
568 @Test
569 fun ensureCapacity() {
570 val l = mutablePKeyListOf(1KeySuffix)
571 assertEquals(1, l.capacity)
572 l.ensureCapacity(5)
573 assertEquals(5, l.capacity)
574 }
575
576 @Test
577 fun removeAllList() {
578 assertFalse(list.removeAll(mutablePKeyListOf(0KeySuffix, 10KeySuffix, 15KeySuffix)))
579 val l = mutablePKeyListOf(0KeySuffix, 1KeySuffix, 15KeySuffix, 10KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix, 20KeySuffix, 5KeySuffix)
580 assertTrue(l.removeAll(mutablePKeyListOf(20KeySuffix, 0KeySuffix, 15KeySuffix, 10KeySuffix, 5KeySuffix)))
581 assertEquals(list, l)
582 }
583
584 @Test
585 fun removeAllPKeyArray() {
586 assertFalse(list.removeAll(pKeyArrayOf(0KeySuffix, 10KeySuffix, 15KeySuffix)))
587 val l = mutablePKeyListOf(0KeySuffix, 1KeySuffix, 15KeySuffix, 10KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix, 20KeySuffix, 5KeySuffix)
588 assertTrue(l.removeAll(pKeyArrayOf(20KeySuffix, 0KeySuffix, 15KeySuffix, 10KeySuffix, 5KeySuffix)))
589 assertEquals(list, l)
590 }
591
592 @Test
593 fun minusAssignList() {
594 val l = mutablePKeyListOf().also { it += list }
595 l -= mutablePKeyListOf(0KeySuffix, 10KeySuffix, 15KeySuffix)
596 assertEquals(list, l)
597 val l2 = mutablePKeyListOf(0KeySuffix, 1KeySuffix, 15KeySuffix, 10KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix, 20KeySuffix, 5KeySuffix)
598 l2 -= mutablePKeyListOf(20KeySuffix, 0KeySuffix, 15KeySuffix, 10KeySuffix, 5KeySuffix)
599 assertEquals(list, l2)
600 }
601
602 @Test
603 fun minusAssignPKeyArray() {
604 val l = mutablePKeyListOf().also { it += list }
605 l -= pKeyArrayOf(0KeySuffix, 10KeySuffix, 15KeySuffix)
606 assertEquals(list, l)
607 val l2 = mutablePKeyListOf(0KeySuffix, 1KeySuffix, 15KeySuffix, 10KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix, 20KeySuffix, 5KeySuffix)
608 l2 -= pKeyArrayOf(20KeySuffix, 0KeySuffix, 15KeySuffix, 10KeySuffix, 5KeySuffix)
609 assertEquals(list, l2)
610 }
611
612 @Test
613 fun retainAll() {
614 assertFalse(list.retainAll(mutablePKeyListOf(1KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix, 6KeySuffix)))
615 val l = mutablePKeyListOf(0KeySuffix, 1KeySuffix, 15KeySuffix, 10KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix, 20KeySuffix)
616 assertTrue(l.retainAll(mutablePKeyListOf(1KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix, 6KeySuffix)))
617 assertEquals(list, l)
618 }
619
620 @Test
621 fun retainAllPKeyArray() {
622 assertFalse(list.retainAll(pKeyArrayOf(1KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix, 6KeySuffix)))
623 val l = mutablePKeyListOf(0KeySuffix, 1KeySuffix, 15KeySuffix, 10KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix, 20KeySuffix)
624 assertTrue(l.retainAll(pKeyArrayOf(1KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix, 6KeySuffix)))
625 assertEquals(list, l)
626 }
627
628 @Test
629 fun removeRange() {
630 val l = mutablePKeyListOf(1KeySuffix, 9KeySuffix, 7KeySuffix, 6KeySuffix, 2KeySuffix, 3KeySuffix, 4KeySuffix, 5KeySuffix)
631 l.removeRange(1, 4)
632 assertEquals(list, l)
633 assertFailsWith<IndexOutOfBoundsException> {
634 l.removeRange(6, 6)
635 }
636 assertFailsWith<IndexOutOfBoundsException> {
637 l.removeRange(100, 200)
638 }
639 assertFailsWith<IndexOutOfBoundsException> {
640 l.removeRange(-1, 0)
641 }
642 assertFailsWith<IllegalArgumentException> {
643 l.removeRange(3, 2)
644 }
645 }
646
647 @Test
648 fun sort() {
649 val l = mutablePKeyListOf(1KeySuffix, 4KeySuffix, 2KeySuffix, 5KeySuffix, 3KeySuffix)
650 l.sort()
651 assertEquals(list, l)
652 }
653
654 @Test
655 fun sortDescending() {
656 val l = mutablePKeyListOf(1KeySuffix, 4KeySuffix, 2KeySuffix, 5KeySuffix, 3KeySuffix)
657 l.sortDescending()
658 assertEquals(mutablePKeyListOf(5KeySuffix, 4KeySuffix, 3KeySuffix, 2KeySuffix, 1KeySuffix), l)
659 }
660
661 @Test
662 fun testEmptyPKeyList() {
663 val l = emptyPKeyList()
664 assertEquals(0, l.size)
665 }
666
667 @Test
668 fun pKeyListOfEmpty() {
669 val l = pKeyListOf()
670 assertEquals(0, l.size)
671 }
672
673 @Test
674 fun pKeyListOfOneValue() {
675 val l = pKeyListOf(2KeySuffix)
676 assertEquals(1, l.size)
677 assertEquals(2KeySuffix, l[0])
678 }
679
680 @Test
681 fun pKeyListOfTwoValues() {
682 val l = pKeyListOf(2KeySuffix, 1KeySuffix)
683 assertEquals(2, l.size)
684 assertEquals(2KeySuffix, l[0])
685 assertEquals(1KeySuffix, l[1])
686 }
687
688 @Test
689 fun pKeyListOfThreeValues() {
690 val l = pKeyListOf(2KeySuffix, 10KeySuffix, -1KeySuffix)
691 assertEquals(3, l.size)
692 assertEquals(2KeySuffix, l[0])
693 assertEquals(10KeySuffix, l[1])
694 assertEquals(-1KeySuffix, l[2])
695 }
696
697 @Test
698 fun pKeyListOfFourValues() {
699 val l = pKeyListOf(2KeySuffix, 10KeySuffix, -1KeySuffix, 10KeySuffix)
700 assertEquals(4, l.size)
701 assertEquals(2KeySuffix, l[0])
702 assertEquals(10KeySuffix, l[1])
703 assertEquals(-1KeySuffix, l[2])
704 assertEquals(10KeySuffix, l[3])
705 }
706
707 @Test
708 fun mutablePKeyListOfOneValue() {
709 val l = mutablePKeyListOf(2KeySuffix)
710 assertEquals(1, l.size)
711 assertEquals(1, l.capacity)
712 assertEquals(2KeySuffix, l[0])
713 }
714
715 @Test
716 fun mutablePKeyListOfTwoValues() {
717 val l = mutablePKeyListOf(2KeySuffix, 1KeySuffix)
718 assertEquals(2, l.size)
719 assertEquals(2, l.capacity)
720 assertEquals(2KeySuffix, l[0])
721 assertEquals(1KeySuffix, l[1])
722 }
723
724 @Test
725 fun mutablePKeyListOfThreeValues() {
726 val l = mutablePKeyListOf(2KeySuffix, 10KeySuffix, -1KeySuffix)
727 assertEquals(3, l.size)
728 assertEquals(3, l.capacity)
729 assertEquals(2KeySuffix, l[0])
730 assertEquals(10KeySuffix, l[1])
731 assertEquals(-1KeySuffix, l[2])
732 }
733
734 @Test
735 fun mutablePKeyListOfFourValues() {
736 val l = mutablePKeyListOf(2KeySuffix, 10KeySuffix, -1KeySuffix, 10KeySuffix)
737 assertEquals(4, l.size)
738 assertEquals(4, l.capacity)
739 assertEquals(2KeySuffix, l[0])
740 assertEquals(10KeySuffix, l[1])
741 assertEquals(-1KeySuffix, l[2])
742 assertEquals(10KeySuffix, l[3])
743 }
744}