streams.test 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ;;;; streams.test --- test Guile ice-9 streams module -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 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 3 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-streams)
  19. :use-module (test-suite lib)
  20. :use-module (ice-9 streams))
  21. ;;;
  22. ;;; stream-for-each
  23. ;;;
  24. (with-test-prefix "stream-for-each"
  25. (with-test-prefix "1 streams"
  26. (pass-if "empty"
  27. (let ((lst '()))
  28. (stream-for-each (lambda (x)
  29. (set! lst (cons x lst)))
  30. (list->stream '()))
  31. (equal? '() lst)))
  32. (pass-if "123"
  33. (let ((lst '()))
  34. (stream-for-each (lambda (x)
  35. (set! lst (cons x lst)))
  36. (list->stream '(1 2 3)))
  37. (equal? '(3 2 1) lst))))
  38. (with-test-prefix "2 streams"
  39. (pass-if "empty empty"
  40. (let ((lst '()))
  41. (stream-for-each (lambda (x y)
  42. (set! lst (cons* x y lst)))
  43. (list->stream '())
  44. (list->stream '()))
  45. (equal? '() lst)))
  46. (pass-if "123 456"
  47. (let ((lst '()))
  48. (stream-for-each (lambda (x y)
  49. (set! lst (cons* x y lst)))
  50. (list->stream '(1 2 3))
  51. (list->stream '(4 5 6)))
  52. (equal? '(3 6 2 5 1 4) lst)))
  53. (pass-if "12 456"
  54. (let ((lst '()))
  55. (stream-for-each (lambda (x y)
  56. (set! lst (cons* x y lst)))
  57. (list->stream '(1 2))
  58. (list->stream '(4 5 6)))
  59. (equal? '(2 5 1 4) lst)))
  60. (pass-if "123 45"
  61. (let ((lst '()))
  62. (stream-for-each (lambda (x y)
  63. (set! lst (cons* x y lst)))
  64. (list->stream '(1 2 3))
  65. (list->stream '(4 5)))
  66. (equal? '(2 5 1 4) lst)))))