Annotation of embedaddon/php/ext/standard/tests/math/round_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test round() function : usage variations - different data types as $precision argument
3: --INI--
4: precision=14
5: --FILE--
6: <?php
7: /* Prototype : float round ( float $val [, int $precision ] )
8: * Description: Returns the rounded value of val to specified precision (number of digits
9: * after the decimal point)
10: * Source code: ext/standard/math.c
11: */
12:
13: echo "*** Testing round() : usage variations ***\n";
14:
15: //get an unset variable
16: $unset_var = 10;
17: unset ($unset_var);
18:
19: // heredoc string
20: $heredoc = <<<EOT
21: abc
22: xyz
23: EOT;
24:
25: // get a class
26: class classA
27: {
28: }
29:
30: // get a resource variable
31: $fp = fopen(__FILE__, "r");
32:
33: $inputs = array(
34: // int data
35: /*1*/ 0,
36: 1,
37: 12345,
38: -2345,
39: 2147483647,
40:
41: // float data
42: /*6*/ 10.5,
43: -10.5,
44: 12.3456789000e5,
45: 12.3456789000E-5,
46: .5,
47:
48: // null data
49: /*11*/ NULL,
50: null,
51:
52: // boolean data
53: /*13*/ true,
54: false,
55: TRUE,
56: FALSE,
57:
58: // empty data
59: /*17*/ "",
60: '',
61: array(),
62:
63: // string data
64: /*20*/ "abcxyz",
65: 'abcxyz',
66: $heredoc,
67:
68: // object data
69: /*23*/ new classA(),
70:
71: // undefined data
72: /*24*/ @$undefined_var,
73:
74: // unset data
75: /*25*/ @$unset_var,
76:
77: // resource variable
78: /*26*/ $fp
79: );
80:
81: // loop through each element of $inputs to check the behaviour of round()
82: $iterator = 1;
83: foreach($inputs as $input) {
84: echo "\n-- Iteration $iterator --\n";
85: var_dump(round(123.4456789, $input));
86: $iterator++;
87: };
88: fclose($fp);
89: ?>
90: ===Done===
91: --EXPECTF--
92: *** Testing round() : usage variations ***
93:
94: -- Iteration 1 --
95: float(123)
96:
97: -- Iteration 2 --
98: float(123.4)
99:
100: -- Iteration 3 --
101: float(123.4456789)
102:
103: -- Iteration 4 --
104: float(0)
105:
106: -- Iteration 5 --
107: float(123.4456789)
108:
109: -- Iteration 6 --
110: float(123.4456789)
111:
112: -- Iteration 7 --
113: float(0)
114:
115: -- Iteration 8 --
116: float(123.4456789)
117:
118: -- Iteration 9 --
119: float(123)
120:
121: -- Iteration 10 --
122: float(123)
123:
124: -- Iteration 11 --
125: float(123)
126:
127: -- Iteration 12 --
128: float(123)
129:
130: -- Iteration 13 --
131: float(123.4)
132:
133: -- Iteration 14 --
134: float(123)
135:
136: -- Iteration 15 --
137: float(123.4)
138:
139: -- Iteration 16 --
140: float(123)
141:
142: -- Iteration 17 --
143:
144: Warning: round() expects parameter 2 to be long, string given in %s on line %d
145: NULL
146:
147: -- Iteration 18 --
148:
149: Warning: round() expects parameter 2 to be long, string given in %s on line %d
150: NULL
151:
152: -- Iteration 19 --
153:
154: Warning: round() expects parameter 2 to be long, array given in %s on line %d
155: NULL
156:
157: -- Iteration 20 --
158:
159: Warning: round() expects parameter 2 to be long, string given in %s on line %d
160: NULL
161:
162: -- Iteration 21 --
163:
164: Warning: round() expects parameter 2 to be long, string given in %s on line %d
165: NULL
166:
167: -- Iteration 22 --
168:
169: Warning: round() expects parameter 2 to be long, string given in %s on line %d
170: NULL
171:
172: -- Iteration 23 --
173:
174: Warning: round() expects parameter 2 to be long, object given in %s on line %d
175: NULL
176:
177: -- Iteration 24 --
178: float(123)
179:
180: -- Iteration 25 --
181: float(123)
182:
183: -- Iteration 26 --
184:
185: Warning: round() expects parameter 2 to be long, resource given in %s on line %d
186: NULL
187: ===Done===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>