Annotation of embedaddon/php/ext/standard/tests/strings/fprintf_variation_001.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test fprintf() function (variation - 1)
3: --SKIPIF--
4: <?php
5: $data_file = dirname(__FILE__) . '/dump.txt';
6: if (!($fp = fopen($data_file, 'w'))) {
7: die('skip File dump.txt could not be created');
8: }
9: ?>
10: --FILE--
11: <?php
12:
13: $float_variation = array( "%f","%-f", "%+f", "%7.2f", "%-7.2f", "%07.2f", "%-07.2f", "%'#7.2f" );
14: $float_numbers = array( 0, 1, -1, 0.32, -0.32, 3.4. -3.4, 2.54, -2.54 );
15:
16: /* creating dumping file */
17: $data_file = dirname(__FILE__) . '/dump.txt';
18: if (!($fp = fopen($data_file, 'wt')))
19: return;
20:
21: $counter = 1;
22: /* float type variations */
23: fprintf($fp, "\n*** Testing fprintf() with floats ***\n");
24:
25: foreach( $float_variation as $float_var ) {
26: fprintf( $fp, "\n-- Iteration %d --\n",$counter);
27: foreach( $float_numbers as $float_num ) {
28: fprintf( $fp, "\n");
29: fprintf( $fp, $float_var, $float_num );
30: }
31: $counter++;
32: }
33:
34: fclose($fp);
35: print_r(file_get_contents($data_file));
36: echo "\nDone";
37:
38: unlink($data_file);
39:
40: ?>
41: --EXPECTF--
42: *** Testing fprintf() with floats ***
43:
44: -- Iteration 1 --
45:
46: 0.000000
47: 1.000000
48: -1.000000
49: 0.320000
50: -0.320000
51: 3.400000
52: 2.540000
53: -2.540000
54: -- Iteration 2 --
55:
56: 0.000000
57: 1.000000
58: -1.000000
59: 0.320000
60: -0.320000
61: 3.400000
62: 2.540000
63: -2.540000
64: -- Iteration 3 --
65:
66: +0.000000
67: +1.000000
68: -1.000000
69: +0.320000
70: -0.320000
71: +3.400000
72: +2.540000
73: -2.540000
74: -- Iteration 4 --
75:
76: 0.00
77: 1.00
78: -1.00
79: 0.32
80: -0.32
81: 3.40
82: 2.54
83: -2.54
84: -- Iteration 5 --
85:
86: 0.00
87: 1.00
88: -1.00
89: 0.32
90: -0.32
91: 3.40
92: 2.54
93: -2.54
94: -- Iteration 6 --
95:
96: 0000.00
97: 0001.00
98: -001.00
99: 0000.32
100: -000.32
101: 0003.40
102: 0002.54
103: -002.54
104: -- Iteration 7 --
105:
106: 0.00000
107: 1.00000
108: -1.0000
109: 0.32000
110: -0.3200
111: 3.40000
112: 2.54000
113: -2.5400
114: -- Iteration 8 --
115:
116: ###0.00
117: ###1.00
118: ##-1.00
119: ###0.32
120: ##-0.32
121: ###3.40
122: ###2.54
123: ##-2.54
124: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>