Annotation of embedaddon/php/ext/standard/tests/strings/004.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Testing randomization of shuffle() and str_shuffle().
! 3: --FILE--
! 4: <?php
! 5: function stats($f, $a) {
! 6: $times = 90000;
! 7: print "$f\n";
! 8: ksort($a);
! 9: foreach($a as $k => $v)
! 10: print "$k: $v: " . sprintf('%0.3f', $v / $times) . "\n";
! 11: }
! 12: $a = array();
! 13: $times = 90000;
! 14: for ($i = 0; $i < $times; $i++) {
! 15: $p = range(1,4);
! 16: shuffle($p);
! 17: $s = join('', $p);
! 18: if (empty($a[$s])) $a[$s] = 0;
! 19: $a[$s]++;
! 20: }
! 21:
! 22: stats('shuffle', $a);
! 23: $a = array();
! 24: $times = 90000;
! 25: for ($i = 0; $i < $times; $i++) {
! 26: $p = '1234';
! 27: $s = str_shuffle($p);
! 28: if (empty($a[$s])) $a[$s] = 0;
! 29: $a[$s]++;
! 30: }
! 31:
! 32: stats('str_shuffle', $a);
! 33: ?>
! 34: --EXPECTREGEX--
! 35: shuffle
! 36: 1234: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 37: 1243: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 38: 1324: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 39: 1342: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 40: 1423: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 41: 1432: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 42: 2134: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 43: 2143: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 44: 2314: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 45: 2341: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 46: 2413: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 47: 2431: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 48: 3124: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 49: 3142: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 50: 3214: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 51: 3241: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 52: 3412: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 53: 3421: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 54: 4123: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 55: 4132: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 56: 4213: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 57: 4231: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 58: 4312: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 59: 4321: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 60: str_shuffle
! 61: 1234: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 62: 1243: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 63: 1324: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 64: 1342: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 65: 1423: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 66: 1432: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 67: 2134: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 68: 2143: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 69: 2314: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 70: 2341: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 71: 2413: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 72: 2431: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 73: 3124: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 74: 3142: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 75: 3214: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 76: 3241: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 77: 3412: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 78: 3421: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 79: 4123: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 80: 4132: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 81: 4213: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 82: 4231: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 83: 4312: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
! 84: 4321: 3[0-9][0-9][0-9]: 0.0[3-4][0-9]
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>