Add test for generator functions

This commit is contained in:
Dane Johnson 2024-11-11 21:35:26 -06:00
parent 87384f611c
commit 224fcc425c

View File

@ -1,5 +1,6 @@
(use-modules (d-)
(rnrs base))
(rnrs base)
(srfi srfi-1))
(define-syntax-rule (define-unit-test (test-name body ...))
(let () body ...))
@ -54,3 +55,15 @@
(define-test argmin
(test
(assert (equal? (argmin cdr < '(a . 5) '(b . 2) '(c . 3)) '(b . 2)))))
(define-test make-generator
(test
(define number-generator
(make-generator (lambda (yield)
(let loop ([i 1])
(yield i)
(loop (1+ i))))))
(assert (= (number-generator) 1))
(assert (= (number-generator) 2))
(assert (= (number-generator) 3))
(assert (= (number-generator) 4))))