bitvectors.test 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ;;;; bitvectors.test --- tests guile's bitvectors -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright 2010, 2011 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 3 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-bitvectors)
  19. #:use-module (test-suite lib))
  20. (with-test-prefix "predicates"
  21. (pass-if (bitvector? #*1010101010))
  22. (pass-if (generalized-vector? #*1010101010))
  23. (pass-if (uniform-vector? #*1010101010))
  24. (pass-if (array? #*1010101010)))
  25. (with-test-prefix "equality"
  26. (pass-if (equal? #*1010101 #*1010101))
  27. (pass-if (array-equal? #*1010101 #*1010101))
  28. (pass-if (not (equal? #*10101010 #*1010101)))
  29. (pass-if (not (array-equal? #*10101010 #*1010101))))
  30. (with-test-prefix "lists"
  31. (pass-if (equal? (bitvector->list #*10010) '(#t #f #f #t #f)))
  32. (pass-if (equal? (array->list #*10010) '(#t #f #f #t #f)))
  33. (pass-if (equal? (uniform-vector->list #*10010) '(#t #f #f #t #f)))
  34. (pass-if (equal? #*10010 (list->bitvector '(#t #f #f #t #f)))))
  35. (with-test-prefix "ref and set"
  36. (with-test-prefix "bv"
  37. (let ((bv (list->bitvector '(#f #f #t #f #t))))
  38. (pass-if (eqv? (bitvector-ref bv 0) #f))
  39. (pass-if (eqv? (bitvector-ref bv 2) #t))
  40. (bitvector-set! bv 0 #t)
  41. (pass-if (eqv? (bitvector-ref bv 0) #t))))
  42. (with-test-prefix "uv"
  43. (let ((bv (list->bitvector '(#f #f #t #f #t))))
  44. (pass-if (eqv? (uniform-vector-ref bv 0) #f))
  45. (pass-if (eqv? (uniform-vector-ref bv 2) #t))
  46. (uniform-vector-set! bv 0 #t)
  47. (pass-if (eqv? (uniform-vector-ref bv 0) #t)))))
  48. (with-test-prefix "bit-set*!"
  49. (pass-if "#t"
  50. (let ((v (bitvector #t #t #f #f)))
  51. (bit-set*! v #*1010 #t)
  52. (equal? v #*1110)))
  53. (pass-if "#f"
  54. (let ((v (bitvector #t #t #f #f)))
  55. (bit-set*! v #*1010 #f)
  56. (equal? v #*0100)))
  57. (pass-if "#t, shorter"
  58. (let ((v (bitvector #t #t #f #f)))
  59. (bit-set*! v #*101 #t)
  60. (equal? v #*1110)))
  61. (pass-if "#f, shorter"
  62. (let ((v (bitvector #t #t #f #f)))
  63. (bit-set*! v #*101 #f)
  64. (equal? v #*0100))))