summaryrefslogtreecommitdiff
path: root/t/03_chunk_size.t
blob: db6b9b30214e066c6297bba28826444afce64823 (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
#!/usr/bin/env perl

use strict;
use warnings;

use Test::More;

BEGIN {
   use_ok 'MCE';
}

my @ans;

sub callback {
   my ($element) = @_;
   push @ans, $element;
   return;
}

my $mce = MCE->new(
   max_workers => 2,

   user_func => sub {
      my ($self, $chunk_ref, $chunk_id) = @_;

      for ( @{ $chunk_ref } ) {
         MCE->do('callback', $_);
      }

      return;
   }
);

@ans = ();
$mce->process([ 0 .. 3 ], { chunk_size => 1 });

is(
   join('', sort @ans), '0123',
   'check that ans is correct for chunk_size of 1'
);

@ans = ();
$mce->process([ 0 .. 7 ], { chunk_size => 2 });

is(
   join('', sort @ans), '01234567',
   'check that ans is correct for chunk_size of 2'
);

@ans = ();
$mce->process([ 0 .. 9 ], { chunk_size => 4 });

is(
   join('', sort @ans), '0123456789',
   'check that ans is correct for chunk_size of 4'
);

$mce->shutdown();

done_testing;