test-bitwise.scm 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ;;; Copyright (C) 2023, 2024 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. ;;; Bitwise operation tests.
  17. ;;;
  18. ;;; Code:
  19. (use-modules (srfi srfi-64)
  20. (test utils))
  21. (test-begin "test-bitwise")
  22. (with-additional-imports
  23. ((hoot bitwise))
  24. ;; FIXME: add tests with bignum arguments
  25. (test-call "8" (lambda (a b) (logand a b)) #b1100 #b1010)
  26. (test-call "14" (lambda (a b) (logior a b)) #b1100 #b1010)
  27. (test-call "6" (lambda (a b) (logxor a b)) #b1100 #b1010)
  28. ;; FIXME: logsub not accessible from scheme
  29. ;;(test-call "4" (lambda (a b) (logsub a b)) #b1100 #b1010)
  30. (test-call "0" (lambda (x n) (ash x n)) 1 -2)
  31. (test-call "-1" (lambda (x n) (ash x n)) -1 -1)
  32. (test-call "16" (lambda (x n) (ash x n)) 32 -1)
  33. (test-call "0" (lambda (x n) (ash x n)) 32 -64)
  34. (test-call "4" (lambda (x n) (ash x n)) 1 2)
  35. (test-call "-2" (lambda (x n) (ash x n)) -1 1)
  36. (test-call "64" (lambda (x n) (ash x n)) 32 1)
  37. (test-call "-2" (lambda (x) (ash x 1)) -1)
  38. (test-call "-1" (lambda (x) (ash x -1)) -1)
  39. (test-call "18446744073709551616" (lambda (x y) (ash x y)) 1 64)
  40. (test-call "0" (lambda (x y z) (ash (+ x y) z)) 536870911 1 -64)
  41. ;; Bitvector equality
  42. (test-call "#t" (lambda (a b) (equal? a b)) #* #*)
  43. (test-call "#t" (lambda (a b) (equal? a b)) #*10 #*10)
  44. (test-call "#f" (lambda (a b) (equal? a b)) #* #*1)
  45. (test-call "#f" (lambda (a b) (equal? a b)) #*10 #*01)
  46. (test-call "#f" (lambda (a b) (equal? a b)) #*100 #*101))
  47. (test-end* "test-bitwise")