-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
323 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Smoren\ArrayView\Tests\Unit\ArrayMaskView; | ||
|
||
use Smoren\ArrayView\Exceptions\SizeError; | ||
use Smoren\ArrayView\Selectors\MaskSelector; | ||
use Smoren\ArrayView\Views\ArrayView; | ||
|
||
class IssetTest extends \Codeception\Test\Unit | ||
{ | ||
|
||
/** | ||
* @dataProvider dataProviderForIssetSelectorTrue | ||
*/ | ||
public function testIssetSelectorTrue(array $source, array $boolMask) | ||
{ | ||
$view = ArrayView::toView($source); | ||
|
||
$this->assertTrue(isset($view[new MaskSelector($boolMask)])); | ||
} | ||
|
||
/** | ||
* @dataProvider dataProviderForIssetSelectorFalse | ||
*/ | ||
public function testIssetSelectorFalse(array $source, array $indexes) | ||
{ | ||
$view = ArrayView::toView($source); | ||
|
||
$this->assertFalse(isset($view[new MaskSelector($indexes)])); | ||
|
||
$this->expectException(SizeError::class); | ||
$_ = $view[new MaskSelector($indexes)]; | ||
} | ||
|
||
public function dataProviderForIssetSelectorTrue(): array | ||
{ | ||
return [ | ||
[[], [], []], | ||
[[1], [0], []], | ||
[[1, 2, 3], [0, 0, 0], []], | ||
[[1], [1], [1]], | ||
[[1, 2], [1, 0], [1]], | ||
[[1, 2], [0, 1], [2]], | ||
[[1, 2], [1, 1], [1, 2]], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 0, 1, 0, 1, 0, 1, 0], [2, 4, 6, 8]], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 1, 1, 0, 0, 0, 0, 0, 1], [1, 2, 3, 9]], | ||
]; | ||
} | ||
|
||
public function dataProviderForIssetSelectorFalse(): array | ||
{ | ||
return [ | ||
[[], [0], []], | ||
[[], [1], []], | ||
[[], [0, 1], []], | ||
[[1], [], []], | ||
[[1], [0, 0], []], | ||
[[1], [1, 0], []], | ||
[[1], [1, 1, 1], []], | ||
[[1, 2, 3], [], []], | ||
[[1, 2, 3], [0], []], | ||
[[1, 2, 3], [0, 0], []], | ||
[[1, 2, 3], [0, 0, 0, 0], []], | ||
[[1, 2, 3], [0, 0, 0, 0, 0], []], | ||
[[1, 2, 3], [1], []], | ||
[[1, 2, 3], [1, 1], []], | ||
[[1, 2, 3], [1, 1, 1, 1], []], | ||
[[1, 2, 3], [1, 1, 1, 1, 1], []], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 0, 1, 0, 1, 0, 1], [2, 4, 6, 8]], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 1, 1, 0, 0, 0, 0, 0, 1, 0], [1, 2, 3, 9]], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Smoren\ArrayView\Tests\Unit\ArraySliceView; | ||
|
||
use Smoren\ArrayView\Selectors\SliceSelector; | ||
use Smoren\ArrayView\Views\ArrayView; | ||
|
||
class IssetTest extends \Codeception\Test\Unit | ||
{ | ||
/** | ||
* @dataProvider dataProviderForIssetSelectorStringTrue | ||
* @dataProvider dataProviderForIssetSelectorArrayTrue | ||
*/ | ||
public function testIssetSelectorObjectTrue(array $source, $slice) | ||
{ | ||
$view = ArrayView::toView($source); | ||
$this->assertTrue(isset($view[new SliceSelector($slice)])); | ||
} | ||
|
||
/** | ||
* @dataProvider dataProviderForIssetSelectorStringTrue | ||
*/ | ||
public function testIssetSelectorStringTrue(array $source, $slice) | ||
{ | ||
$view = ArrayView::toView($source); | ||
$this->assertTrue(isset($view[$slice])); | ||
} | ||
|
||
public function dataProviderForIssetSelectorStringTrue(): array | ||
{ | ||
return [ | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '1:6'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '1:6:1'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '1:6:2'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '2:8'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '2:8:1'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '2:8:2'], | ||
|
||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '-1::-1'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '-1:0:-1'], | ||
|
||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '0:9:1'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '0:9:2'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '1:9:2'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '0:10:1'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '0:10:2'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '-9:9:1'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '-9:9:2'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '-10:10:1'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '-10:10:2'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '-5:10:1'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '-5:100:2'], | ||
|
||
[[], '0:'], | ||
[[], '0:0'], | ||
[[], '0:0:1'], | ||
[[], '1:-1'], | ||
[[], '-1:-1'], | ||
[[], '-2:-1'], | ||
[[], '-2:-1:2'], | ||
[[], '-1:0:-1'], | ||
[[1], '0:'], | ||
[[1], '0:1'], | ||
[[1], '0:1:1'], | ||
[[1], '0:1:2'], | ||
[[1], '0:-1'], | ||
[[1], '0:-1:1'], | ||
[[1], '0:-1:2'], | ||
[[1], '0:10:100'], | ||
[[1], '1:10:100'], | ||
[[1], '0:'], | ||
[[1, 2, 3], '0:0:1'], | ||
[[1], '1:'], | ||
[[1, 2], '1:0'], | ||
[[1, 2], '1::-1'], | ||
[[1, 2], '0:1'], | ||
[[1, 2], '1:1'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '1::2'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], '::2'], | ||
]; | ||
} | ||
|
||
public function dataProviderForIssetSelectorArrayTrue(): array | ||
{ | ||
return [ | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], [1,6]], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], [1,6,1]], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], [1,6,2]], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], [2,8]], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], [2,8,1]], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], [2,8,2]], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Smoren\ArrayView\Tests\Unit\ArrayView; | ||
|
||
use Smoren\ArrayView\Selectors\SliceSelector; | ||
use Smoren\ArrayView\Views\ArrayView; | ||
|
||
class IssetTest extends \Codeception\Test\Unit | ||
{ | ||
/** | ||
* @dataProvider dataProviderForIssetSelectorFalse | ||
*/ | ||
public function testIssetSelectorFalse(array $source, $slice) | ||
{ | ||
$view = ArrayView::toView($source); | ||
$this->assertFalse(isset($view[$slice])); | ||
} | ||
|
||
public function dataProviderForIssetSelectorFalse(): array | ||
{ | ||
return [ | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], null], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], true], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], false], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], 1.1], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], INF], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], -INF], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], [1,6]], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], 'asd'], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], ['a' => 1]], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9], new \ArrayObject(['a' => 1])], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Smoren\ArrayView\Tests\Unit\Structs; | ||
|
||
use Smoren\ArrayView\Structs\Slice; | ||
|
||
class NormalizedSliceTest extends \Codeception\Test\Unit | ||
{ | ||
/** | ||
* @dataProvider dataProviderForToSlice | ||
*/ | ||
public function testToSlice($input, $containerSize, array $expected) | ||
{ | ||
$actual = Slice::toSlice($input)->normalize($containerSize); | ||
$expectedSlice = new Slice(...$expected); | ||
|
||
$this->assertSame($expectedSlice->getStart(), $actual->getStart()); | ||
$this->assertSame($expectedSlice->getEnd(), $actual->getEnd()); | ||
$this->assertSame($expectedSlice->getStep(), $actual->getStep()); | ||
} | ||
|
||
public function dataProviderForToSlice(): array | ||
{ | ||
return [ | ||
[':', 0, [0, 0, 1]], | ||
['::', 0, [0, 0, 1]], | ||
['::', 1, [0, 1, 1]], | ||
['::', 2, [0, 2, 1]], | ||
['0:', 0, [0, 0, 1]], | ||
['0:', 1, [0, 1, 1]], | ||
['1:', 0, [0, 0, 1]], | ||
['-1:', 0, [0, 0, 1]], | ||
['-1:', 1, [0, 1, 1]], | ||
['0:0:', 0, [0, 0, 1]], | ||
['0:0:', 10, [0, 0, 1]], | ||
['1:1:', 0, [0, 0, 1]], | ||
['1:1:', 10, [1, 1, 1]], | ||
['-1:-1:', 0, [0, 0, 1]], | ||
['-1:-1:', 10, [9, 9, 1]], | ||
['1:1:-1', 0, [0, 0, -1]], | ||
['1:1:-1', 1, [0, 0, -1]], | ||
['1:1:-1', 2, [1, 1, -1]], | ||
['-1:-1:-1', 0, [0, 0, -1]], | ||
['-1:-1:-1', 1, [0, 0, -1]], | ||
['-1:-1:-1', 2, [1, 1, -1]], | ||
['1:2:3', 0, [0, 0, 3]], | ||
['1:2:3', 1, [0, 0, 3]], | ||
['1:2:3', 2, [1, 2, 3]], | ||
['1:2:3', 3, [1, 2, 3]], | ||
['1:2:3', 10, [1, 2, 3]], | ||
]; | ||
} | ||
} |