q.test 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. ;;;; q.test --- test (ice-9 q) module -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright 2004, 2006 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 2.1 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-ice-9-q)
  19. #:use-module (test-suite lib)
  20. #:use-module (ice-9 q))
  21. ;; Call (THUNK) and return #t if it throws 'q-empty, or #f it not.
  22. (define (true-if-catch-q-empty thunk)
  23. (catch 'q-empty
  24. (lambda ()
  25. (thunk)
  26. #f)
  27. (lambda args
  28. #t)))
  29. ;;;
  30. ;;; q-pop!
  31. ;;;
  32. (with-test-prefix "q-pop!"
  33. (with-test-prefix "no elems"
  34. (let ((q (make-q)))
  35. (pass-if "empty" (true-if-catch-q-empty
  36. (lambda ()
  37. (q-pop! q))))
  38. (pass-if "valid at end" (q? q))))
  39. (with-test-prefix "one elem"
  40. (let ((x (cons 1 2))
  41. (q (make-q)))
  42. (q-push! q x)
  43. (pass-if "x" (eq? x (q-pop! q)))
  44. (pass-if "valid after x" (q? q))
  45. (pass-if "empty" (true-if-catch-q-empty
  46. (lambda ()
  47. (q-pop! q))))
  48. (pass-if "valid at end" (q? q))))
  49. (with-test-prefix "two elems"
  50. (let ((x (cons 1 2))
  51. (y (cons 3 4))
  52. (q (make-q)))
  53. (q-push! q x)
  54. (q-push! q y)
  55. (pass-if "y" (eq? y (q-pop! q)))
  56. (pass-if "valid after y" (q? q))
  57. (pass-if "x" (eq? x (q-pop! q)))
  58. (pass-if "valid after x" (q? q))
  59. (pass-if "empty" (true-if-catch-q-empty
  60. (lambda ()
  61. (q-pop! q))))
  62. (pass-if "valid at end" (q? q))))
  63. (with-test-prefix "three elems"
  64. (let ((x (cons 1 2))
  65. (y (cons 3 4))
  66. (z (cons 5 6))
  67. (q (make-q)))
  68. (q-push! q x)
  69. (q-push! q y)
  70. (q-push! q z)
  71. (pass-if "z" (eq? z (q-pop! q)))
  72. (pass-if "valid after z" (q? q))
  73. (pass-if "y" (eq? y (q-pop! q)))
  74. (pass-if "valid after y" (q? q))
  75. (pass-if "x" (eq? x (q-pop! q)))
  76. (pass-if "valid after x" (q? q))
  77. (pass-if "empty" (true-if-catch-q-empty
  78. (lambda ()
  79. (q-pop! q))))
  80. (pass-if "valid at end" (q? q)))))