a6f9a6c8ce85da1ff2285a59f9091a38ee90d72e
2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 require_once dirname(__FILE__
) . '/../include/test.inc.php';
24 class ParallelIteratorTest
extends PlTestCase
26 public function testSameCallback()
28 $m = PlIteratorUtils
::fromArray(array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5));
29 $s1 = PlIteratorUtils
::fromArray(array('X' => 1, 'Y' => 2, 'Z' => 4));
30 $s2 = PlIteratorUtils
::fromArray(array('aaa' => 2, 'bbb' => 3, 'ccc' => 6));
32 $cb = PlIteratorUtils
::arrayValueCallback('value');
34 $its = array(0 => $m, 1 => $s1, 2 => $s2);
35 $cbs = array(0 => $cb, 1 => $cb, 2 => $cb);
37 $it = PlIteratorUtils
::parallelIterator($its, $cbs, 0);
39 $this->assertSame(5, $it->total());
41 $this->assertSame(array(0 => array('keys' => array('a'), 'value' => 1),
42 1 => array('keys' => array('X'), 'value' => 1),
43 2 => null
), $it->next());
44 $this->assertTrue($it->first());
45 $this->assertFalse($it->last());
47 $this->assertSame(array(0 => array('keys' => array('b'), 'value' => 2),
48 1 => array('keys' => array('Y'), 'value' => 2),
49 2 => array('keys' => array('aaa'), 'value' => 2)
52 $this->assertFalse($it->first());
53 $this->assertFalse($it->last());
55 $this->assertSame(array(0 => array('keys' => array('c'), 'value' => 3),
57 2 => array('keys' => array('bbb'), 'value' => 3),
60 $this->assertFalse($it->first());
61 $this->assertFalse($it->last());
63 $this->assertSame(array(0 => array('keys' => array('d'), 'value' => 4),
64 1 => array('keys' => array('Z'), 'value' => 4),
68 $this->assertFalse($it->first());
69 $this->assertFalse($it->last());
71 $this->assertSame(array(0 => array('keys' => array('e'), 'value' => 5),
76 $this->assertFalse($it->first());
77 $this->assertTrue($it->last());
79 $this->assertNull($it->next());
82 public function testOneCallback()
84 $m = PlIteratorUtils
::fromArray(array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5));
85 $s1 = PlIteratorUtils
::fromArray(array('X' => 1, 'Y' => 2, 'Z' => 4));
86 $s2 = PlIteratorUtils
::fromArray(array('aaa' => 2, 'bbb' => 3, 'ccc' => 6));
88 $cb = PlIteratorUtils
::arrayValueCallback('value');
90 $its = array(0 => $m, 1 => $s1, 2 => $s2);
92 $it = PlIteratorUtils
::parallelIterator($its, $cb, 0);
94 $this->assertSame(5, $it->total());
96 $this->assertSame(array(0 => array('keys' => array('a'), 'value' => 1),
97 1 => array('keys' => array('X'), 'value' => 1),
98 2 => null
), $it->next());
99 $this->assertTrue($it->first());
100 $this->assertFalse($it->last());
102 $this->assertSame(array(0 => array('keys' => array('b'), 'value' => 2),
103 1 => array('keys' => array('Y'), 'value' => 2),
104 2 => array('keys' => array('aaa'), 'value' => 2)
107 $this->assertFalse($it->first());
108 $this->assertFalse($it->last());
110 $this->assertSame(array(0 => array('keys' => array('c'), 'value' => 3),
112 2 => array('keys' => array('bbb'), 'value' => 3),
115 $this->assertFalse($it->first());
116 $this->assertFalse($it->last());
118 $this->assertSame(array(0 => array('keys' => array('d'), 'value' => 4),
119 1 => array('keys' => array('Z'), 'value' => 4),
123 $this->assertFalse($it->first());
124 $this->assertFalse($it->last());
126 $this->assertSame(array(0 => array('keys' => array('e'), 'value' => 5),
131 $this->assertFalse($it->first());
132 $this->assertTrue($it->last());
134 $this->assertNull($it->next());
139 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: