1
0
mirror of https://github.com/php/php-src.git synced 2026-03-25 08:42:29 +01:00
Files
archived-php-src/ext/standard/tests/array/shuffle_basic1.phpt
Peter Kokot d679f02295 Sync leading and final newlines in *.phpt sections
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines in all
*.phpt sections.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-15 04:33:09 +02:00

150 lines
3.1 KiB
PHP

--TEST--
Test shuffle() function : basic functionality - array with default keys
--FILE--
<?php
/* Prototype : bool shuffle(array $array_arg)
* Description: Randomly shuffle the contents of an array
* Source code: ext/standard/array.c
*/
/*
* Test behaviour of shuffle when an array with default keys
* is passed to the 'array_arg' argument and check for the
* changes in the input array by printing the input array
* before and after shuffle() function is applied on it
*/
echo "*** Testing shuffle() : with arrays having default keys ***\n";
// Initialise the array with integers
$array_arg_int = array(0, 10, 20, 30, 40, 50, 60, 70, 80);
// Initialise the array with strings
$array_arg_strings = array("one", 'two', 'three', "four", "five", " ", 'six', ' ', "seven");
/* Testing shuffle() function with array of integers */
// printing the input array with integers before the shuffle operation
echo "\n-- input array of integers before shuffle() function is applied --\n";
var_dump( $array_arg_int );
// applying shuffle() function on the input array of integers
echo "\n-- return value from shuffle() function --\n";
var_dump( shuffle($array_arg_int) ); // prints the return value from shuffle() function
echo "\n-- resultant array after shuffle() function is applied --\n";
var_dump( $array_arg_int );
/* Testing shuffle() function with array of strings */
// printing the input array with strings before the shuffle operation
echo "\n-- input array of strings before shuffle() function is applied --\n";
var_dump( $array_arg_strings );
// applying shuffle() function on the input array of strings
echo "\n-- return value from shuffle() function --\n";
var_dump( shuffle($array_arg_strings) ); // prints the return value from shuffle() function
echo "\n-- resultant array after shuffle() function is applied --\n";
var_dump( $array_arg_strings );
echo "Done";
?>
--EXPECTF--
*** Testing shuffle() : with arrays having default keys ***
-- input array of integers before shuffle() function is applied --
array(9) {
[0]=>
int(0)
[1]=>
int(10)
[2]=>
int(20)
[3]=>
int(30)
[4]=>
int(40)
[5]=>
int(50)
[6]=>
int(60)
[7]=>
int(70)
[8]=>
int(80)
}
-- return value from shuffle() function --
bool(true)
-- resultant array after shuffle() function is applied --
array(9) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
[4]=>
int(%d)
[5]=>
int(%d)
[6]=>
int(%d)
[7]=>
int(%d)
[8]=>
int(%d)
}
-- input array of strings before shuffle() function is applied --
array(9) {
[0]=>
string(3) "one"
[1]=>
string(3) "two"
[2]=>
string(5) "three"
[3]=>
string(4) "four"
[4]=>
string(4) "five"
[5]=>
string(1) " "
[6]=>
string(3) "six"
[7]=>
string(1) " "
[8]=>
string(5) "seven"
}
-- return value from shuffle() function --
bool(true)
-- resultant array after shuffle() function is applied --
array(9) {
[0]=>
string(%d) "%s"
[1]=>
string(%d) "%s"
[2]=>
string(%d) "%s"
[3]=>
string(%d) "%s"
[4]=>
string(%d) "%s"
[5]=>
string(%d) "%s"
[6]=>
string(%d) "%s"
[7]=>
string(%d) "%s"
[8]=>
string(%d) "%s"
}
Done