Release plat/al core v1.1.13
[platal.git] / ut / filtermapiteratortest.php
CommitLineData
6cbf939b
FB
1<?php
2/***************************************************************************
e92ecb8c 3 * Copyright (C) 2003-2011 Polytechnique.org *
6cbf939b
FB
4 * http://opensource.polytechnique.org/ *
5 * *
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. *
10 * *
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. *
15 * *
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 *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22require_once dirname(__FILE__) . '/../include/test.inc.php';
23
24class FilterMapIteratorTest extends PlTestCase
25{
26 public static function filter($e)
27 {
28 return $e > 8;
29 }
30
31 public function testFilter()
32 {
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());
37
748543a7 38 $this->assertSame(10, $it->next());
6cbf939b
FB
39 $this->assertTrue($it->first());
40 $this->assertFalse($it->last());
41
748543a7 42 $this->assertSame(9, $it->next());
6cbf939b
FB
43 $this->assertFalse($it->first());
44 $this->assertFalse($it->last());
45
748543a7 46 $this->assertSame(42, $it->next());
6cbf939b
FB
47 $this->assertFalse($it->first());
48 $this->assertFalse($it->last());
49
748543a7 50 $this->assertSame(9, $it->next());
6cbf939b
FB
51 $this->assertFalse($it->first());
52 $this->assertTrue($it->last());
53
54 $this->assertNull($it->next());
55 }
56
57 public static function map($e)
58 {
59 return $e * 2;
60 }
61
62 public function testMap()
63 {
64 $it = PlIteratorUtils::fromArray(array(1, 2, 3, 4, 7, 512), 1, true);
65 $it = PlIteratorUtils::map($it, array('FilterMapIteratorTest', 'map'));
748543a7 66 $this->assertSame(6, $it->total());
6cbf939b 67
748543a7 68 $this->assertSame(2, $it->next());
6cbf939b
FB
69 $this->assertTrue($it->first());
70 $this->assertFalse($it->last());
71
748543a7 72 $this->assertSame(4, $it->next());
6cbf939b
FB
73 $this->assertFalse($it->first());
74 $this->assertFalse($it->last());
75
748543a7 76 $this->assertSame(6, $it->next());
6cbf939b
FB
77 $this->assertFalse($it->first());
78 $this->assertFalse($it->last());
79
748543a7 80 $this->assertSame(8, $it->next());
6cbf939b
FB
81 $this->assertFalse($it->first());
82 $this->assertFalse($it->last());
83
748543a7 84 $this->assertSame(14, $it->next());
6cbf939b
FB
85 $this->assertFalse($it->first());
86 $this->assertFalse($it->last());
87
748543a7 88 $this->assertSame(1024, $it->next());
6cbf939b
FB
89 $this->assertFalse($it->first());
90 $this->assertTrue($it->last());
91
92 $this->assertNull($it->next());
93 }
94}
95
fa7ffd66 96// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
6cbf939b 97?>