Annotation of embedaddon/php/ext/standard/tests/strings/vprintf_variation18.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test vprintf() function : usage variations - scientific formats with non-scientific values
3: --FILE--
4: <?php
5: /* Prototype : string vprintf(string format, array args)
6: * Description: Output a formatted string
7: * Source code: ext/standard/formatted_print.c
8: */
9:
10: /*
11: * Test vprintf() when different scientific formats and non-scientific values are passed to
12: * the '$format' and '$args' arguments of the function
13: */
14:
15: echo "*** Testing vprintf() : scientific formats and non-scientific values ***\n";
16:
17: // defining array of non-scientific formats
18: $formats =
19: '%e %+e %-e
20: %le %Le %4e %-4e
21: %10.4e %-10.4e %04e %04.4e
22: %\'#2e %\'2e %\'$2e %\'_2e
23: %3$e %4$e %1$e %2$e';
24:
25: // Arrays of non scientific values for the format defined in $format.
26: // Each sub array contains non scientific values which correspond to each format in $format
27: $args_array = array(
28:
29: // array of float values
30: array(2.2, .2, 10.2,
31: 123456.234, 123456.234, -1234.6789, +1234.6789,
32: 20.00, +212.2, -411000000000, 2212.000000000001,
33: 12345.780, 12.000000011111, -12.00000111111, -123456.234,
34: 3.33, +4.44, 1.11,-2.22 ),
35:
36: // array of strings
37: array(" ", ' ', 'hello',
38: '123hello', "123hello", '-123hello', '+123hello',
39: "\12345678hello", "-\12345678hello", '0123456hello', 'h123456ello',
40: "1234hello", "hello\0world", "NULL", "true",
41: "3", "4", '1', '2'),
42:
43: // different arrays
44: array( array(0), array(1, 2), array(-1, -1),
45: array("123"), array('123'), array('-123'), array("-123"),
46: array(true), array(false), array(TRUE), array(FALSE),
47: array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
48: array("3"), array("4"), array("1"), array("2") ),
49:
50: // array of boolean data
51: array( true, TRUE, false,
52: TRUE, 0, FALSE, 1,
53: true, false, TRUE, FALSE,
54: 0, 1, 1, 0,
55: 1, TRUE, 0, FALSE),
56:
57: );
58:
59: // looping to test vprintf() with different scientific formats from the above $format array
60: // and with non-scientific values from the above $args_array array
61: $counter = 1;
62: foreach($args_array as $args) {
63: echo "\n-- Iteration $counter --\n";
64: $result = vprintf($formats, $args);
65: echo "\n";
66: var_dump($result);
67: $counter++;
68: }
69:
70: ?>
71: ===DONE===
72: --EXPECT--
73: *** Testing vprintf() : scientific formats and non-scientific values ***
74:
75: -- Iteration 1 --
76: 2.200000e+0 +2.000000e-1 1.020000e+1
77: 1.234562e+5 e -1.234679e+3 1.234679e+3
78: 2.0000e+1 2.1220e+2 -4.110000e+11 2.2120e+3
79: 1.234578e+4 1.200000e+1 -1.200000e+1 -1.234562e+5
80: 1.020000e+1 1.234562e+5 2.200000e+0 2.000000e-1
81: int(232)
82:
83: -- Iteration 2 --
84: 0.000000e+0 +0.000000e+0 0.000000e+0
85: 1.230000e+2 e -1.230000e+2 1.230000e+2
86: 0.0000e+0 0.0000e+0 1.234560e+5 0.0000e+0
87: 1.234000e+3 0.000000e+0 0.000000e+0 0.000000e+0
88: 0.000000e+0 1.230000e+2 0.000000e+0 0.000000e+0
89: int(228)
90:
91: -- Iteration 3 --
92: 1.000000e+0 +1.000000e+0 1.000000e+0
93: 1.000000e+0 e 1.000000e+0 1.000000e+0
94: 1.0000e+0 1.0000e+0 1.000000e+0 1.0000e+0
95: 1.000000e+0 1.000000e+0 1.000000e+0 1.000000e+0
96: 1.000000e+0 1.000000e+0 1.000000e+0 1.000000e+0
97: int(227)
98:
99: -- Iteration 4 --
100: 1.000000e+0 +1.000000e+0 0.000000e+0
101: 1.000000e+0 e 0.000000e+0 1.000000e+0
102: 1.0000e+0 0.0000e+0 1.000000e+0 0.0000e+0
103: 0.000000e+0 1.000000e+0 1.000000e+0 0.000000e+0
104: 0.000000e+0 1.000000e+0 1.000000e+0 1.000000e+0
105: int(227)
106: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>