From: andy wharmby Date: Sun, 1 Feb 2009 18:32:38 +0000 (+0000) Subject: New floatval() tests. Tested on Windows, Linux and Linux 64 X-Git-Tag: php-5.4.0alpha1~191^2~4355 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=054f6e1075870ba7da7efadbc8adb2c199278616;p=php New floatval() tests. Tested on Windows, Linux and Linux 64 --- diff --git a/ext/standard/tests/general_functions/floatval_basic.phpt b/ext/standard/tests/general_functions/floatval_basic.phpt new file mode 100644 index 0000000000..129aa87b3c --- /dev/null +++ b/ext/standard/tests/general_functions/floatval_basic.phpt @@ -0,0 +1,172 @@ +--TEST-- +Testing floatval() and its alias doubleval() Functions +--INI-- +precision = 14 +--FILE-- + 0.0, + "1.0" => 1.0, + "-1.0" => -1.0, + "1.234" => 1.234, + "-1.234" => -1.234, + "1.2e3" => 1.2e3, + "-1.2e3" => -1.2e3, + "10.0000000000000000005" => 10.0000000000000000005, + "10.5e+5" => 10.5e+5, + "1e5" => 1e5, + "-1e5" => -1e5, + "1e5" => 1e-5, + "-1e-1" => -1e-1, + "1e+5" => 1e+5, + "-1e+5" =>-1e+5, + "1E5" => 1E5, + "-1E5" => -1E5, + "1E+5" => 1E+5, + "-1E5" => -1E+5, + ".5e+7" => .5e+7, + "-.5e+7" =>-.5e+7 +); + +/* loop to check that floatval() recognizes different + float values, expected output:float value for valid floating point number */ +echo "*** Testing floatval() with valid float values ***\n"; +foreach ($valid_floats as $key => $value ) { + echo "\n-- Iteration : $key -- \n"; + var_dump( floatval($value) ); +} + +/* loop to check that doubleval() also recognizes different + float values, expected output:float value for valid floating point number */ +echo "\n*** Testing doubleval() with valid float values ***\n"; +foreach ($valid_floats as $key => $value ) { + echo "\n-- Iteration : $key -- \n"; + var_dump( doubleval($value) ); +} + +?> +===DONE=== +--EXPECT-- +*** Testing floatval() with valid float values *** + +-- Iteration : 0.0 -- +float(0) + +-- Iteration : 1.0 -- +float(1) + +-- Iteration : -1.0 -- +float(-1) + +-- Iteration : 1.234 -- +float(1.234) + +-- Iteration : -1.234 -- +float(-1.234) + +-- Iteration : 1.2e3 -- +float(1200) + +-- Iteration : -1.2e3 -- +float(-1200) + +-- Iteration : 10.0000000000000000005 -- +float(10) + +-- Iteration : 10.5e+5 -- +float(1050000) + +-- Iteration : 1e5 -- +float(1.0E-5) + +-- Iteration : -1e5 -- +float(-100000) + +-- Iteration : -1e-1 -- +float(-0.1) + +-- Iteration : 1e+5 -- +float(100000) + +-- Iteration : -1e+5 -- +float(-100000) + +-- Iteration : 1E5 -- +float(100000) + +-- Iteration : -1E5 -- +float(-100000) + +-- Iteration : 1E+5 -- +float(100000) + +-- Iteration : .5e+7 -- +float(5000000) + +-- Iteration : -.5e+7 -- +float(-5000000) + +*** Testing doubleval() with valid float values *** + +-- Iteration : 0.0 -- +float(0) + +-- Iteration : 1.0 -- +float(1) + +-- Iteration : -1.0 -- +float(-1) + +-- Iteration : 1.234 -- +float(1.234) + +-- Iteration : -1.234 -- +float(-1.234) + +-- Iteration : 1.2e3 -- +float(1200) + +-- Iteration : -1.2e3 -- +float(-1200) + +-- Iteration : 10.0000000000000000005 -- +float(10) + +-- Iteration : 10.5e+5 -- +float(1050000) + +-- Iteration : 1e5 -- +float(1.0E-5) + +-- Iteration : -1e5 -- +float(-100000) + +-- Iteration : -1e-1 -- +float(-0.1) + +-- Iteration : 1e+5 -- +float(100000) + +-- Iteration : -1e+5 -- +float(-100000) + +-- Iteration : 1E5 -- +float(100000) + +-- Iteration : -1E5 -- +float(-100000) + +-- Iteration : 1E+5 -- +float(100000) + +-- Iteration : .5e+7 -- +float(5000000) + +-- Iteration : -.5e+7 -- +float(-5000000) +===DONE=== \ No newline at end of file diff --git a/ext/standard/tests/general_functions/floatval_error.phpt b/ext/standard/tests/general_functions/floatval_error.phpt new file mode 100644 index 0000000000..178713abe9 --- /dev/null +++ b/ext/standard/tests/general_functions/floatval_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +Testing floatval() and its alias doubleval() : error conditions - wrong numbers of parametersns +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing floatval() and doubleval() : error conditions *** + +-- Testing floatval() and doubleval() function with no arguments -- + +Warning: floatval() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: doubleval() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing floatval() and doubleval() function with more than expected no. of arguments -- + +Warning: floatval() expects exactly 1 parameter, 2 given in %s on line %d +NULL + +Warning: doubleval() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== \ No newline at end of file diff --git a/ext/standard/tests/general_functions/floatval_variation1.phpt b/ext/standard/tests/general_functions/floatval_variation1.phpt new file mode 100644 index 0000000000..83925b89b0 --- /dev/null +++ b/ext/standard/tests/general_functions/floatval_variation1.phpt @@ -0,0 +1,154 @@ +--TEST-- +Testing floatval() and its alias doubleval() functions : usage variations - different data types as $y arg +--FILE-- + -2147483648, // max negative integer value + "2147483647" => 2147483648, // max positive integer value + "file resoruce" => $fp, + "directory resource" => $dfp, + "\"0.0\"" => "0.0", // string + "\"1.0\"" => "1.0", + "\"-1.3e3\"" => "-1.3e3", + "\"bob-1.3e3\"" => "bob-1.3e3", + "\"10 Some dollars\"" => "10 Some dollars", + "\"10.2 Some Dollars\"" => "10.2 Some Dollars", + "\"10.0 dollar\" + 1" => "10.0 dollar" + 1, + "\"10.0 dollar\" + 1.0" => "10.0 dollar" + 1.0, + "\"\"" => "", + "true" => true, + "NULL" => NULL, + "null" => null, + ); +/* loop through the $not_float_types to see working of + floatval() on non float types, expected output: float value valid floating point numbers */ +echo "\n*** Testing floatval() on non floating types ***\n"; +foreach ($not_float_types as $key => $type ) { + echo "\n-- Iteration : $key --\n"; + var_dump( floatval($type) ); +} + +echo "\n*** Testing doubleval() on non floating types ***\n"; + +/* loop through the $not_float_types to see working of + doubleval() on non float types, expected output: float value valid floating point numbers */ +foreach ($not_float_types as $key => $type ) { + echo "\n-- Iteration : $key --\n"; + var_dump( doubleval($type) ); +} +?> +===DONE=== +--EXPECTF-- +*** Testing floatval() on non floating types *** + +-- Iteration : -2147483648 -- +float(-2147483648) + +-- Iteration : 2147483647 -- +float(2147483648) + +-- Iteration : file resoruce -- +float(%d) + +-- Iteration : directory resource -- +float(%d) + +-- Iteration : "0.0" -- +float(0) + +-- Iteration : "1.0" -- +float(1) + +-- Iteration : "-1.3e3" -- +float(-1300) + +-- Iteration : "bob-1.3e3" -- +float(0) + +-- Iteration : "10 Some dollars" -- +float(10) + +-- Iteration : "10.2 Some Dollars" -- +float(10.2) + +-- Iteration : "10.0 dollar" + 1 -- +float(11) + +-- Iteration : "10.0 dollar" + 1.0 -- +float(11) + +-- Iteration : "" -- +float(0) + +-- Iteration : true -- +float(1) + +-- Iteration : NULL -- +float(0) + +-- Iteration : null -- +float(0) + +*** Testing doubleval() on non floating types *** + +-- Iteration : -2147483648 -- +float(-2147483648) + +-- Iteration : 2147483647 -- +float(2147483648) + +-- Iteration : file resoruce -- +float(%d) + +-- Iteration : directory resource -- +float(%d) + +-- Iteration : "0.0" -- +float(0) + +-- Iteration : "1.0" -- +float(1) + +-- Iteration : "-1.3e3" -- +float(-1300) + +-- Iteration : "bob-1.3e3" -- +float(0) + +-- Iteration : "10 Some dollars" -- +float(10) + +-- Iteration : "10.2 Some Dollars" -- +float(10.2) + +-- Iteration : "10.0 dollar" + 1 -- +float(11) + +-- Iteration : "10.0 dollar" + 1.0 -- +float(11) + +-- Iteration : "" -- +float(0) + +-- Iteration : true -- +float(1) + +-- Iteration : NULL -- +float(0) + +-- Iteration : null -- +float(0) +===DONE=== \ No newline at end of file