r6rs-arithmetic-bitwise.test 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ;;; arithmetic-bitwise.test --- Test suite for R6RS (rnrs arithmetic bitwise)
  2. ;; Copyright (C) 2010, 2013 Free Software Foundation, Inc.
  3. ;;
  4. ;; This library is free software; you can redistribute it and/or
  5. ;; modify it under the terms of the GNU Lesser General Public
  6. ;; License as published by the Free Software Foundation; either
  7. ;; version 3 of the License, or (at your option) any later version.
  8. ;;
  9. ;; This library is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ;; Lesser General Public License for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU Lesser General Public
  15. ;; License along with this library; if not, write to the Free Software
  16. ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. (define-module (test-suite test-r6rs-arithmetic-bitwise)
  18. :use-module ((rnrs arithmetic bitwise) :version (6))
  19. :use-module (test-suite lib))
  20. (with-test-prefix "bitwise-not"
  21. (pass-if "bitwise-not simple"
  22. (eqv? (bitwise-not 3) -4)))
  23. (with-test-prefix "bitwise-and"
  24. (pass-if "bitwise-and simple"
  25. (eqv? (bitwise-and #b101 #b110) #b100)))
  26. (with-test-prefix "bitwise-ior"
  27. (pass-if "bitwise-ior simple"
  28. (eqv? (bitwise-ior #b010 #b100) #b110)))
  29. (with-test-prefix "bitwise-xor"
  30. (pass-if "bitwise-xor simple"
  31. (eqv? (bitwise-xor #b101 #b100) #b001)))
  32. (with-test-prefix "bitwise-if"
  33. (pass-if "bitwise-if simple"
  34. (eqv? (bitwise-if #b101 #b011 #b100) #b001)))
  35. (with-test-prefix "bitwise-bit-count"
  36. (pass-if "bitwise-bit-count simple"
  37. (eqv? (bitwise-bit-count #b101) 2))
  38. (pass-if "bitwise-bit-count negative"
  39. (eqv? (bitwise-bit-count #b-101) -2)))
  40. (with-test-prefix "bitwise-length"
  41. (pass-if "bitwise-length simple"
  42. (eqv? (bitwise-length #b101) 3))
  43. (pass-if "bitwise-length leading zeros"
  44. (eqv? (bitwise-length #b001) 1)))
  45. (with-test-prefix "bitwise-first-bit-set"
  46. (pass-if "bitwise-first-bit-set simple"
  47. (and (eqv? (bitwise-first-bit-set 1) 0)
  48. (eqv? (bitwise-first-bit-set -4) 2)))
  49. (pass-if "bitwise-first-bit-set zero"
  50. (and (eqv? (bitwise-first-bit-set 0) -1))))
  51. (with-test-prefix "bitwise-copy-bit"
  52. (pass-if "bitwise-copy-bit simple"
  53. (eqv? (bitwise-copy-bit #b010 2 1) #b110)))
  54. (with-test-prefix "bitwise-bit-field"
  55. (pass-if "bitwise-bit-field simple"
  56. (eqv? (bitwise-bit-field #b110010 1 4) #b001)))
  57. (with-test-prefix "bitwise-copy-bit-field"
  58. (pass-if "bitwise-copy-bit-field simple"
  59. (eqv? (bitwise-copy-bit-field #b11111111 2 6 #b1010) #b11101011)))
  60. (with-test-prefix "bitwise-arithmetic-shift"
  61. (pass-if "bitwise-arithmetic-shift simple"
  62. (and (eqv? (bitwise-arithmetic-shift -6 -1) -3)
  63. (eqv? (bitwise-arithmetic-shift -5 -1) -3)
  64. (eqv? (bitwise-arithmetic-shift -4 -1) -2)
  65. (eqv? (bitwise-arithmetic-shift -3 -1) -2)
  66. (eqv? (bitwise-arithmetic-shift -2 -1) -1)
  67. (eqv? (bitwise-arithmetic-shift -1 -1) -1))))
  68. (with-test-prefix "bitwise-arithmetic-shift-left"
  69. (pass-if "bitwise-arithmetic-shift-left simple"
  70. (eqv? (bitwise-arithmetic-shift-left -6 -1) -3)))
  71. (with-test-prefix "bitwise-arithmetic-shift-right"
  72. (pass-if "bitwise-arithmetic-shift-right simple"
  73. (eqv? (bitwise-arithmetic-shift-right -6 1) -3)))
  74. (with-test-prefix "bitwise-rotate-bit-field"
  75. (pass-if "bitwise-rotate-bit-field simple"
  76. (eqv? (bitwise-rotate-bit-field #b11100011 2 6 2) #b11001011)))
  77. (with-test-prefix "bitwise-reverse-bit-field"
  78. (pass-if "bitwise-reverse-bit-field simple"
  79. (eqv? (bitwise-reverse-bit-field #b1010010 1 4) #b1011000)))