Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
Add tests for array compatible iterators and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
TimeToogo committed Jun 21, 2015
1 parent 87fc0ee commit aed4ed5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
3.2.2 (21/6/15)
===============
- Optimize standard and generator iterators to only use array compatible iterator (replaces non scalar keys) where necessary

3.2.1 (20/6/15)
===============
- Update join generator classes such that they dont perform unnecessary inner loop computations for every iteration.
Expand Down
48 changes: 43 additions & 5 deletions Tests/Integration/Traversable/IteratorSchemeTest.php
Expand Up @@ -3,9 +3,22 @@
namespace Pinq\Tests\Integration\Traversable;

use Pinq\Iterators\IIteratorScheme;
use Pinq\Iterators\SchemeProvider;
use Pinq\Traversable;

class IteratorSchemeTest extends TraversableTest
{
public function schemes()
{
$schemes = [];

foreach (SchemeProvider::getAvailableSchemes() as $scheme) {
$schemes[] = [$scheme];
}

return $schemes;
}

/**
* @dataProvider theImplementations
*/
Expand All @@ -28,13 +41,13 @@ public function testThatMaintainsCorrectSameIteratorScheme(\Pinq\ITraversable $t
->except([])
->groupBy(function () { return 1; })
->groupJoin([])
->on(function () { return true; })
->to(function () { return 1; })
->on(function () { return true; })
->to(function () { return 1; })
->indexBy(function () { return 1; })
->intersect([])
->join([])
->on(function () { return true; })
->to(function () { return 1; })
->on(function () { return true; })
->to(function () { return 1; })
->keys()
->orderBy(function () { return 1; }, \Pinq\Direction::ASCENDING)
->thenByDescending(function () { return 1; })
Expand All @@ -46,8 +59,33 @@ public function testThatMaintainsCorrectSameIteratorScheme(\Pinq\ITraversable $t
->union([])
->where(function () { return true; })
->whereIn([]);
//Well that was fun
//Well that was fun

$this->assertSame($originalScheme, $queriedTraversable->getIteratorScheme());
}

/**
* @dataProvider schemes
*/
public function testThatArrayCompatibleIsNotUsedForArrays(IIteratorScheme $scheme)
{
$iterator = Traversable::from([1,2,3], $scheme)
->where(function () { return true; })
->select(function ($v) { return $v; })
->getIterator();

$this->assertNotInstanceOf(get_class($scheme->arrayCompatibleIterator(new \EmptyIterator())), $iterator);
}

/**
* @dataProvider schemes
*/
public function testThatArrayCompatibleIsUsedForIndexBy(IIteratorScheme $scheme)
{
$iterator = Traversable::from([1,2,3], $scheme)
->indexBy(function () { return new \stdClass(); })
->getIterator();

$this->assertInstanceOf(get_class($scheme->arrayCompatibleIterator(new \EmptyIterator())), $iterator);
}
}

0 comments on commit aed4ed5

Please sign in to comment.