ramap.test 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. ;;;; ramap.test --- test array mapping functions -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
  4. ;;;;
  5. ;;;; This library is free software; you can redistribute it and/or
  6. ;;;; modify it under the terms of the GNU Lesser General Public
  7. ;;;; License as published by the Free Software Foundation; either
  8. ;;;; version 2.1 of the License, or (at your option) any later version.
  9. ;;;;
  10. ;;;; This library is distributed in the hope that it will be useful,
  11. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. ;;;; Lesser General Public License for more details.
  14. ;;;;
  15. ;;;; You should have received a copy of the GNU Lesser General Public
  16. ;;;; License along with this library; if not, write to the Free Software
  17. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. (define-module (test-suite test-ramap)
  19. #:use-module (test-suite lib))
  20. ;;;
  21. ;;; array-index-map!
  22. ;;;
  23. (with-test-prefix "array-index-map!"
  24. (pass-if (let ((nlst '()))
  25. (array-index-map! (make-array #f '(1 1))
  26. (lambda (n)
  27. (set! nlst (cons n nlst))))
  28. (equal? nlst '(1)))))
  29. ;;;
  30. ;;; array-map!
  31. ;;;
  32. (with-test-prefix "array-map!"
  33. (pass-if-exception "no args" exception:wrong-num-args
  34. (array-map!))
  35. (pass-if-exception "one arg" exception:wrong-num-args
  36. (array-map! (make-array #f 5)))
  37. (with-test-prefix "no sources"
  38. (pass-if "closure 0"
  39. (array-map! (make-array #f 5) (lambda () #f))
  40. #t)
  41. (pass-if-exception "closure 1" exception:wrong-num-args
  42. (array-map! (make-array #f 5) (lambda (x) #f)))
  43. (pass-if-exception "closure 2" exception:wrong-num-args
  44. (array-map! (make-array #f 5) (lambda (x y) #f)))
  45. (pass-if-exception "subr_1" exception:wrong-num-args
  46. (array-map! (make-array #f 5) length))
  47. (pass-if-exception "subr_2" exception:wrong-num-args
  48. (array-map! (make-array #f 5) logtest))
  49. (pass-if-exception "subr_2o" exception:wrong-num-args
  50. (array-map! (make-array #f 5) number->string))
  51. (pass-if-exception "dsubr" exception:wrong-num-args
  52. (array-map! (make-array #f 5) $sqrt))
  53. (pass-if "rpsubr"
  54. (let ((a (make-array 'foo 5)))
  55. (array-map! a =)
  56. (equal? a (make-array #t 5))))
  57. (pass-if "asubr"
  58. (let ((a (make-array 'foo 5)))
  59. (array-map! a +)
  60. (equal? a (make-array 0 5))))
  61. ;; in Guile 1.6.4 and earlier this resulted in a segv
  62. (pass-if "noop"
  63. (array-map! (make-array #f 5) noop)
  64. #t))
  65. (with-test-prefix "one source"
  66. (pass-if-exception "closure 0" exception:wrong-num-args
  67. (array-map! (make-array #f 5) (lambda () #f)
  68. (make-array #f 5)))
  69. (pass-if "closure 1"
  70. (let ((a (make-array #f 5)))
  71. (array-map! a (lambda (x) 'foo) (make-array #f 5))
  72. (equal? a (make-array 'foo 5))))
  73. (pass-if-exception "closure 2" exception:wrong-num-args
  74. (array-map! (make-array #f 5) (lambda (x y) #f)
  75. (make-array #f 5)))
  76. (pass-if "subr_1"
  77. (let ((a (make-array #f 5)))
  78. (array-map! a length (make-array '(x y z) 5))
  79. (equal? a (make-array 3 5))))
  80. (pass-if-exception "subr_2" exception:wrong-num-args
  81. (array-map! (make-array #f 5) logtest
  82. (make-array 999 5)))
  83. (pass-if "subr_2o"
  84. (let ((a (make-array #f 5)))
  85. (array-map! a number->string (make-array 99 5))
  86. (equal? a (make-array "99" 5))))
  87. (pass-if "dsubr"
  88. (let ((a (make-array #f 5)))
  89. (array-map! a $sqrt (make-array 16.0 5))
  90. (equal? a (make-array 4.0 5))))
  91. (pass-if "rpsubr"
  92. (let ((a (make-array 'foo 5)))
  93. (array-map! a = (make-array 0 5))
  94. (equal? a (make-array #t 5))))
  95. (pass-if "asubr"
  96. (let ((a (make-array 'foo 5)))
  97. (array-map! a - (make-array 99 5))
  98. (equal? a (make-array -99 5))))
  99. ;; in Guile 1.6.5 and 1.6.6 this was an error
  100. (pass-if "1+"
  101. (let ((a (make-array #f 5)))
  102. (array-map! a 1+ (make-array 123 5))
  103. (equal? a (make-array 124 5)))))
  104. (with-test-prefix "two sources"
  105. (pass-if-exception "closure 0" exception:wrong-num-args
  106. (array-map! (make-array #f 5) (lambda () #f)
  107. (make-array #f 5) (make-array #f 5)))
  108. (pass-if-exception "closure 1" exception:wrong-num-args
  109. (array-map! (make-array #f 5) (lambda (x) #f)
  110. (make-array #f 5) (make-array #f 5)))
  111. (pass-if "closure 2"
  112. (let ((a (make-array #f 5)))
  113. (array-map! a (lambda (x y) 'foo)
  114. (make-array #f 5) (make-array #f 5))
  115. (equal? a (make-array 'foo 5))))
  116. (pass-if-exception "subr_1" exception:wrong-type-arg
  117. (array-map! (make-array #f 5) length
  118. (make-array #f 5) (make-array #f 5)))
  119. (pass-if "subr_2"
  120. (let ((a (make-array 'foo 5)))
  121. (array-map! a logtest
  122. (make-array 999 5) (make-array 999 5))
  123. (equal? a (make-array #t 5))))
  124. (pass-if "subr_2o"
  125. (let ((a (make-array #f 5)))
  126. (array-map! a number->string
  127. (make-array 32 5) (make-array 16 5))
  128. (equal? a (make-array "20" 5))))
  129. (pass-if "dsubr"
  130. (let ((a (make-array #f 5)))
  131. (array-map! a $sqrt
  132. (make-array 16.0 5) (make-array 16.0 5))
  133. (equal? a (make-array 4.0 5))))
  134. (pass-if "rpsubr"
  135. (let ((a (make-array 'foo 5)))
  136. (array-map! a = (make-array 99 5) (make-array 77 5))
  137. (equal? a (make-array #f 5))))
  138. (pass-if "asubr"
  139. (let ((a (make-array 'foo 5)))
  140. (array-map! a - (make-array 99 5) (make-array 11 5))
  141. (equal? a (make-array 88 5))))
  142. (pass-if "+"
  143. (let ((a (make-array #f 4)))
  144. (array-map! a + #(1 2 3 4) #(5 6 7 8))
  145. (equal? a #(6 8 10 12))))))