-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better test coverage and bug fixes on flatten
- Loading branch information
1 parent
43afc4b
commit fbdb856
Showing
7 changed files
with
194 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LazyLists\Test; | ||
|
||
use ArrayIterator; | ||
|
||
/** | ||
* For testing purposes only | ||
*/ | ||
class ArrayIteratorSpy extends ArrayIterator | ||
{ | ||
public $howManyNexts = 0; | ||
public function next() | ||
{ | ||
$this->howManyNexts++; | ||
parent::next(); | ||
} | ||
} |
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
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 LazyLists\Test\Transducer; | ||
|
||
use LazyLists\Test\TestCase; | ||
|
||
use function LazyLists\map; | ||
use function LazyLists\flatten; | ||
use function LazyLists\pipe; | ||
use function LazyLists\take; | ||
|
||
class FlattenTest extends TestCase | ||
{ | ||
public function test() | ||
{ | ||
$input = [ | ||
[1, 2], | ||
[3, 4] | ||
]; | ||
$times2 = map(static function ($v) { | ||
return $v * 2; | ||
}); | ||
$pipe = pipe(flatten(1), $times2); | ||
$this->assertSame([2, 4, 6, 8], $pipe($input)); | ||
} | ||
public function testNull() | ||
{ | ||
$input = [ | ||
[1, null, 2] | ||
]; | ||
$pipe = pipe(flatten(1)); | ||
$this->assertCount(3, $pipe($input)); | ||
$this->assertSame([1, null, 2], $pipe($input)); | ||
} | ||
public function testTake() | ||
{ | ||
$input = [ | ||
[1, null, 2] | ||
]; | ||
$pipe = pipe(flatten(1), take(2)); | ||
$this->assertCount(2, $pipe($input)); | ||
$this->assertSame([1, null], $pipe($input)); | ||
} | ||
public function testAssociativeArrays() | ||
{ | ||
$input = [ | ||
[[1], ["a" => 1], 2] | ||
]; | ||
$pipe = pipe(flatten(2)); | ||
$this->assertCount(3, $pipe($input)); | ||
$this->assertSame([1, ["a" => 1], 2], $pipe($input)); | ||
} | ||
} |
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