Annotation of embedaddon/php/ext/standard/tests/math/mt_rand_basic.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test mt_rand() - basic function test mt_rand()
! 3: --FILE--
! 4: <?php
! 5: $default_max = mt_getrandmax();
! 6:
! 7: echo "\nmt_rand() tests with default min and max value (i.e 0 thru ", $default_max, ")\n";
! 8: for ($i = 0; $i < 100; $i++) {
! 9: $res = mt_rand();
! 10:
! 11: // By default RAND_MAX is 32768 although no constant is defined for it for user space apps
! 12: if (!is_int($res) || $res < 0 || $res > $default_max) {
! 13: break;
! 14: }
! 15: }
! 16:
! 17: if ($i != 100) {
! 18: echo "FAILED: res = ", $res, " min = 0 max = ", $default_max, "\n";
! 19: } else {
! 20: echo "PASSED: range min = 0 max = ", $default_max, "\n";
! 21: }
! 22:
! 23: echo "\nmt_rand() tests with defined min and max value\n";
! 24:
! 25: $min = array(10,
! 26: 100,
! 27: 10.5,
! 28: 10.5e3,
! 29: 0x10,
! 30: 0400);
! 31:
! 32: $max = array(100,
! 33: 1000,
! 34: 19.5,
! 35: 10.5e5,
! 36: 0x10000,
! 37: 0700);
! 38:
! 39: for ($x = 0; $x < count($min); $x++) {
! 40: for ($i = 0; $i < 100; $i++) {
! 41: $res = mt_rand($min[$x], $max[$x]);
! 42:
! 43: if (!is_int($res) || $res < intval($min[$x]) || $res > intval($max[$x])) {
! 44: echo "FAILED: res = ", $res, " min = ", intval($min[$x]), " max = ", intval($max[$x]), "\n";
! 45: break;
! 46: }
! 47: }
! 48:
! 49: if ($i == 100) {
! 50: echo "PASSED: range min = ", intval($min[$x]), " max = ", intval($max[$x]), "\n";
! 51: }
! 52: }
! 53:
! 54: echo "\nNon-numeric cases\n";
! 55: $min = array(true,
! 56: false,
! 57: null,
! 58: "10",
! 59: "0x10",
! 60: "10.5");
! 61:
! 62: // Eexepcted numerical equivalent of above non-numerics
! 63: $minval = array(1,
! 64: 0,
! 65: 0,
! 66: 10,
! 67: 0,
! 68: 10);
! 69: for ($x = 0; $x < count($min); $x++) {
! 70: for ($i = 0; $i < 100; $i++) {
! 71: $res = mt_rand($min[$x], 100);
! 72:
! 73: if (!is_int($res) || $res < intval($minval[$x]) || $res > 100) {
! 74: echo "FAILED: res = ", $res, " min = ", intval($min[$x]), " max = ", intval($max[$x]), "\n";
! 75: break;
! 76: }
! 77: }
! 78:
! 79: if ($i == 100) {
! 80: echo "PASSED range min = ", intval($min[$x]), " max = 100\n";
! 81: }
! 82: }
! 83: ?>
! 84: --EXPECTF--
! 85: mt_rand() tests with default min and max value (i.e 0 thru 2147483647)
! 86: PASSED: range min = 0 max = 2147483647
! 87:
! 88: mt_rand() tests with defined min and max value
! 89: PASSED: range min = 10 max = 100
! 90: PASSED: range min = 100 max = 1000
! 91: PASSED: range min = 10 max = 19
! 92: PASSED: range min = 10500 max = 1050000
! 93: PASSED: range min = 16 max = 65536
! 94: PASSED: range min = 256 max = 448
! 95:
! 96: Non-numeric cases
! 97: PASSED range min = 1 max = 100
! 98: PASSED range min = 0 max = 100
! 99: PASSED range min = 0 max = 100
! 100: PASSED range min = 10 max = 100
! 101: PASSED range min = 0 max = 100
! 102: PASSED range min = 10 max = 100
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>