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