This repository has been archived on 2020-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
2018-09-07 19:43:00 +00:00
|
|
|
--TEST--
|
|
|
|
Test Collection::intersectValues() and Collection::subtract().
|
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
$array = [];
|
|
|
|
for ($i = 0; $i < 50; ++$i) {
|
2018-09-12 05:50:26 +00:00
|
|
|
$array[] = mt_rand(1, 50);
|
2018-09-07 19:43:00 +00:00
|
|
|
}
|
|
|
|
$array1 = [];
|
|
|
|
for ($i = 0; $i < 50; ++$i) {
|
2018-09-12 05:50:26 +00:00
|
|
|
$array1[] = mt_rand(1, 50);
|
2018-09-07 19:43:00 +00:00
|
|
|
}
|
|
|
|
$collection = Collection::init($array);
|
|
|
|
$collection1 = Collection::init($array1);
|
|
|
|
|
|
|
|
$intersected = array_values(array_unique(array_intersect($array, $array1)));
|
|
|
|
if ($collection->intersectValues($collection1)->toArray() != $intersected ||
|
|
|
|
$collection->intersectValues([])->toArray() != [] ||
|
|
|
|
Collection::init()->intersectValues($collection1)->toArray() != []
|
|
|
|
) {
|
|
|
|
echo 'Collection::intersectValues() failed.', PHP_EOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
$subtracted = array_values(array_unique(array_diff($array, $array1)));
|
|
|
|
if ($collection->subtract($collection1)->toArray() != $subtracted ||
|
|
|
|
$collection->subtract([])->toArray() != $array ||
|
|
|
|
$collection->subtract($collection)->toArray() != []
|
|
|
|
) {
|
|
|
|
echo 'Collection::subtract() failed.', PHP_EOL;
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
--EXPECT--
|