diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-04-12 13:30:32 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-04-21 21:16:45 +0200 |
commit | ed4281ff072443167c43207c039570126061d23b (patch) | |
tree | 3c5c0c73a43935d19cc12bd39036b08b7dd4230b /tests/test/srfi-41-util.scm | |
parent | Allow tests in subdirs. (diff) | |
download | calp-ed4281ff072443167c43207c039570126061d23b.tar.gz calp-ed4281ff072443167c43207c039570126061d23b.tar.xz |
Add a lot of new unit tests.
Diffstat (limited to 'tests/test/srfi-41-util.scm')
-rw-r--r-- | tests/test/srfi-41-util.scm | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/tests/test/srfi-41-util.scm b/tests/test/srfi-41-util.scm index 176fb38e..12eccac5 100644 --- a/tests/test/srfi-41-util.scm +++ b/tests/test/srfi-41-util.scm @@ -6,14 +6,8 @@ (define-module (test srfi-41-util) :use-module (srfi srfi-64) :use-module (srfi srfi-88) - :use-module ((srfi srfi-41 util) :select (stream-paginate)) - :use-module ((srfi srfi-41) - :select (stream->list - stream-ref - stream-from - stream-filter - stream-car - stream)) + :use-module (srfi srfi-41 util) + :use-module (srfi srfi-41) :use-module ((ice-9 sandbox) :select (call-with-time-limit))) (test-equal "Finite stream" @@ -42,3 +36,51 @@ (lambda _ unique-symbol)))) + + +(test-equal "stream insert" + '(1 4 5 7 8) + (stream->list (stream-insert < 5 (stream 1 4 7 8)))) + + +(test-equal "Filter sorted stream" + '(4 6 8) + (stream->list (filter-sorted-stream even? (stream 1 3 4 6 8 9 11)))) + +(test-equal "Filter sorted stream (which actually is unsorted)" + '(4 6 8) + (stream->list (filter-sorted-stream even? (stream 1 3 4 6 8 9 11 12)))) + +;; TODO filter-sorted-stream* + +(test-equal + "Get stream interval" + '(5 6 7 8 9) + (stream->list (get-stream-interval (lambda (x) (< 4 x)) + (lambda (x) (< x 10)) + (stream 1 2 3 4 5 6 7 8 9 10 11 12)))) + + + +(test-equal "stream find" 2 (stream-find even? (stream-from 1))) + + +(test-equal + "repeating naturals" + '(1 1 1 2 2 2 3 3 3 4) + (stream->list 10 (repeating-naturals 1 3))) + + +;; sleep will return early if a singal arrives, this just resumes sleeping until +;; the wanted time is hit. +;; Might sleep longer since sleep always returns a whole number of seconds remaining +(define (true-sleep n) + (let loop ((remaining n)) + (unless (zero? remaining) + (loop (sleep remaining))))) + +(let ((strm (stream-map (lambda (x) (when (zero? (modulo x 4)) (true-sleep 1)) x) (stream-from 1)))) + (let ((strm (stream-timeslice-limit strm 0.1))) + (test-equal "time limited stream" + '(1 2 3) + (stream->list strm)))) |