java-array-test.scm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. (test-begin "java-array" 33)
  2. (define obj1 ::Object (Object))
  3. (define obj2 ::Object (Object))
  4. (define obj-arr1 ::Object[] [obj1 #!null obj2])
  5. (define obj-arr2 ::Object[] [obj1 #!null])
  6. (define boolean-arr ::boolean[] [#t #f])
  7. (define byte-arr ::byte[] [1 2 3])
  8. (define char-arr ::char[] [#\1 #\2 #\3])
  9. (define double-arr ::double[] [1 2 3])
  10. (define float-arr ::float[] [1 2 3])
  11. (define int-arr ::int[] [1 2 3])
  12. (define long-arr ::long[] [1 2 3])
  13. (define short-arr ::short[] [1 2 3])
  14. ;;; array vs non-array => #f
  15. (test-equal #f (equal? obj-arr1 obj1))
  16. ;;; different array lengths => #f
  17. (test-equal #f (equal? obj-arr1 obj-arr2))
  18. ;;; different array types => #f
  19. (test-equal #f (equal? (Object[]) (byte[])))
  20. (define str1 ::String "hello")
  21. (define str2 ::string (string #\h #\e #\l #\l #\o))
  22. (test-equal #f (equal? (Object[] str1) (String[] str1)))
  23. (test-equal #f (equal? (String[] str1 #!null str2)
  24. (string[] str2 #!null str1)))
  25. ;;; primitive arrays are equal if their values are equal
  26. (test-equal (boolean[] #t #f) boolean-arr)
  27. (let ((vals ::list '(1 2 3)))
  28. (test-equal (apply byte[] vals) byte-arr)
  29. (test-equal #f (equal? (apply char[] (map integer->char vals)) char-arr))
  30. (test-equal (apply double[] vals) double-arr)
  31. (test-equal (apply float[] vals) float-arr)
  32. (test-equal (apply int[] vals) int-arr)
  33. (test-equal (apply long[] vals) long-arr)
  34. (test-equal (apply short[] vals) short-arr))
  35. (define bytes ::byte[] (byte[] length: 4))
  36. (do ((i 0 (+ i 1)))
  37. ((= i bytes:length))
  38. (set! (bytes i) i))
  39. (test-equal (byte[] 0 1 2 3) bytes)
  40. ;;; object arrays are equal iff all elements are equal
  41. (test-equal (String[] str1 str2 #!null)
  42. (String[] str1 str2 #!null))
  43. (test-equal #f (equal? (Object[] str1 #!null) (Object[] str1 str2)))
  44. (test-equal (Object[] str1) (Object[] str2))
  45. (test-equal (short[][] [1 2 3] [1 2 3]) (short[][] short-arr short-arr))
  46. (test-equal #f (equal? (Object[] obj1) (Object[] obj2)))
  47. (test-equal 5 (apply - (vector 10 4 1)))
  48. (test-equal 5 (apply - (object[] 10 4 1)))
  49. (test-equal 85 (apply - 100 (object[] 10 4 1)))
  50. (test-equal 5 (apply - (integer[] 10 4 1)))
  51. (test-equal 85 (apply - 100 (integer[] 10 4 1)))
  52. (test-equal 5 (apply - (short[] 10 4 1)))
  53. (test-equal 85 (apply - 100 (short[] 10 4 1)))
  54. (test-equal 5.0d+0 (apply - (double[] 10 4 1)))
  55. (test-equal 85.0d+0 (apply - 100 (double[] 10 4 1)))
  56. (test-equal (int[] 1 2 3) (int-arr:clone))
  57. (! arrb1 (boolean[] #f #t #t #f))
  58. (! vecb1 (->bitvector arrb1))
  59. (test-equal #f (vecb1 3))
  60. (set! (arrb1 3) #t)
  61. (test-equal vecb1 (bitvector #f #t #t #t))
  62. (test-equal #t (vecb1 3))
  63. (set! (vecb1 1) #f)
  64. (test-equal vecb1 (bitvector #f #f #t #t))
  65. (test-end)