From 4e791aff6814e38da8b431b8ddb8444a32e34fe6 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 27 Dec 2024 22:14:51 +0000 Subject: [PATCH] Fix a bug in fibers-batch-map (and related procedures) And add more tests. --- knots/parallelism.scm | 5 ++++- tests/parallelism.scm | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/knots/parallelism.scm b/knots/parallelism.scm index 9331757..8f3ec39 100644 --- a/knots/parallelism.scm +++ b/knots/parallelism.scm @@ -79,7 +79,10 @@ (define result-vec (make-vector vecs-length)) - (let loop ((next-to-process-index 0) + (let loop ((next-to-process-index + (if (= 0 vecs-length) + #f + 0)) (channel-indexes '())) (if (and (eq? #f next-to-process-index) (null? channel-indexes)) diff --git a/tests/parallelism.scm b/tests/parallelism.scm index 0901b3c..7d8dea7 100644 --- a/tests/parallelism.scm +++ b/tests/parallelism.scm @@ -24,6 +24,16 @@ 100 (iota 34)))))) +;; Test fibers-map with an empty list +(run-fibers-for-tests + (lambda () + (fibers-map identity '()))) + +;; Test fibers-map with an empty vector +(run-fibers-for-tests + (lambda () + (fibers-map identity #()))) + ;; Test fibers-map with vectors (run-fibers-for-tests (lambda () @@ -43,4 +53,11 @@ (* 2 i)) (iota 34)))) +;; Test fibers-map-with-progress with an empty list +(run-fibers-for-tests + (lambda () + (fibers-map-with-progress + identity + '(())))) + (display "parallelism test finished successfully\n")