Annotation of embedaddon/php/ext/standard/tests/array/array_rand_variation5.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test array_rand() function : usage variation - invalid values for 'req_num' parameter
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : mixed array_rand(array $input [, int $num_req])
                      6:  * Description: Return key/keys for random entry/entries in the array 
                      7:  * Source code: ext/standard/array.c
                      8: */
                      9: 
                     10: /*
                     11: * Test behaviour of array_rand() function when associative array and 
                     12: * various invalid values are passed to the 'input' and 'req_num' 
                     13: * parameters respectively
                     14: */
                     15: 
                     16: echo "*** Testing array_rand() : with invalid values for 'req_num' ***\n";
                     17: 
                     18: // initialise associative arrays
                     19: $input = array(
                     20:   1 => 'one', 2.2 => 'float key', 0.9 => 'decimal key',
                     21:   2e2 => 'exp key1', 2000e-3 => 'negative exp key',
                     22:   0xabc => 2748, 0x12f => '303', 0xff => "255",
                     23:   0123 => 83, 0129 => 10, 010 => "8"
                     24: );
                     25:        
                     26: // Testing array_rand() function with various invalid 'req_num' values
                     27: // with valid num_req values  
                     28: echo"\n-- With default num_req value --\n";
                     29: var_dump( array_rand($input) );  // with default $num_req value
                     30: echo"\n-- With num_req = 1 --\n";
                     31: var_dump( array_rand($input, 1) );  // with valid $num_req value
                     32: 
                     33: // with invalid num_req value
                     34: echo"\n-- With num_req = 0 --\n";
                     35: var_dump( array_rand($input, 0) );  // with $num_req=0
                     36: echo"\n-- With num_req = -1 --\n";
                     37: var_dump( array_rand($input, -1) );  // with $num_req=-1
                     38: echo"\n-- With num_req = -2 --\n";
                     39: var_dump( array_rand($input, -2) );  // with $num_req=-2
                     40: echo"\n-- With num_req more than number of members in 'input' array --\n";
                     41: var_dump( array_rand($input, 13) );  // with $num_req=13
                     42:  
                     43: 
                     44: echo "Done";
                     45: ?>
                     46: --EXPECTF--
                     47: *** Testing array_rand() : with invalid values for 'req_num' ***
                     48: 
                     49: -- With default num_req value --
                     50: int(%d)
                     51: 
                     52: -- With num_req = 1 --
                     53: int(%d)
                     54: 
                     55: -- With num_req = 0 --
                     56: 
                     57: Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d
                     58: NULL
                     59: 
                     60: -- With num_req = -1 --
                     61: 
                     62: Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d
                     63: NULL
                     64: 
                     65: -- With num_req = -2 --
                     66: 
                     67: Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d
                     68: NULL
                     69: 
                     70: -- With num_req more than number of members in 'input' array --
                     71: 
                     72: Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d
                     73: NULL
                     74: Done
                     75: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>