Annotation of embedaddon/php/ext/standard/tests/general_functions/floatval_variation1.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Testing floatval() and its alias doubleval() functions : usage variations - different data types as $y arg
! 3: --FILE--
! 4: <?php
! 5: /* Prototype: float floatval( mixed $var );
! 6: * Description: Returns the float value of var.
! 7: */
! 8:
! 9:
! 10:
! 11: // get a resource type variable
! 12: $fp = fopen (__FILE__, "r");
! 13: fclose($fp);
! 14: $dfp = opendir ( dirname(__FILE__) );
! 15: closedir($dfp);
! 16:
! 17: // other types in an array
! 18: $not_float_types = array (
! 19: "-2147483648" => -2147483648, // max negative integer value
! 20: "2147483647" => 2147483648, // max positive integer value
! 21: "file resoruce" => $fp,
! 22: "directory resource" => $dfp,
! 23: "\"0.0\"" => "0.0", // string
! 24: "\"1.0\"" => "1.0",
! 25: "\"-1.3e3\"" => "-1.3e3",
! 26: "\"bob-1.3e3\"" => "bob-1.3e3",
! 27: "\"10 Some dollars\"" => "10 Some dollars",
! 28: "\"10.2 Some Dollars\"" => "10.2 Some Dollars",
! 29: "\"10.0 dollar\" + 1" => "10.0 dollar" + 1,
! 30: "\"10.0 dollar\" + 1.0" => "10.0 dollar" + 1.0,
! 31: "\"\"" => "",
! 32: "true" => true,
! 33: "NULL" => NULL,
! 34: "null" => null,
! 35: );
! 36: /* loop through the $not_float_types to see working of
! 37: floatval() on non float types, expected output: float value valid floating point numbers */
! 38: echo "\n*** Testing floatval() on non floating types ***\n";
! 39: foreach ($not_float_types as $key => $type ) {
! 40: echo "\n-- Iteration : $key --\n";
! 41: var_dump( floatval($type) );
! 42: }
! 43:
! 44: echo "\n*** Testing doubleval() on non floating types ***\n";
! 45:
! 46: /* loop through the $not_float_types to see working of
! 47: doubleval() on non float types, expected output: float value valid floating point numbers */
! 48: foreach ($not_float_types as $key => $type ) {
! 49: echo "\n-- Iteration : $key --\n";
! 50: var_dump( doubleval($type) );
! 51: }
! 52: ?>
! 53: ===DONE===
! 54: --EXPECTF--
! 55: *** Testing floatval() on non floating types ***
! 56:
! 57: -- Iteration : -2147483648 --
! 58: float(-2147483648)
! 59:
! 60: -- Iteration : 2147483647 --
! 61: float(2147483648)
! 62:
! 63: -- Iteration : file resoruce --
! 64: float(%d)
! 65:
! 66: -- Iteration : directory resource --
! 67: float(%d)
! 68:
! 69: -- Iteration : "0.0" --
! 70: float(0)
! 71:
! 72: -- Iteration : "1.0" --
! 73: float(1)
! 74:
! 75: -- Iteration : "-1.3e3" --
! 76: float(-1300)
! 77:
! 78: -- Iteration : "bob-1.3e3" --
! 79: float(0)
! 80:
! 81: -- Iteration : "10 Some dollars" --
! 82: float(10)
! 83:
! 84: -- Iteration : "10.2 Some Dollars" --
! 85: float(10.2)
! 86:
! 87: -- Iteration : "10.0 dollar" + 1 --
! 88: float(11)
! 89:
! 90: -- Iteration : "10.0 dollar" + 1.0 --
! 91: float(11)
! 92:
! 93: -- Iteration : "" --
! 94: float(0)
! 95:
! 96: -- Iteration : true --
! 97: float(1)
! 98:
! 99: -- Iteration : NULL --
! 100: float(0)
! 101:
! 102: -- Iteration : null --
! 103: float(0)
! 104:
! 105: *** Testing doubleval() on non floating types ***
! 106:
! 107: -- Iteration : -2147483648 --
! 108: float(-2147483648)
! 109:
! 110: -- Iteration : 2147483647 --
! 111: float(2147483648)
! 112:
! 113: -- Iteration : file resoruce --
! 114: float(%d)
! 115:
! 116: -- Iteration : directory resource --
! 117: float(%d)
! 118:
! 119: -- Iteration : "0.0" --
! 120: float(0)
! 121:
! 122: -- Iteration : "1.0" --
! 123: float(1)
! 124:
! 125: -- Iteration : "-1.3e3" --
! 126: float(-1300)
! 127:
! 128: -- Iteration : "bob-1.3e3" --
! 129: float(0)
! 130:
! 131: -- Iteration : "10 Some dollars" --
! 132: float(10)
! 133:
! 134: -- Iteration : "10.2 Some Dollars" --
! 135: float(10.2)
! 136:
! 137: -- Iteration : "10.0 dollar" + 1 --
! 138: float(11)
! 139:
! 140: -- Iteration : "10.0 dollar" + 1.0 --
! 141: float(11)
! 142:
! 143: -- Iteration : "" --
! 144: float(0)
! 145:
! 146: -- Iteration : true --
! 147: float(1)
! 148:
! 149: -- Iteration : NULL --
! 150: float(0)
! 151:
! 152: -- Iteration : null --
! 153: float(0)
! 154: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>