Skip to content

Commit

Permalink
test Seed methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dakujem committed Jan 26, 2024
1 parent a3a66c3 commit c9d796f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/tool.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ declare(strict_types=1);

namespace Dakujem\Test;

use ArrayIterator;
use Dakujem\Oliva\Iterator\LevelOrderTraversal;
use Dakujem\Oliva\Iterator\PostOrderTraversal;
use Dakujem\Oliva\Iterator\PreOrderTraversal;
use Dakujem\Oliva\Node;
use Dakujem\Oliva\Seed;
use Tester\Assert;

require_once __DIR__ . '/setup.php';
Expand Down Expand Up @@ -43,4 +45,21 @@ require_once __DIR__ . '/setup.php';
Assert::same('FBADCEGIH', TreeTesterTool::flatten($tree, PreOrderTraversal::class));
Assert::same('ACEDBHIGF', TreeTesterTool::flatten($tree, PostOrderTraversal::class));
Assert::same('FBGADICEH', TreeTesterTool::flatten($tree, LevelOrderTraversal::class));
})();
})();

(function () {
Assert::same(null, Seed::firstOf([]));
Assert::same(1, Seed::firstOf([1]));
Assert::same(1, Seed::firstOf([1, 2, 3]));
Assert::same(1, Seed::firstOf(new ArrayIterator([1, 2, 3])));
Assert::same(null, Seed::firstOf(new ArrayIterator([])));
Assert::same(42, Seed::firstOf(new ArrayIterator([42])));
})();

(function () {
Assert::same([], iterator_to_array(Seed::merged()));
Assert::same([], iterator_to_array(Seed::merged([], [], new ArrayIterator([]))));
Assert::same([1, 2, 3, 4], iterator_to_array(Seed::merged([1, 2], new ArrayIterator([2 => 3, 4]))));
Assert::same([1, 2, 3, 4], iterator_to_array(Seed::merged(new ArrayIterator([1, 2]), new ArrayIterator([2 => 3, 4]))));
Assert::same([1, 2, 3, 4], iterator_to_array(Seed::merged(new ArrayIterator([1, 2]), [2 => 3, 4])));
})();

0 comments on commit c9d796f

Please sign in to comment.