|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Smoren\ArrayView\Tests\Unit\ArrayIndexListView; |
| 4 | + |
| 5 | +use Smoren\ArrayView\Selectors\IndexListSelector; |
| 6 | +use Smoren\ArrayView\Selectors\MaskSelector; |
| 7 | +use Smoren\ArrayView\Views\ArrayIndexListView; |
| 8 | +use Smoren\ArrayView\Views\ArrayView; |
| 9 | + |
| 10 | +class IssetTest extends \Codeception\Test\Unit |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @dataProvider dataProviderForIssetTrue |
| 14 | + */ |
| 15 | + public function testIssetTrue(array $source, array $indexes) |
| 16 | + { |
| 17 | + $view = ArrayView::toView($source); |
| 18 | + $subview = $view->subview(new IndexListSelector($indexes)); |
| 19 | + |
| 20 | + $existIndexes = [ |
| 21 | + ...range(0, \count($indexes) - 1), |
| 22 | + ...range(-1, -\count($indexes)), |
| 23 | + ]; |
| 24 | + |
| 25 | + foreach ($existIndexes as $index) { |
| 26 | + $this->assertTrue(isset($subview[$index]), $index); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * @dataProvider dataProviderForIssetFalse |
| 32 | + */ |
| 33 | + public function testIssetFalse(array $source, array $indexes, array $expected) |
| 34 | + { |
| 35 | + $view = ArrayView::toView($source); |
| 36 | + $subview = $view->subview(new IndexListSelector($indexes)); |
| 37 | + |
| 38 | + foreach ($expected as $index) { |
| 39 | + $this->assertFalse(isset($subview[$index]), $index); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + public function dataProviderForIssetTrue(): array |
| 44 | + { |
| 45 | + return [ |
| 46 | + [[1], [0]], |
| 47 | + [[1], [0, 0]], |
| 48 | + [[1], [0, 0, 0]], |
| 49 | + [[1, 2], [0]], |
| 50 | + [[1, 2], [1]], |
| 51 | + [[1, 2], [0, 1]], |
| 52 | + [[1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 3, 5, 7]], |
| 53 | + [[1, 2, 3, 4, 5, 6, 7, 8, 9], [7, 5, 3, 1]], |
| 54 | + [[1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 5, 3, 7]], |
| 55 | + [[1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 7, 8]], |
| 56 | + [[1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 1, 5, 5, 3]], |
| 57 | + ]; |
| 58 | + } |
| 59 | + |
| 60 | + public static function dataProviderForIssetFalse(): array |
| 61 | + { |
| 62 | + return [ |
| 63 | + [[], [], [-2, -1, 0, 1, 2]], |
| 64 | + [[1], [], [-2, -1, 0, 1, 2]], |
| 65 | + [[1, 2, 3], [], [-2, -1, 0, 1, 2]], |
| 66 | + [[1], [0], [-3, -2, 1, 2]], |
| 67 | + [[1], [0, 0], [-5, -4, -3, 2, 3, 4]], |
| 68 | + [[1], [0, 0, 0], [-6, -5, -4, 3, 4, 5]], |
| 69 | + [[1, 2], [0], [-3, -2, 1, 2]], |
| 70 | + [[1, 2], [1], [-3, -2, 1, 2]], |
| 71 | + [[1, 2], [0, 1], [-5, -4, -3, 2, 3, 4]], |
| 72 | + [[1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 3, 5, 7], [-7, -6, -5, 4, 5, 6]], |
| 73 | + [[1, 2, 3, 4, 5, 6, 7, 8, 9], [7, 5, 3, 1], [-7, -6, -5, 4, 5, 6]], |
| 74 | + [[1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 5, 3, 7], [-7, -6, -5, 4, 5, 6]], |
| 75 | + [[1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 7, 8], [-7, -6, -5, 4, 5, 6]], |
| 76 | + [[1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 1, 5, 5, 3], [-8, -7, -6, 5, 6, 7]], |
| 77 | + ]; |
| 78 | + } |
| 79 | +} |
0 commit comments