File: 03_chunk_size.t

package info (click to toggle)
libmce-perl 1.517-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,864 kB
  • ctags: 377
  • sloc: perl: 10,516; makefile: 2
file content (62 lines) | stat: -rwxr-xr-x 996 bytes parent folder | download
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
#!/usr/bin/env perl

use strict;
use warnings;

BEGIN {
   eval 'use threads; use threads::shared;' if $^O eq 'MSWin32';
}

use Test::More tests => 3;

use MCE;

my @ans;

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

my $mce = MCE->new(
   use_threads => ($^O eq 'MSWin32') ? 1 : 0,
   spawn_delay => 0.2,
   max_workers => 4,

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

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


@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();