aboutsummaryrefslogtreecommitdiff
path: root/tests/parallelism.scm
blob: 7d8dea7293298093727d364ea242c9d7323c60bb (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(use-modules (tests)
             (fibers)
             (unit-test)
             (knots parallelism))

;; Test fibers-map
(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
    '(()))))

(display "parallelism test finished successfully\n")