wharmby         Sun Feb  1 18:32:38 2009 UTC

  Added files:                 
    /php-src/ext/standard/tests/general_functions       
                                                        
floatval_variation1.phpt 
                                                        floatval_basic.phpt 
                                                        floatval_error.phpt 
  Log:
  New floatval() tests. Tested on Windows, Linux and Linux 64
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/general_functions/floatval_variation1.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/general_functions/floatval_variation1.phpt
+++ php-src/ext/standard/tests/general_functions/floatval_variation1.phpt
--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===
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/general_functions/floatval_basic.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/general_functions/floatval_basic.phpt
+++ php-src/ext/standard/tests/general_functions/floatval_basic.phpt
--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===
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/general_functions/floatval_error.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/general_functions/floatval_error.phpt
+++ php-src/ext/standard/tests/general_functions/floatval_error.phpt
--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: 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===
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to