guile-knots/tests/parallelism.scm

97 lines
2.2 KiB
Scheme
Raw Normal View History

2024-11-19 18:43:43 +00:00
(use-modules (tests)
(fibers)
(unit-test)
2025-03-08 09:39:27 +00:00
(ice-9 exceptions)
2024-11-19 18:43:43 +00:00
(knots parallelism))
;; Test fibers-map
2024-11-19 18:43:43 +00:00
(run-fibers-for-tests
(lambda ()
(assert-equal
1122
(apply + (fibers-map
(lambda (i)
(* 2 i))
(iota 34))))))
;; Test fibers-batch-map with a large batch size
(run-fibers-for-tests
(lambda ()
(assert-equal
1122
(apply + (fibers-batch-map
(lambda (i)
(* 2 i))
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 ()
(assert-equal
1122
(apply + (vector->list
(fibers-map
(lambda (i)
(* 2 i))
(list->vector (iota 34))))))))
;; Test fibers-for-each
(run-fibers-for-tests
(lambda ()
(fibers-for-each
(lambda (i)
(* 2 i))
(iota 34))))
;; Test fibers-map-with-progress with an empty list
(run-fibers-for-tests
(lambda ()
(fibers-map-with-progress
identity
'(()))))
2025-03-08 09:39:27 +00:00
(run-fibers-for-tests
(lambda ()
(with-exception-handler
(lambda (exn)
(unless (and (exception-with-message? exn)
(string=? (exception-message exn)
"foo"))
(raise-exception exn)))
(lambda ()
(fibers-for-each
(lambda (i)
(raise-exception
(make-exception-with-message "foo")))
(iota 2)))
#:unwind? #t)))
(run-fibers-for-tests
(lambda ()
(with-exception-handler
(lambda (exn)
(unless (and (exception-with-message? exn)
(string=? (exception-message exn)
"foo"))
(raise-exception exn)))
(lambda ()
((fiberize
(lambda (i)
(raise-exception
(make-exception-with-message "foo"))))
1))
#:unwind? #t)))
2024-11-19 18:43:43 +00:00
(display "parallelism test finished successfully\n")