summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandy wharmby <wharmby@php.net>2009-02-01 18:32:42 +0000
committerandy wharmby <wharmby@php.net>2009-02-01 18:32:42 +0000
commitb43e2722abe0ca098a8e27e28bfa6928858cb635 (patch)
tree684e188e4ba9b800f3039148ac064b201751e5e7
parenta7e664e21652aec0fd2f8dad79bdd678a0327136 (diff)
downloadphp-git-b43e2722abe0ca098a8e27e28bfa6928858cb635.tar.gz
New floatval() tests. Tested on Windows, Linux and Linux 64
-rw-r--r--ext/standard/tests/general_functions/floatval_basic.phpt172
-rw-r--r--ext/standard/tests/general_functions/floatval_error.phpt40
-rw-r--r--ext/standard/tests/general_functions/floatval_variation1.phpt154
3 files changed, 366 insertions, 0 deletions
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--
+<?php
+/* Prototype: float floatval( mixed $var );
+ * Description: Returns the float value of var.
+ */
+
+// different valid float values
+$valid_floats = array(
+ "0.0" => 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..38868a64fc
--- /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--
+<?php
+/* Prototype: float floatval( mixed $var );
+ * Description: Returns the float value of var.
+ */
+
+echo "*** Testing floatval() and doubleval() : error conditions ***\n";
+
+
+echo "\n-- Testing floatval() and doubleval() function with no arguments --\n";
+var_dump( floatval() );
+var_dump( doubleval() );
+
+echo "\n-- Testing floatval() and doubleval() function with more than expected no. of arguments --\n";
+var_dump( floatval(10.5, FALSE) );
+var_dump( doubleval(10.5, FALSE) );
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing floatval() and doubleval() : error conditions ***
+
+-- Testing floatval() and doubleval() function with no arguments --
+
+Warning: Wrong parameter count for floatval() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for doubleval() in %s on line %d
+NULL
+
+-- Testing floatval() and doubleval() function with more than expected no. of arguments --
+
+Warning: Wrong parameter count for floatval() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for doubleval() 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--
+<?php
+/* Prototype: float floatval( mixed $var );
+ * Description: Returns the float value of var.
+ */
+
+
+
+// get a resource type variable
+$fp = fopen (__FILE__, "r");
+fclose($fp);
+$dfp = opendir ( dirname(__FILE__) );
+closedir($dfp);
+
+// other types in an array
+$not_float_types = array (
+ "-2147483648" => -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