streams.test 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ;;;; streams.test --- test Guile ice-9 streams module -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2004, 2006 Free Software Foundation, Inc.
  4. ;;;;
  5. ;;;; This program is free software; you can redistribute it and/or modify
  6. ;;;; it under the terms of the GNU General Public License as published by
  7. ;;;; the Free Software Foundation; either version 2, or (at your option)
  8. ;;;; any later version.
  9. ;;;;
  10. ;;;; This program 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
  13. ;;;; GNU General Public License for more details.
  14. ;;;;
  15. ;;;; You should have received a copy of the GNU General Public License
  16. ;;;; along with this software; see the file COPYING. If not, write to
  17. ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. ;;;; Boston, MA 02110-1301 USA
  19. (define-module (test-suite test-streams)
  20. :use-module (test-suite lib)
  21. :use-module (ice-9 streams))
  22. ;;;
  23. ;;; stream-for-each
  24. ;;;
  25. (with-test-prefix "stream-for-each"
  26. (with-test-prefix "1 streams"
  27. (pass-if "empty"
  28. (let ((lst '()))
  29. (stream-for-each (lambda (x)
  30. (set! lst (cons x lst)))
  31. (list->stream '()))
  32. (equal? '() lst)))
  33. (pass-if "123"
  34. (let ((lst '()))
  35. (stream-for-each (lambda (x)
  36. (set! lst (cons x lst)))
  37. (list->stream '(1 2 3)))
  38. (equal? '(3 2 1) lst))))
  39. (with-test-prefix "2 streams"
  40. (pass-if "empty empty"
  41. (let ((lst '()))
  42. (stream-for-each (lambda (x y)
  43. (set! lst (cons* x y lst)))
  44. (list->stream '())
  45. (list->stream '()))
  46. (equal? '() lst)))
  47. (pass-if "123 456"
  48. (let ((lst '()))
  49. (stream-for-each (lambda (x y)
  50. (set! lst (cons* x y lst)))
  51. (list->stream '(1 2 3))
  52. (list->stream '(4 5 6)))
  53. (equal? '(3 6 2 5 1 4) lst)))
  54. (pass-if "12 456"
  55. (let ((lst '()))
  56. (stream-for-each (lambda (x y)
  57. (set! lst (cons* x y lst)))
  58. (list->stream '(1 2))
  59. (list->stream '(4 5 6)))
  60. (equal? '(2 5 1 4) lst)))
  61. (pass-if "123 45"
  62. (let ((lst '()))
  63. (stream-for-each (lambda (x y)
  64. (set! lst (cons* x y lst)))
  65. (list->stream '(1 2 3))
  66. (list->stream '(4 5)))
  67. (equal? '(2 5 1 4) lst)))))