vprintf_variation18.phpt 3.1 KB

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