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.
ext-collections/tests/045-sort-sorted.phpt

41 lines
1.0 KiB
Plaintext
Raw Permalink Normal View History

--TEST--
2018-08-26 12:23:22 +00:00
Test Collection::sort(), Collection::sortDescending(), Collection::sorted(), Collection::sortedDescending().
--FILE--
<?php
$array = [];
2018-08-28 14:11:09 +00:00
for ($i = 0; $i < 100; ++$i) {
$array[] = mt_rand(-200, 200);
2018-08-28 14:11:09 +00:00
}
$collection = Collection::init($array);
$collection->sort();
$array1 = $array;
sort($array1, SORT_NUMERIC);
2018-08-28 14:11:09 +00:00
if ($array1 != $collection->toArray()) {
echo 'Collection::sort() failed.', PHP_EOL;
2018-08-28 14:11:09 +00:00
}
$collection = Collection::init($array);
$collection->sortDescending();
$array1 = $array;
rsort($array1, SORT_NUMERIC);
2018-08-28 14:11:09 +00:00
if ($array1 != $collection->toArray()) {
echo 'Collection::sortDescending() failed.', PHP_EOL;
2018-08-28 14:11:09 +00:00
}
2018-08-26 12:23:22 +00:00
$collection = Collection::init($array);
$array1 = $array;
sort($array1, SORT_NUMERIC);
2018-08-28 14:11:09 +00:00
if ($array1 != $collection->sorted()->toArray()) {
2018-08-26 12:23:22 +00:00
echo 'Collection::sorted() failed.', PHP_EOL;
2018-08-28 14:11:09 +00:00
}
2018-08-26 12:23:22 +00:00
$collection = Collection::init($array);
$array1 = $array;
rsort($array1, SORT_NUMERIC);
2018-08-28 14:11:09 +00:00
if ($array1 != $collection->sortedDescending()->toArray()) {
2018-08-26 12:23:22 +00:00
echo 'Collection::sortedDescending() failed.', PHP_EOL;
2018-08-28 14:11:09 +00:00
}
?>
--EXPECT--