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

1.1       misho       1: --TEST--
                      2: Test rsort() function : usage variations - numeric values
                      3: --SKIPIF--
                      4: <?php
                      5: if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
                      6: ?>
                      7: --FILE--
                      8: <?php
                      9: /* Prototype  : bool rsort(array &$array_arg [, int $sort_flags])
                     10:  * Description: Sort an array in reverse order 
                     11:  * Source code: ext/standard/array.c
                     12:  */
                     13: 
                     14: /*
                     15:  * Pass arrays containing different numeric data to rsort() to test behaviour
                     16:  */
                     17: 
                     18: echo "*** Testing rsort() : variation ***\n";
                     19: 
                     20: // group of various arrays
                     21: 
                     22: $various_arrays = array (
                     23: // negative/positive integers array
                     24: array(11, -11, 21, -21, 31, -31, 0, 41, -41),
                     25: 
                     26: // float value array
                     27: array(10.5, -10.5, 10.5e2, 10.6E-2, .5, .01, -.1),
                     28: 
                     29: // mixed value array
                     30: array(.0001, .0021, -.01, -1, 0, .09, 2, -.9, 10.6E-2, -10.6E-2, 33),
                     31: 
                     32: // array values contains minimum and maximum ranges
                     33: array(2147483647, 2147483648, -2147483647, -2147483648, -0, 0, -2147483649)
                     34: );
                     35: 
                     36: // set of possible flag values
                     37: $flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC);
                     38: 
                     39: $count = 1;
                     40: 
                     41: // loop through to test rsort() with different arrays
                     42: foreach ($various_arrays as $array) {
                     43:   echo "\n-- Iteration $count --\n";
                     44: 
                     45:   echo "- With Defualt sort flag -\n"; 
                     46:   $temp_array = $array; 
                     47:   var_dump(rsort($temp_array) );
                     48:   var_dump($temp_array);
                     49: 
                     50:   // loop through $flag_value array and setting all possible flag values
                     51:   foreach($flag_value as $key => $flag){
                     52:     echo "- Sort flag = $key -\n";
                     53:     $temp_array = $array; 
                     54:     var_dump(rsort($temp_array, $flag) );
                     55:     var_dump($temp_array);
                     56:   }  
                     57:   $count++;
                     58: } 
                     59: 
                     60: echo "Done";
                     61: ?>
                     62: 
                     63: --EXPECTF--
                     64: *** Testing rsort() : variation ***
                     65: 
                     66: -- Iteration 1 --
                     67: - With Defualt sort flag -
                     68: bool(true)
                     69: array(9) {
                     70:   [0]=>
                     71:   int(41)
                     72:   [1]=>
                     73:   int(31)
                     74:   [2]=>
                     75:   int(21)
                     76:   [3]=>
                     77:   int(11)
                     78:   [4]=>
                     79:   int(0)
                     80:   [5]=>
                     81:   int(-11)
                     82:   [6]=>
                     83:   int(-21)
                     84:   [7]=>
                     85:   int(-31)
                     86:   [8]=>
                     87:   int(-41)
                     88: }
                     89: - Sort flag = SORT_REGULAR -
                     90: bool(true)
                     91: array(9) {
                     92:   [0]=>
                     93:   int(41)
                     94:   [1]=>
                     95:   int(31)
                     96:   [2]=>
                     97:   int(21)
                     98:   [3]=>
                     99:   int(11)
                    100:   [4]=>
                    101:   int(0)
                    102:   [5]=>
                    103:   int(-11)
                    104:   [6]=>
                    105:   int(-21)
                    106:   [7]=>
                    107:   int(-31)
                    108:   [8]=>
                    109:   int(-41)
                    110: }
                    111: - Sort flag = SORT_NUMERIC -
                    112: bool(true)
                    113: array(9) {
                    114:   [0]=>
                    115:   int(41)
                    116:   [1]=>
                    117:   int(31)
                    118:   [2]=>
                    119:   int(21)
                    120:   [3]=>
                    121:   int(11)
                    122:   [4]=>
                    123:   int(0)
                    124:   [5]=>
                    125:   int(-11)
                    126:   [6]=>
                    127:   int(-21)
                    128:   [7]=>
                    129:   int(-31)
                    130:   [8]=>
                    131:   int(-41)
                    132: }
                    133: 
                    134: -- Iteration 2 --
                    135: - With Defualt sort flag -
                    136: bool(true)
                    137: array(7) {
                    138:   [0]=>
                    139:   float(1050)
                    140:   [1]=>
                    141:   float(10.5)
                    142:   [2]=>
                    143:   float(0.5)
                    144:   [3]=>
                    145:   float(0.106)
                    146:   [4]=>
                    147:   float(0.01)
                    148:   [5]=>
                    149:   float(-0.1)
                    150:   [6]=>
                    151:   float(-10.5)
                    152: }
                    153: - Sort flag = SORT_REGULAR -
                    154: bool(true)
                    155: array(7) {
                    156:   [0]=>
                    157:   float(1050)
                    158:   [1]=>
                    159:   float(10.5)
                    160:   [2]=>
                    161:   float(0.5)
                    162:   [3]=>
                    163:   float(0.106)
                    164:   [4]=>
                    165:   float(0.01)
                    166:   [5]=>
                    167:   float(-0.1)
                    168:   [6]=>
                    169:   float(-10.5)
                    170: }
                    171: - Sort flag = SORT_NUMERIC -
                    172: bool(true)
                    173: array(7) {
                    174:   [0]=>
                    175:   float(1050)
                    176:   [1]=>
                    177:   float(10.5)
                    178:   [2]=>
                    179:   float(0.5)
                    180:   [3]=>
                    181:   float(0.106)
                    182:   [4]=>
                    183:   float(0.01)
                    184:   [5]=>
                    185:   float(-0.1)
                    186:   [6]=>
                    187:   float(-10.5)
                    188: }
                    189: 
                    190: -- Iteration 3 --
                    191: - With Defualt sort flag -
                    192: bool(true)
                    193: array(11) {
                    194:   [0]=>
                    195:   int(33)
                    196:   [1]=>
                    197:   int(2)
                    198:   [2]=>
                    199:   float(0.106)
                    200:   [3]=>
                    201:   float(0.09)
                    202:   [4]=>
                    203:   float(0.0021)
                    204:   [5]=>
                    205:   float(0.0001)
                    206:   [6]=>
                    207:   int(0)
                    208:   [7]=>
                    209:   float(-0.01)
                    210:   [8]=>
                    211:   float(-0.106)
                    212:   [9]=>
                    213:   float(-0.9)
                    214:   [10]=>
                    215:   int(-1)
                    216: }
                    217: - Sort flag = SORT_REGULAR -
                    218: bool(true)
                    219: array(11) {
                    220:   [0]=>
                    221:   int(33)
                    222:   [1]=>
                    223:   int(2)
                    224:   [2]=>
                    225:   float(0.106)
                    226:   [3]=>
                    227:   float(0.09)
                    228:   [4]=>
                    229:   float(0.0021)
                    230:   [5]=>
                    231:   float(0.0001)
                    232:   [6]=>
                    233:   int(0)
                    234:   [7]=>
                    235:   float(-0.01)
                    236:   [8]=>
                    237:   float(-0.106)
                    238:   [9]=>
                    239:   float(-0.9)
                    240:   [10]=>
                    241:   int(-1)
                    242: }
                    243: - Sort flag = SORT_NUMERIC -
                    244: bool(true)
                    245: array(11) {
                    246:   [0]=>
                    247:   int(33)
                    248:   [1]=>
                    249:   int(2)
                    250:   [2]=>
                    251:   float(0.106)
                    252:   [3]=>
                    253:   float(0.09)
                    254:   [4]=>
                    255:   float(0.0021)
                    256:   [5]=>
                    257:   float(0.0001)
                    258:   [6]=>
                    259:   int(0)
                    260:   [7]=>
                    261:   float(-0.01)
                    262:   [8]=>
                    263:   float(-0.106)
                    264:   [9]=>
                    265:   float(-0.9)
                    266:   [10]=>
                    267:   int(-1)
                    268: }
                    269: 
                    270: -- Iteration 4 --
                    271: - With Defualt sort flag -
                    272: bool(true)
                    273: array(7) {
                    274:   [0]=>
                    275:   float(2147483648)
                    276:   [1]=>
                    277:   int(2147483647)
                    278:   [2]=>
                    279:   int(0)
                    280:   [3]=>
                    281:   int(0)
                    282:   [4]=>
                    283:   int(-2147483647)
                    284:   [5]=>
                    285:   float(-2147483648)
                    286:   [6]=>
                    287:   float(-2147483649)
                    288: }
                    289: - Sort flag = SORT_REGULAR -
                    290: bool(true)
                    291: array(7) {
                    292:   [0]=>
                    293:   float(2147483648)
                    294:   [1]=>
                    295:   int(2147483647)
                    296:   [2]=>
                    297:   int(0)
                    298:   [3]=>
                    299:   int(0)
                    300:   [4]=>
                    301:   int(-2147483647)
                    302:   [5]=>
                    303:   float(-2147483648)
                    304:   [6]=>
                    305:   float(-2147483649)
                    306: }
                    307: - Sort flag = SORT_NUMERIC -
                    308: bool(true)
                    309: array(7) {
                    310:   [0]=>
                    311:   float(2147483648)
                    312:   [1]=>
                    313:   int(2147483647)
                    314:   [2]=>
                    315:   int(0)
                    316:   [3]=>
                    317:   int(0)
                    318:   [4]=>
                    319:   int(-2147483647)
                    320:   [5]=>
                    321:   float(-2147483648)
                    322:   [6]=>
                    323:   float(-2147483649)
                    324: }
                    325: Done

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