]> gitweb.factorcode.org Git - factor.git/blob - basis/concurrency/combinators/combinators-tests.factor
core: Rename iota to <iota> so we can have TUPLE: iota ... ; instead of TUPLE: iota...
[factor.git] / basis / concurrency / combinators / combinators-tests.factor
1 USING: concurrency.combinators tools.test random kernel math
2 concurrency.mailboxes threads sequences accessors arrays
3 math.parser ;
4 IN: concurrency.combinators.tests
5
6 [ [ drop ] parallel-each ] must-infer
7 { 2 0 } [ [ 2drop ] 2parallel-each ] must-infer-as
8 [ [ ] parallel-map ] must-infer
9 { 2 1 } [ [ 2array ] 2parallel-map ] must-infer-as
10 [ [ ] parallel-filter ] must-infer
11
12 { { 1 4 9 } } [ { 1 2 3 } [ sq ] parallel-map ] unit-test
13
14 { { 1 4 9 } } [ { 1 2 3 } [ 1000000 random sleep sq ] parallel-map ] unit-test
15
16 [ { 1 2 3 } [ dup 2 mod 0 = [ "Even" throw ] when ] parallel-map ]
17 [ error>> "Even" = ] must-fail-with
18
19 { V{ 0 3 6 9 } }
20 [ 10 <iota> [ 3 mod zero? ] parallel-filter ] unit-test
21
22 { 10 }
23 [
24     V{ } clone
25     10 <iota> over [ push ] curry parallel-each
26     length
27 ] unit-test
28
29 { { 10 20 30 } } [
30     { 1 4 3 } { 10 5 10 } [ * ] 2parallel-map
31 ] unit-test
32
33 { { -9 -1 -7 } } [
34     { 1 4 3 } { 10 5 10 } [ - ] 2parallel-map
35 ] unit-test
36
37 [
38     { 1 4 3 } { 1 0 1 } [ / drop ] 2parallel-each
39 ] must-fail
40
41 { 20 }
42 [
43     V{ } clone
44     10 <iota> 10 iota pick [ [ push ] [ push ] bi ] curry 2parallel-each
45     length
46 ] unit-test
47
48 [ { f } [ "OOPS" throw ] parallel-each ] must-fail
49
50 { "1a" "4b" "3c" } [
51     2
52     { [ 1 - ] [ sq ] [ 1 + ] } parallel-cleave
53     [ number>string ] 3 parallel-napply
54     { [ "a" append ] [ "b" append ] [ "c" append ] } parallel-spread
55 ] unit-test
56
57 { H{ { 0 4 } { 2 6 } { 4 8 } } } [
58     H{ { 1 2 } { 3 4 } { 5 6 } } [
59         [ 1 - ] [ 2 + ] bi*
60     ] parallel-assoc-map
61 ] unit-test