test-vectors.scm 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. ;;; Copyright (C) 2023 Igalia, S.L.
  2. ;;;
  3. ;;; Licensed under the Apache License, Version 2.0 (the "License");
  4. ;;; you may not use this file except in compliance with the License.
  5. ;;; You may obtain a copy of the License at
  6. ;;;
  7. ;;; http://www.apache.org/licenses/LICENSE-2.0
  8. ;;;
  9. ;;; Unless required by applicable law or agreed to in writing, software
  10. ;;; distributed under the License is distributed on an "AS IS" BASIS,
  11. ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. ;;; See the License for the specific language governing permissions and
  13. ;;; limitations under the License.
  14. ;;; Commentary:
  15. ;;;
  16. ;;; Vector tests.
  17. ;;;
  18. ;;; Code:
  19. (use-modules (srfi srfi-64)
  20. (test utils))
  21. (test-begin "test-vectors")
  22. (test-call "#(1 2 3)" (lambda (a b c) (vector a b c)) 1 2 3)
  23. (test-call "3" (lambda (v) (vector-ref v 2)) #(1 2 3))
  24. (test-call "2" (lambda (v idx) (vector-ref v idx)) #(1 2 3) 1)
  25. (test-call "#(42 42 42)" (lambda (n) (make-vector n 42)) 3)
  26. (test-call "#t" (lambda (a b) (equal? a b)) #() #())
  27. (test-call "#t" (lambda (a b) (equal? a b)) #(1 2) #(1 2))
  28. (test-call "#f" (lambda (a b) (equal? a b)) #() #(1))
  29. (test-call "#f" (lambda (a b) (equal? a b)) #(1 2) #(2 1))
  30. ;; Vectors with cycles
  31. (test-call "#t" (lambda ()
  32. (let ((x (vector 'a 'b 'c #f))
  33. (y (vector 'a 'b 'c #f)))
  34. (vector-set! x 3 x)
  35. (vector-set! y 3 y)
  36. (equal? x y))))
  37. (test-call "#f" (lambda ()
  38. (let ((x (vector 'a 'b 'c #f))
  39. (y (vector 'a 'b #f)))
  40. (vector-set! x 3 x)
  41. (vector-set! y 2 y)
  42. (equal? x y))))
  43. (with-additional-imports ((only (hoot vectors) vector-sort!))
  44. (test-call "#(4 4 7 8 9 9 10 12 12 13 15 17 18 18 19 19 19 21 21 21 24 24 24 25 25 26 27 28 30 34 35 35 35 35 37 38 39 41 43 43 45 46 48 49 49 52 52 53 53 54 54 55 55 56 56 57 57 58 61 61 62 62 63 64 64 65 66 67 67 69 69 69 73 73 77 79 79 79 80 80 80 84 84 84 85 85 87 87 88 88 89 91 92 95 95 96 96 97 98 99)"
  45. (lambda (v)
  46. (vector-sort! v <)
  47. v)
  48. (vector 56 19 80 52 18 37 13 63 96 30 79 84 18 64 53 67 8 24 85
  49. 21 79 62 55 17 21 58 26 73 46 10 69 48 15 4 45 96 89 88
  50. 35 9 35 97 69 43 92 61 56 61 52 80 95 84 88 24 4 7 91 80
  51. 66 77 39 12 85 69 34 57 35 62 38 28 95 79 84 65 25 99 43
  52. 54 27 9 54 57 53 87 25 87 49 35 12 49 19 98 24 64 21 19
  53. 67 41 55 73)))
  54. (test-end* "test-vectors")