1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
--TEST--
number.phpt: Unit tests for 'Validate.php'
--FILE--
<?php
// $Id$
require_once 'Validate.php';
// Validate test script
$noYes = array('NO', 'YES');
echo "Test Validate_Number\n";
echo "********************\n";
$numbers = array(
array(8), // OK
array('-8'), // OK
array(-8), // OK
array('-8,', 'decimal'=>','), // NOK
array('-8.0', 'decimal'=>','), // NOK
array('-8,0', 'decimal'=>',', 'dec_prec'=>2), // OK
array(8.0004, 'decimal'=>'.', 'dec_prec'=>3), // NOK
array(8.0004, 'decimal'=>'.', 'dec_prec'=>4), // OK
array('-8', 'min'=>1, 'max'=>9), // NOK
array('-8', 'min'=>-8, 'max'=>-7), // OK
array('-8.02', 'decimal'=>'.', 'min'=>-8, 'max'=>-7), // NOK
array('-8.02', 'decimal'=>'.', 'min'=>-9, 'max'=>-7), // OK
array('-8.02', 'decimal'=>'.,','min'=>-9, 'max'=>-7) // OK
);
foreach($numbers as $data) {
$number = array_shift($data);
echo "{$number} (";
foreach ($data as $key=>$val) {
echo "{$key}=>{$val} ";
}
echo "): ".$noYes[Validate::number($number,$data)]."\n";
}
?>
--EXPECT--
Test Validate_Number
********************
8 (): YES
-8 (): YES
-8 (): YES
-8, (decimal=>, ): NO
-8.0 (decimal=>, ): NO
-8,0 (decimal=>, dec_prec=>2 ): YES
8.0004 (decimal=>. dec_prec=>3 ): NO
8.0004 (decimal=>. dec_prec=>4 ): YES
-8 (min=>1 max=>9 ): NO
-8 (min=>-8 max=>-7 ): YES
-8.02 (decimal=>. min=>-8 max=>-7 ): NO
-8.02 (decimal=>. min=>-9 max=>-7 ): YES
-8.02 (decimal=>., min=>-9 max=>-7 ): YES
|