SliceIteratorTest::testSliceIterator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace itertools;
4
5
use ArrayIterator;
6
use PHPUnit_Framework_TestCase;
7
8
9
class SliceIteratorTest extends PHPUnit_Framework_TestCase
10
{
11
	/** @test */
12
	public function testSliceIterator()
13
	{
14
		$a = range(5, 20);
15
		$this->assertEquals(array_slice($a, 10), $this->islice($a, 10));
16
		$this->assertEquals(array_slice($a, 30), $this->islice($a, 30));
17
		$this->assertEquals(array_slice($a, 1, 5), $this->islice($a, 1, 5));
18
		$this->assertEquals(array_slice($a, 1, 200), $this->islice($a, 1, 200));
19
		$this->assertEquals(array_slice($a, 1, 200, true), $this->islice($a, 1, 200, true));
20
	}
21
22
	protected function islice($array, $offset, $length = INF, $preserve_keys = false)
23
	{
24
		return iterator_to_array(new SliceIterator($array, $offset, $length, $preserve_keys));
25
	}
26
}
27
28