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 FilterMapIteratorTest
extends PlTestCase
26 public static function filter($e)
31 public function testFilter()
33 $it = PlIteratorUtils
::fromArray(array(1, 10, 3, 9, 42, -23, 9, 8), 1, true
);
34 $it = PlIteratorUtils
::filter($it, array('FilterMapIteratorTest', 'filter'));
35 $this->assertLessThanOrEqual(8, $it->total());
36 $this->assertGreaterThanOrEqual(4, $it->total());
38 $this->assertEquals(10, $it->next());
39 $this->assertTrue($it->first());
40 $this->assertFalse($it->last());
42 $this->assertEquals(9, $it->next());
43 $this->assertFalse($it->first());
44 $this->assertFalse($it->last());
46 $this->assertEquals(42, $it->next());
47 $this->assertFalse($it->first());
48 $this->assertFalse($it->last());
50 $this->assertEquals(9, $it->next());
51 $this->assertFalse($it->first());
52 $this->assertTrue($it->last());
54 $this->assertNull($it->next());
57 public static function map($e)
62 public function testMap()
64 $it = PlIteratorUtils
::fromArray(array(1, 2, 3, 4, 7, 512), 1, true
);
65 $it = PlIteratorUtils
::map($it, array('FilterMapIteratorTest', 'map'));
66 $this->assertEquals(6, $it->total());
68 $this->assertEquals(2, $it->next());
69 $this->assertTrue($it->first());
70 $this->assertFalse($it->last());
72 $this->assertEquals(4, $it->next());
73 $this->assertFalse($it->first());
74 $this->assertFalse($it->last());
76 $this->assertEquals(6, $it->next());
77 $this->assertFalse($it->first());
78 $this->assertFalse($it->last());
80 $this->assertEquals(8, $it->next());
81 $this->assertFalse($it->first());
82 $this->assertFalse($it->last());
84 $this->assertEquals(14, $it->next());
85 $this->assertFalse($it->first());
86 $this->assertFalse($it->last());
88 $this->assertEquals(1024, $it->next());
89 $this->assertFalse($it->first());
90 $this->assertTrue($it->last());
92 $this->assertNull($it->next());
96 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: