summaryrefslogtreecommitdiff
path: root/examples/scala-js/test-suite/src/test/scala/scala/scalajs/testsuite/javalib/ArraysTest.scala
blob: d0d97f1e1e9ac80d3d4baf04917ac4b93c38c9db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
/*                     __                                               *\
**     ________ ___   / /  ___      __ ____  Scala.js Test Suite        **
**    / __/ __// _ | / /  / _ | __ / // __/  (c) 2013, LAMP/EPFL        **
**  __\ \/ /__/ __ |/ /__/ __ |/_// /_\ \    http://scala-js.org/       **
** /____/\___/_/ |_/____/_/ | |__/ /____/                               **
**                          |/____/                                     **
\*                                                                      */
package scala.scalajs.testsuite.javalib

import language.implicitConversions

import scala.scalajs.js
import scala.scalajs.js.JSConverters._

import org.scalajs.jasminetest.JasmineTest

import java.util.{ Arrays, Comparator }

import scala.reflect.ClassTag

object ArraysTest extends ArraysTest

/** This is also used in the typedarray package to test scala.Arrays backed
 *  by TypedArrays
 */
trait ArraysTest extends JasmineTest {

  // Just in here, we allow ourselves to do this
  implicit def array2jsArray[T](arr: Array[T]): js.Array[T] = arr.toJSArray

  /** Overridden by typedarray tests */
  def Array[T : ClassTag](v: T*): scala.Array[T] = scala.Array(v: _*)

  /** Overridden by typedarray tests */
  def testBody(suite: => Unit) = describe("java.util.Arrays")(suite)

  val stringComparator = new Comparator[String]() {
    def compare(s1: String, s2: String) = s1.compareTo(s2)
  }

  val intComparator = new Comparator[Int]() {
    def compare(i1: Int, i2: Int) = i1 - i2
  }

  testBody {

    it("should respond to `sort` for Int") {
      val scalaInts = Array(5, 3, 6, 1, 2, 4)
      val ints = new Array[Object](scalaInts.length)
      for (i <- 0 until scalaInts.length)
        ints(i) = scalaInts(i).asInstanceOf[Object]
      val sorted = Array(1, 2, 3, 4, 5, 6)

      Arrays.sort(ints, intComparator.asInstanceOf[Comparator[Object]])
      expect(ints).toEqual(Array(1, 2, 3, 4, 5, 6))
    }

    it("should respond to `sort` for String") {
      val scalajs: Array[Object] = Array("S", "c", "a", "l", "a", ".", "j", "s")
      val sorted = Array(".", "S", "a", "a", "c", "j", "l", "s")

      Arrays.sort(scalajs, stringComparator.asInstanceOf[Comparator[Object]])
      expect(scalajs).toEqual(sorted)
    }

    it("should respond to `fill` for Boolean") {
      val booleans = new Array[Boolean](6)
      Arrays.fill(booleans, false)
      expect(booleans).toEqual(Array(false, false, false, false, false, false))

      Arrays.fill(booleans, true)
      expect(booleans).toEqual(Array(true, true, true, true, true, true))
    }

    it("should respond to `fill` with start and end index for Boolean") {
      val booleans = new Array[Boolean](6)
      Arrays.fill(booleans, 1, 4, true)
      expect(booleans).toEqual(Array(false, true, true, true, false, false))
    }

    it("should respond to `fill` for Byte") {
      val bytes = new Array[Byte](6)
      Arrays.fill(bytes, 42.toByte)
      expect(bytes).toEqual(Array[Byte](42, 42, 42, 42, 42, 42))

      Arrays.fill(bytes, -1.toByte)
      expect(bytes).toEqual(Array[Byte](-1, -1, -1, -1, -1, -1))
    }

    it("should respond to `fill` with start and end index for Byte") {
      val bytes = new Array[Byte](6)
      Arrays.fill(bytes, 1, 4, 42.toByte)
      expect(bytes).toEqual(Array[Byte](0, 42, 42, 42, 0, 0))

      Arrays.fill(bytes, 2, 5, -1.toByte)
      expect(bytes).toEqual(Array[Byte](0, 42, -1, -1, -1, 0))
    }

    it("should respond to `fill` for Short") {
      val shorts = new Array[Short](6)
      Arrays.fill(shorts, 42.toShort)
      expect(shorts).toEqual(Array[Short](42, 42, 42, 42, 42, 42))

      Arrays.fill(shorts, -1.toShort)
      expect(shorts).toEqual(Array[Short](-1, -1, -1, -1, -1, -1))
    }

    it("should respond to `fill` with start and end index for Short") {
      val shorts = new Array[Short](6)
      Arrays.fill(shorts, 1, 4, 42.toShort)
      expect(shorts).toEqual(Array[Short](0, 42, 42, 42, 0, 0))

      Arrays.fill(shorts, 2, 5, -1.toShort)
      expect(shorts).toEqual(Array[Short](0, 42, -1, -1, -1, 0))
    }

    it("should respond to `fill` for Int") {
      val ints = new Array[Int](6)
      Arrays.fill(ints, 42)
      expect(ints).toEqual(Array(42, 42, 42, 42, 42, 42))

      Arrays.fill(ints, -1)
      expect(ints).toEqual(Array(-1, -1, -1, -1, -1, -1))
    }

    it("should respond to `fill` with start and end index for Int") {
      val ints = new Array[Int](6)
      Arrays.fill(ints, 1, 4, 42)
      expect(ints).toEqual(Array(0, 42, 42, 42, 0, 0))

      Arrays.fill(ints, 2, 5, -1)
      expect(ints).toEqual(Array(0, 42, -1, -1, -1, 0))
    }

    it("should respond to `fill` for Long") {
      val longs = new Array[Long](6)
      Arrays.fill(longs, 42L)
      expect(longs).toEqual(Array(42L, 42L, 42L, 42L, 42L, 42L))

      Arrays.fill(longs, -1L)
      expect(longs).toEqual(Array(-1L, -1L, -1L, -1L, -1L, -1L))
    }

    it("should respond to `fill` with start and end index for Long") {
      val longs = new Array[Long](6)
      Arrays.fill(longs, 1, 4, 42L)
      expect(longs).toEqual(Array(0L, 42L, 42L, 42L, 0L, 0L))

      Arrays.fill(longs, 2, 5, -1L)
      expect(longs).toEqual(Array(0L, 42L, -1L, -1L, -1L, 0L))
    }

    it("should respond to `fill` for Float") {
      val floats = new Array[Float](6)
      Arrays.fill(floats, 42.0f)
      expect(floats).toEqual(Array(42.0f, 42.0f, 42.0f, 42.0f, 42.0f, 42.0f))

      Arrays.fill(floats, -1.0f)
      expect(floats).toEqual(Array(-1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f))
    }

    it("should respond to `fill` with start and end index for Float") {
      val floats = new Array[Float](6)
      Arrays.fill(floats, 1, 4, 42.0f)
      expect(floats).toEqual(Array(0.0f, 42.0f, 42.0f, 42.0f, 0.0f, 0.0f))

      Arrays.fill(floats, 2, 5, -1.0f)
      expect(floats).toEqual(Array(0.0f, 42.0f, -1.0f, -1.0f, -1.0f, 0.0f))
    }

    it("should respond to `fill` for Double") {
      val doubles = new Array[Double](6)
      Arrays.fill(doubles, 42.0)
      expect(doubles).toEqual(Array(42.0, 42.0, 42.0, 42.0, 42.0, 42.0))

      Arrays.fill(doubles, -1.0f)
      expect(doubles).toEqual(Array(-1.0, -1.0, -1.0, -1.0, -1.0, -1.0))
    }

    it("should respond to `fill` with start and end index for Double") {
      val doubles = new Array[Double](6)
      Arrays.fill(doubles, 1, 4, 42.0)
      expect(doubles).toEqual(Array(0.0, 42.0, 42.0, 42.0, 0.0, 0.0))

      Arrays.fill(doubles, 2, 5, -1.0)
      expect(doubles).toEqual(Array(0.0, 42.0, -1.0, -1.0, -1.0, 0.0))
    }

    it("should respond to `fill` for AnyRef") {
      val array = new Array[AnyRef](6)
      Arrays.fill(array, "a")
      expect(array).toEqual(Array[AnyRef]("a", "a", "a", "a", "a", "a"))

      Arrays.fill(array, "b")
      expect(array).toEqual(Array[AnyRef]("b", "b", "b", "b", "b", "b"))
    }

    it("should respond to `fill` with start and end index for AnyRef") {
      val bytes = new Array[AnyRef](6)
      Arrays.fill(bytes, 1, 4, "a")
      expect(bytes).toEqual(Array[AnyRef](null, "a", "a", "a", null, null))

      Arrays.fill(bytes, 2, 5, "b")
      expect(bytes).toEqual(Array[AnyRef](null, "a", "b", "b", "b", null))
    }

    it("should respond to `binarySearch` with start index, end index and key for Long") {
      val longs: Array[Long] = Array(1, 2, 3, 5, 6, 7)
      var ret = Arrays.binarySearch(longs, 0, 6, 5)
      expect(ret).toEqual(3)

      ret = Arrays.binarySearch(longs, 0, 6, 0)
      expect(ret).toEqual(-1)

      ret = Arrays.binarySearch(longs, 0, 6, 4)
      expect(ret).toEqual(-4)

      ret = Arrays.binarySearch(longs, 0, 6, 8)
      expect(ret).toEqual(-7)
    }

    it("should respond to `binarySearch` with key for Long") {
      val longs: Array[Long] = Array(1, 2, 3, 5, 6, 7)
      var ret = Arrays.binarySearch(longs, 5)
      expect(ret).toEqual(3)

      ret = Arrays.binarySearch(longs, 0)
      expect(ret).toEqual(-1)

      ret = Arrays.binarySearch(longs, 4)
      expect(ret).toEqual(-4)

      ret = Arrays.binarySearch(longs, 8)
      expect(ret).toEqual(-7)
    }

    it("should respond to `binarySearch` with start index, end index and key for Int") {
      val ints: Array[Int] = Array(1, 2, 3, 5, 6, 7)
      var ret = Arrays.binarySearch(ints, 0, 6, 5)
      expect(ret).toEqual(3)

      ret = Arrays.binarySearch(ints, 0, 6, 0)
      expect(ret).toEqual(-1)

      ret = Arrays.binarySearch(ints, 0, 6, 4)
      expect(ret).toEqual(-4)

      ret = Arrays.binarySearch(ints, 0, 6, 8)
      expect(ret).toEqual(-7)
    }

    it("should respond to `binarySearch` with key for Int") {
      val ints: Array[Int] = Array(1, 2, 3, 5, 6, 7)
      var ret = Arrays.binarySearch(ints, 5)
      expect(ret).toEqual(3)

      ret = Arrays.binarySearch(ints, 0)
      expect(ret).toEqual(-1)

      ret = Arrays.binarySearch(ints, 4)
      expect(ret).toEqual(-4)

      ret = Arrays.binarySearch(ints, 8)
      expect(ret).toEqual(-7)
    }

    it("should respond to `binarySearch` with start index, end index and key for Short") {
      val shorts: Array[Short] = Array(1, 2, 3, 5, 6, 7)
      var ret = Arrays.binarySearch(shorts, 0, 6, 5.toShort)
      expect(ret).toEqual(3)

      ret = Arrays.binarySearch(shorts, 0, 6, 0.toShort)
      expect(ret).toEqual(-1)

      ret = Arrays.binarySearch(shorts, 0, 6, 4.toShort)
      expect(ret).toEqual(-4)

      ret = Arrays.binarySearch(shorts, 0, 6, 8.toShort)
      expect(ret).toEqual(-7)
    }

    it("should respond to `binarySearch` with key for Short") {
      val shorts: Array[Short] = Array(1, 2, 3, 5, 6, 7)
      var ret = Arrays.binarySearch(shorts, 5.toShort)
      expect(ret).toEqual(3)

      ret = Arrays.binarySearch(shorts, 0.toShort)
      expect(ret).toEqual(-1)

      ret = Arrays.binarySearch(shorts, 4.toShort)
      expect(ret).toEqual(-4)

      ret = Arrays.binarySearch(shorts, 8.toShort)
      expect(ret).toEqual(-7)
    }

    it("should respond to `binarySearch` with start index, end index and key for Char") {
      val chars: Array[Char] = Array('b', 'c', 'd', 'f', 'g', 'h')
      var ret = Arrays.binarySearch(chars, 0, 6, 'f')
      expect(ret).toEqual(3)

      ret = Arrays.binarySearch(chars, 0, 6, 'a')
      expect(ret).toEqual(-1)

      ret = Arrays.binarySearch(chars, 0, 6, 'e')
      expect(ret).toEqual(-4)

      ret = Arrays.binarySearch(chars, 0, 6, 'i')
      expect(ret).toEqual(-7)
    }

    it("should respond to `binarySearch` with key for Char") {
      val chars: Array[Char] = Array('b', 'c', 'd', 'f', 'g', 'h')
      var ret = Arrays.binarySearch(chars, 'f')
      expect(ret).toEqual(3)

      ret = Arrays.binarySearch(chars, 'a')
      expect(ret).toEqual(-1)

      ret = Arrays.binarySearch(chars, 'e')
      expect(ret).toEqual(-4)

      ret = Arrays.binarySearch(chars, 'i')
      expect(ret).toEqual(-7)
    }

    it("should respond to `binarySearch` with start index, end index and key for Double") {
      val doubles: Array[Double] = Array(0.1, 0.2, 0.3, 0.5, 0.6, 0.7)
      var ret = Arrays.binarySearch(doubles, 0, 6, 0.5)
      expect(ret).toEqual(3)

      ret = Arrays.binarySearch(doubles, 0, 6, 0.0)
      expect(ret).toEqual(-1)

      ret = Arrays.binarySearch(doubles, 0, 6, 0.4)
      expect(ret).toEqual(-4)

      ret = Arrays.binarySearch(doubles, 0, 6, 0.8)
      expect(ret).toEqual(-7)
    }

    it("should respond to `binarySearch` with key for Double") {
      val doubles: Array[Double] = Array(0.1, 0.2, 0.3, 0.5, 0.6, 0.7)
      var ret = Arrays.binarySearch(doubles, 0.5)
      expect(ret).toEqual(3)

      ret = Arrays.binarySearch(doubles, 0.0)
      expect(ret).toEqual(-1)

      ret = Arrays.binarySearch(doubles, 0.4)
      expect(ret).toEqual(-4)

      ret = Arrays.binarySearch(doubles, 0.8)
      expect(ret).toEqual(-7)
    }

    it("should respond to `binarySearch` with start index, end index and key for Float") {
      val floats: Array[Float] = Array(0.1f, 0.2f, 0.3f, 0.5f, 0.6f, 0.7f)
      var ret = Arrays.binarySearch(floats, 0, 6, 0.5f)
      expect(ret).toEqual(3)

      ret = Arrays.binarySearch(floats, 0, 6, 0.0f)
      expect(ret).toEqual(-1)

      ret = Arrays.binarySearch(floats, 0, 6, 0.4f)
      expect(ret).toEqual(-4)

      ret = Arrays.binarySearch(floats, 0, 6, 0.8f)
      expect(ret).toEqual(-7)
    }

    it("should respond to `binarySearch` with key for Float") {
      val floats: Array[Float] = Array(0.1f, 0.2f, 0.3f, 0.5f, 0.6f, 0.7f)
      var ret = Arrays.binarySearch(floats, 0.5f)
      expect(ret).toEqual(3)

      ret = Arrays.binarySearch(floats, 0.0f)
      expect(ret).toEqual(-1)

      ret = Arrays.binarySearch(floats, 0.4f)
      expect(ret).toEqual(-4)

      ret = Arrays.binarySearch(floats, 0.8f)
      expect(ret).toEqual(-7)
    }

    it("should respond to `binarySearch` with start index, end index and key for AnyRef") {
      val strings: Array[AnyRef] = Array("aa", "abc", "cc", "zz", "zzzs", "zzzt")
      var ret = Arrays.binarySearch(strings, 0, 6, "zz")
      expect(ret).toEqual(3)

      ret = Arrays.binarySearch(strings, 0, 6, "a")
      expect(ret).toEqual(-1)

      ret = Arrays.binarySearch(strings, 0, 6, "cd")
      expect(ret).toEqual(-4)

      ret = Arrays.binarySearch(strings, 0, 6, "zzzz")
      expect(ret).toEqual(-7)
    }

    it("should respond to `binarySearch` with key for AnyRef") {
      val strings: Array[AnyRef] = Array("aa", "abc", "cc", "zz", "zzzs", "zzzt")
      var ret = Arrays.binarySearch(strings, "zz")
      expect(ret).toEqual(3)

      ret = Arrays.binarySearch(strings, "a")
      expect(ret).toEqual(-1)

      ret = Arrays.binarySearch(strings, "cd")
      expect(ret).toEqual(-4)

      ret = Arrays.binarySearch(strings, "zzzz")
      expect(ret).toEqual(-7)
    }

    it("should check ranges of input to `binarySearch`") {
      def expectException(block: => Unit)(expected: PartialFunction[Throwable, Unit]): Unit = {
        val catchAll: PartialFunction[Throwable, Unit] = {
          case e: Throwable => expect(e.getClass.getName).toBe("not thrown")
        }

        try {
          block
          expect("exception").toBe("thrown")
        } catch expected orElse catchAll
      }

      val array = Array(0, 1, 3, 4)

      expectException({ Arrays.binarySearch(array, 3, 2, 2) }) {
        case exception: IllegalArgumentException =>
          expect(exception.getMessage).toBe("fromIndex(3) > toIndex(2)")
      }

      // start/end comparison is made before index ranges checks
      expectException({ Arrays.binarySearch(array, 7, 5, 2) }) {
        case exception: IllegalArgumentException =>
          expect(exception.getMessage).toBe("fromIndex(7) > toIndex(5)")
      }

      expectException({ Arrays.binarySearch(array, -1, 4, 2) }) {
        case exception: ArrayIndexOutOfBoundsException =>
          expect(exception.getMessage).toBe("Array index out of range: -1")
      }

      expectException({ Arrays.binarySearch(array, 0, 5, 2) }) {
        case exception: ArrayIndexOutOfBoundsException =>
          expect(exception.getMessage).toBe("Array index out of range: 5")
      }
    }

    it("should respond to `copyOf` with key for Int") {
      val ints: Array[Int] = Array(1, 2, 3)
      val intscopy = Arrays.copyOf(ints, 5)
      expect(intscopy).toEqual(Array(1, 2, 3, 0, 0))
    }

    it("should respond to `copyOf` with key for Long") {
      val longs: Array[Long] = Array(1, 2, 3)
      val longscopy = Arrays.copyOf(longs, 5)
      expect(longscopy).toEqual(Array[Long](1, 2, 3, 0, 0))
    }

    it("should respond to `copyOf` with key for Short") {
      val shorts: Array[Short] = Array(1, 2, 3)
      val shortscopy = Arrays.copyOf(shorts, 5)
      expect(shortscopy).toEqual(Array[Short](1, 2, 3, 0, 0))
    }

    it("should respond to `copyOf` with key for Byte") {
      val bytes: Array[Byte] = Array(42, 43, 44)
      val floatscopy = Arrays.copyOf(bytes, 5)
      expect(floatscopy).toEqual(Array[Byte](42, 43, 44, 0, 0))
    }

    it("should respond to `copyOf` with key for Char") {
      val chars: Array[Char] = Array('a', 'b', '0')
      val charscopy = Arrays.copyOf(chars, 5)
      expect(charscopy(4)).toEqual(0.toChar)
    }

    it("should respond to `copyOf` with key for Double") {
      val doubles: Array[Double] = Array(0.1, 0.2, 0.3)
      val doublescopy = Arrays.copyOf(doubles, 5)
      expect(doublescopy).toEqual(Array[Double](0.1, 0.2, 0.3, 0, 0))
    }

    it("should respond to `copyOf` with key for Float") {
      val floats: Array[Float] = Array(0.1f, 0.2f, 0.3f)
      val floatscopy = Arrays.copyOf(floats, 5)
      expect(floatscopy).toEqual(Array[Float](0.1f, 0.2f, 0.3f, 0f, 0f))
    }

    it("should respond to `copyOf` with key for Boolean") {
      val bools: Array[Boolean] = Array(false, true, false)
      val boolscopy = Arrays.copyOf(bools, 5)
      expect(boolscopy).toEqual(Array[Boolean](false, true, false, false, false))
    }

    it("should respond to `copyOf` with key for AnyRef") {
      val anyrefs: Array[AnyRef] = Array("a", "b", "c")
      val anyrefscopy = Arrays.copyOf(anyrefs, 5)
      expect(anyrefscopy.getClass() == classOf[Array[AnyRef]]).toBeTruthy
      expect(anyrefscopy).toEqual(Array[AnyRef]("a", "b", "c", null, null))

      val sequences: Array[CharSequence] = Array("a", "b", "c")
      val sequencescopy = Arrays.copyOf(sequences, 2)
      expect(sequencescopy.getClass() == classOf[Array[CharSequence]])
      expect(sequencescopy).toEqual(Array[CharSequence]("a", "b"))
    }

    it("should respond to `copyOfRange` for AnyRef") {
      val anyrefs: Array[AnyRef] = Array("a", "b", "c", "d", "e")
      val anyrefscopy = Arrays.copyOfRange(anyrefs, 2, 4)
      expect(anyrefscopy.getClass() == classOf[Array[AnyRef]]).toBeTruthy
      expect(anyrefscopy).toEqual(Array[AnyRef]("c", "d"))

      val sequences: Array[CharSequence] = Array("a", "b", "c", "d", "e")
      val sequencescopy = Arrays.copyOfRange(sequences, 1, 5)
      expect(sequencescopy.getClass() == classOf[Array[CharSequence]])
      expect(sequencescopy).toEqual(Array[CharSequence]("b", "c", "d", "e"))
    }

    it("should respond to `hashCode` for Boolean") {
      expect(Arrays.hashCode(null: Array[Boolean])).toEqual(0)
      expect(Arrays.hashCode(Array[Boolean]())).toEqual(1)
      expect(Arrays.hashCode(Array[Boolean](false))).toEqual(1268)
      expect(Arrays.hashCode(Array[Boolean](true, false))).toEqual(40359)
    }

    it("should respond to `hashCode` for Chars") {
      expect(Arrays.hashCode(null: Array[Char])).toEqual(0)
      expect(Arrays.hashCode(Array[Char]())).toEqual(1)
      expect(Arrays.hashCode(Array[Char]('a'))).toEqual(128)
      expect(Arrays.hashCode(Array[Char]('c', '&'))).toEqual(4068)
      expect(Arrays.hashCode(Array[Char]('-', '5', 'q'))).toEqual(74792)
      expect(Arrays.hashCode(Array[Char]('.', ' ', '\u4323', 'v', '~'))).toEqual(88584920)
    }

    it("should respond to `hashCode` for Bytes") {
      expect(Arrays.hashCode(null: Array[Byte])).toEqual(0)
      expect(Arrays.hashCode(Array[Byte]())).toEqual(1)
      expect(Arrays.hashCode(Array[Byte](1))).toEqual(32)
      expect(Arrays.hashCode(Array[Byte](7, -125))).toEqual(1053)
      expect(Arrays.hashCode(Array[Byte](3, 0, 45))).toEqual(32719)
      expect(Arrays.hashCode(Array[Byte](0, 45, 100, 1, 1))).toEqual(30065878)
    }

    it("should respond to `hashCode` for Shorts") {
      expect(Arrays.hashCode(null: Array[Short])).toEqual(0)
      expect(Arrays.hashCode(Array[Short]())).toEqual(1)
      expect(Arrays.hashCode(Array[Short](1))).toEqual(32)
      expect(Arrays.hashCode(Array[Short](7, -125))).toEqual(1053)
      expect(Arrays.hashCode(Array[Short](3, 0, 4534))).toEqual(37208)
      expect(Arrays.hashCode(Array[Short](0, 45, 100, 1, 1))).toEqual(30065878)
    }

    it("should respond to `hashCode` for Ints") {
      expect(Arrays.hashCode(null: Array[Int])).toEqual(0)
      expect(Arrays.hashCode(Array[Int]())).toEqual(1)
      expect(Arrays.hashCode(Array[Int](1))).toEqual(32)
      expect(Arrays.hashCode(Array[Int](7, -125))).toEqual(1053)
      expect(Arrays.hashCode(Array[Int](3, 0, 4534))).toEqual(37208)
      expect(Arrays.hashCode(Array[Int](0, 45, 100, 1, 1, Int.MaxValue))).toEqual(-1215441431)
    }

    it("should respond to `hashCode` for Longs") {
      expect(Arrays.hashCode(null: Array[Long])).toEqual(0)
      expect(Arrays.hashCode(Array[Long]())).toEqual(1)
      expect(Arrays.hashCode(Array[Long](1L))).toEqual(32)
      expect(Arrays.hashCode(Array[Long](7L, -125L))).toEqual(1302)
      expect(Arrays.hashCode(Array[Long](3L, 0L, 4534L))).toEqual(37208)
      expect(Arrays.hashCode(Array[Long](0L, 45L, 100L, 1L, 1L, Int.MaxValue))).toEqual(-1215441431)
      expect(Arrays.hashCode(Array[Long](0L, 34573566354545L, 100L, 1L, 1L, Int.MaxValue))).toEqual(-1952288964)
    }

    it("should respond to `hashCode` for Floats") {
      expect(Arrays.hashCode(null: Array[Float])).toEqual(0)
      expect(Arrays.hashCode(Array[Float]())).toEqual(1)
      expect(Arrays.hashCode(Array[Float](1f))).toEqual(32)
      expect(Arrays.hashCode(Array[Float](7.2f, -125.2f))).toEqual(-2082726591)
      expect(Arrays.hashCode(Array[Float](302.1f, 0.0f, 4534f))).toEqual(-1891539602)
      expect(Arrays.hashCode(Array[Float](0.0f, 45f, -100f, 1.1f, -1f, 3567f))).toEqual(-1591440133)
    }

    it("should respond to `hashCode` for Doubles") {
      expect(Arrays.hashCode(null: Array[Double])).toEqual(0)
      expect(Arrays.hashCode(Array[Double]())).toEqual(1)
      expect(Arrays.hashCode(Array[Double](1.1))).toEqual(-1503133662)
      expect(Arrays.hashCode(Array[Double](7.3, -125.23))).toEqual(-2075734168)
      expect(Arrays.hashCode(Array[Double](3.9, 0.2, 4534.9))).toEqual(-557562564)
      expect(Arrays.hashCode(Array[Double](0.1, 45.1, -100.0, 1.1, 1.7))).toEqual(-1750344582)
      expect(Arrays.hashCode(Array[Double](0.0, 34573566354545.9, 100.2, 1.1, 1.2, Int.MaxValue))).toEqual(-1764602991)
    }

    it("should respond to `hashCode` for AnyRef") {
      expect(Arrays.hashCode(null: Array[AnyRef])).toEqual(0)
      expect(Arrays.hashCode(Array[AnyRef]())).toEqual(1)
      expect(Arrays.hashCode(Array[AnyRef](null, null))).toEqual(961)
      expect(Arrays.hashCode(Array[AnyRef]("a", "b", null))).toEqual(126046)
      expect(Arrays.hashCode(Array[AnyRef](null, "a", "b", null, "fooooo"))).toEqual(-1237252983)
    }

    it("should respond to `equals` for Booleans") {
      val a1 = Array(true, false)

      expect(Arrays.equals(a1, a1)).toBeTruthy
      expect(Arrays.equals(a1, Array(true, false))).toBeTruthy

      expect(Arrays.equals(a1, Array(true))).toBeFalsy
      expect(Arrays.equals(a1, Array(false))).toBeFalsy
      expect(Arrays.equals(a1, Array[Boolean]())).toBeFalsy
      expect(Arrays.equals(a1, Array(false, true))).toBeFalsy
      expect(Arrays.equals(a1, Array(false, true, false))).toBeFalsy
    }

    it("should respond to `equals` for Bytes") {
      val a1 = Array[Byte](1, -7, 10)

      expect(Arrays.equals(null: Array[Byte], null: Array[Byte])).toBeTruthy
      expect(Arrays.equals(a1, a1)).toBeTruthy
      expect(Arrays.equals(a1, Array[Byte](1, -7, 10))).toBeTruthy

      expect(Arrays.equals(a1, null)).toBeFalsy
      expect(Arrays.equals(a1, Array[Byte](3))).toBeFalsy
      expect(Arrays.equals(a1, Array[Byte](1))).toBeFalsy
      expect(Arrays.equals(a1, Array[Byte]())).toBeFalsy
      expect(Arrays.equals(a1, Array[Byte](1, -7, 11))).toBeFalsy
      expect(Arrays.equals(a1, Array[Byte](1, -7, 11, 20))).toBeFalsy
    }

    it("should respond to `equals` for Chars") {
      val a1 = Array[Char]('a', '0', '-')

      expect(Arrays.equals(null: Array[Char], null: Array[Char])).toBeTruthy
      expect(Arrays.equals(a1, a1)).toBeTruthy
      expect(Arrays.equals(a1, Array[Char]('a', '0', '-'))).toBeTruthy

      expect(Arrays.equals(a1, null)).toBeFalsy
      expect(Arrays.equals(a1, Array[Char]('z'))).toBeFalsy
      expect(Arrays.equals(a1, Array[Char]('a'))).toBeFalsy
      expect(Arrays.equals(a1, Array[Char]())).toBeFalsy
      expect(Arrays.equals(a1, Array[Char]('a', '0', '+'))).toBeFalsy
      expect(Arrays.equals(a1, Array[Char]('a', '0', '-', 'z'))).toBeFalsy
    }

    it("should respond to `equals` for Shorts") {
      val a1 = Array[Short](1, -7, 10)

      expect(Arrays.equals(null: Array[Short], null: Array[Short])).toBeTruthy
      expect(Arrays.equals(a1, a1)).toBeTruthy
      expect(Arrays.equals(a1, Array[Short](1, -7, 10))).toBeTruthy

      expect(Arrays.equals(a1, null)).toBeFalsy
      expect(Arrays.equals(a1, Array[Short](3))).toBeFalsy
      expect(Arrays.equals(a1, Array[Short](1))).toBeFalsy
      expect(Arrays.equals(a1, Array[Short]())).toBeFalsy
      expect(Arrays.equals(a1, Array[Short](1, -7, 11))).toBeFalsy
      expect(Arrays.equals(a1, Array[Short](1, -7, 11, 20))).toBeFalsy
    }

    it("should respond to `equals` for Ints") {
      val a1 = Array[Int](1, -7, 10)

      expect(Arrays.equals(null: Array[Int], null: Array[Int])).toBeTruthy
      expect(Arrays.equals(a1, a1)).toBeTruthy
      expect(Arrays.equals(a1, Array[Int](1, -7, 10))).toBeTruthy

      expect(Arrays.equals(a1, null)).toBeFalsy
      expect(Arrays.equals(a1, Array[Int](3))).toBeFalsy
      expect(Arrays.equals(a1, Array[Int](1))).toBeFalsy
      expect(Arrays.equals(a1, Array[Int]())).toBeFalsy
      expect(Arrays.equals(a1, Array[Int](1, -7, 11))).toBeFalsy
      expect(Arrays.equals(a1, Array[Int](1, -7, 11, 20))).toBeFalsy
    }

    it("should respond to `equals` for Longs") {
      val a1 = Array[Long](1L, -7L, 10L)

      expect(Arrays.equals(null: Array[Long], null: Array[Long])).toBeTruthy
      expect(Arrays.equals(a1, a1)).toBeTruthy
      expect(Arrays.equals(a1, Array[Long](1L, -7L, 10L))).toBeTruthy

      expect(Arrays.equals(a1, null)).toBeFalsy
      expect(Arrays.equals(a1, Array[Long](3L))).toBeFalsy
      expect(Arrays.equals(a1, Array[Long](1L))).toBeFalsy
      expect(Arrays.equals(a1, Array[Long]())).toBeFalsy
      expect(Arrays.equals(a1, Array[Long](1L, -7L, 11L))).toBeFalsy
      expect(Arrays.equals(a1, Array[Long](1L, -7L, 11L, 20L))).toBeFalsy
    }

    it("should respond to `equals` for Floats") {
      val a1 = Array[Float](1.1f, -7.4f, 10.0f)

      expect(Arrays.equals(null: Array[Float], null: Array[Float])).toBeTruthy
      expect(Arrays.equals(a1, a1)).toBeTruthy
      expect(Arrays.equals(a1, Array[Float](1.1f, -7.4f, 10.0f))).toBeTruthy

      expect(Arrays.equals(a1, null)).toBeFalsy
      expect(Arrays.equals(a1, Array[Float](3.0f))).toBeFalsy
      expect(Arrays.equals(a1, Array[Float](1.1f))).toBeFalsy
      expect(Arrays.equals(a1, Array[Float]())).toBeFalsy
      expect(Arrays.equals(a1, Array[Float](1.1f, -7.4f, 11.0f))).toBeFalsy
      expect(Arrays.equals(a1, Array[Float](1.1f, -7.4f, 10.0f, 20.0f))).toBeFalsy
    }

    it("should respond to `equals` for Doubles") {
      val a1 = Array[Double](1.1, -7.4, 10.0)

      expect(Arrays.equals(null: Array[Double], null: Array[Double])).toBeTruthy
      expect(Arrays.equals(a1, a1)).toBeTruthy
      expect(Arrays.equals(a1, Array[Double](1.1, -7.4, 10.0))).toBeTruthy

      expect(Arrays.equals(a1, null)).toBeFalsy
      expect(Arrays.equals(a1, Array[Double](3.0))).toBeFalsy
      expect(Arrays.equals(a1, Array[Double](1.1))).toBeFalsy
      expect(Arrays.equals(a1, Array[Double]())).toBeFalsy
      expect(Arrays.equals(a1, Array[Double](1.1, -7.4, 11.0))).toBeFalsy
      expect(Arrays.equals(a1, Array[Double](1.1, -7.4, 10.0, 20.0))).toBeFalsy
    }

    it("should respond to `equals` for AnyRefs") {
      class A(private val x: Int) {
        override def equals(that: Any) = that match {
          case that: A => this.x == that.x
          case _ => false
        }
      }

      def A(x: Int) = new A(x)

      val a1 = Array[AnyRef](A(1), A(-7), A(10))

      expect(Arrays.equals(null: Array[AnyRef], null: Array[AnyRef])).toBeTruthy
      expect(Arrays.equals(a1, a1)).toBeTruthy
      expect(Arrays.equals(a1, Array[AnyRef](A(1), A(-7), A(10)))).toBeTruthy

      expect(Arrays.equals(a1, null)).toBeFalsy
      expect(Arrays.equals(a1, Array[AnyRef](A(3)))).toBeFalsy
      expect(Arrays.equals(a1, Array[AnyRef](A(1)))).toBeFalsy
      expect(Arrays.equals(a1, Array[AnyRef]())).toBeFalsy
      expect(Arrays.equals(a1, Array[AnyRef](A(1), null, A(11)))).toBeFalsy
      expect(Arrays.equals(a1, Array[AnyRef](A(1), A(-7), A(11), A(20)))).toBeFalsy
    }

  }

}