test-bitwise.scm 1.9 KB

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