test-bitwise.scm 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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: re-enable this test when we bump to Guile
  29. ;; v3.0.10-31-g7aa4cfa9d or later.
  30. ;; (test-call "8" (lambda (a b) (logand a (lognot b))) #b1100 #b0100)
  31. (test-call "0" (lambda (x n) (ash x n)) 1 -2)
  32. (test-call "-1" (lambda (x n) (ash x n)) -1 -1)
  33. (test-call "16" (lambda (x n) (ash x n)) 32 -1)
  34. (test-call "0" (lambda (x n) (ash x n)) 32 -64)
  35. (test-call "4" (lambda (x n) (ash x n)) 1 2)
  36. (test-call "-2" (lambda (x n) (ash x n)) -1 1)
  37. (test-call "64" (lambda (x n) (ash x n)) 32 1)
  38. ;; lsh/immediate
  39. (test-call "8589934592" (lambda (x) (ash x 33)) 1)
  40. (test-call "-2" (lambda (x) (ash x 1)) -1)
  41. (test-call "-1" (lambda (x) (ash x -1)) -1)
  42. (test-call "18446744073709551616" (lambda (x y) (ash x y)) 1 64)
  43. (test-call "0" (lambda (x y z) (ash (+ x y) z)) 536870911 1 -64)
  44. ;; Bitvector equality
  45. (test-call "#t" (lambda (a b) (equal? a b)) #* #*)
  46. (test-call "#t" (lambda (a b) (equal? a b)) #*10 #*10)
  47. (test-call "#f" (lambda (a b) (equal? a b)) #* #*1)
  48. (test-call "#f" (lambda (a b) (equal? a b)) #*10 #*01)
  49. (test-call "#f" (lambda (a b) (equal? a b)) #*100 #*101))
  50. (test-end* "test-bitwise")