public function testConcat() { $setA = ImmArray::fromArray([1, 2, 3]); $setB = ImmArray::fromItems(new ArrayIterator([4, 5, 6])); $concatted = $setA->concat($setB); $this->assertSame([1, 2, 3, 4, 5, 6], $concatted->toArray()); }
<?php /** * Simple tests for now, to verify basic functionality. * This should soon be PHPUnit. */ require_once __DIR__ . '/../vendor/autoload.php'; use Qaribou\Collection\ImmArray; use Qaribou\Iterator\SliceIterator; $ia = ImmArray::fromArray(['a', 'b', 'c', 'd', 'e']); $slice = new SliceIterator($ia, 1, -1); foreach ($slice as $i => $el) { echo $i . ': ' . $el, PHP_EOL; } echo 'Count: ' . count($slice), PHP_EOL; echo '1st index: ' . $slice[2], PHP_EOL;
echo 'Sorted: ' . $sorted->join(', '), PHP_EOL; // Slice $firstThree = $numberSet->slice(0, 3); echo 'Sliced: ' . $firstThree->join(), PHP_EOL; // Reduce $summed = $numberSet->reduce(function ($last, $cur) { return $last + $cur; }, 0); echo 'Reduced (summed): ' . $summed, PHP_EOL; $concatted = $sorted->reduce(function ($last, $cur, $i) { return $last . '{"' . $i . '":"' . $cur . '"},'; }, ''); echo 'Reduced (concat): ' . $concatted, PHP_EOL; // Big $bigSet = ImmArray::fromArray(array_map(function ($el) { return md5($el); }, range(0, 200000))); // Time the filter function $t = microtime(true); $bigSet->filter(function ($el) { return strpos($el, 'a8') > -1; }); echo 'filter: ' . (microtime(true) - $t) . 's', PHP_EOL; // Time the map function $t = microtime(true); $mem = memory_get_usage(); $big = $bigSet->map(function ($el) { return '{' . $el . '}'; }); echo 'ImmArray::map() ' . (microtime(true) - $t) . 's' . ', mem: ' . (memory_get_usage(true) - $mem), PHP_EOL; $bigArr = $bigSet->toArray();