range.phpt 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. --TEST--
  2. Test range() function
  3. --INI--
  4. serialize_precision=14
  5. --FILE--
  6. <?php
  7. echo "*** Testing range() function on basic operations ***\n";
  8. echo "\n-- Integers as Low and High --\n";
  9. echo "-- An array of elements from low to high --\n";
  10. var_dump( range(1, 10) );
  11. echo "\n-- An array of elements from high to low --\n";
  12. var_dump( range(10, 1) );
  13. echo "\n-- Numeric Strings as Low and High --\n";
  14. echo "-- An array of elements from low to high --\n";
  15. var_dump( range("1", "10") );
  16. echo "\n-- An array of elements from high to low --\n";
  17. var_dump( range("10", "1") );
  18. echo "\n-- Chars as Low and High --\n";
  19. echo "-- An array of elements from low to high --\n";
  20. var_dump( range("a", "z") );
  21. echo "\n-- An array of elements from high to low --\n";
  22. var_dump( range("z", "a") );
  23. echo "\n-- Low and High are equal --\n";
  24. var_dump( range(5, 5) );
  25. var_dump( range("q", "q") );
  26. echo "\n-- floats as Low and High --\n";
  27. var_dump( range(5.1, 10.1) );
  28. var_dump( range(10.1, 5.1) );
  29. var_dump( range("5.1", "10.1") );
  30. var_dump( range("10.1", "5.1") );
  31. echo "\n-- Passing step with Low and High --\n";
  32. var_dump( range(1, 2, 0.1) );
  33. var_dump( range(2, 1, 0.1) );
  34. var_dump( range(1, 2, "0.1") );
  35. var_dump( range("1", "2", 0.1) );
  36. echo "\n-- Testing basic string with step --\n";
  37. var_dump( range("abcd", "mnop", 2) );
  38. echo "Done\n";
  39. ?>
  40. --EXPECT--
  41. *** Testing range() function on basic operations ***
  42. -- Integers as Low and High --
  43. -- An array of elements from low to high --
  44. array(10) {
  45. [0]=>
  46. int(1)
  47. [1]=>
  48. int(2)
  49. [2]=>
  50. int(3)
  51. [3]=>
  52. int(4)
  53. [4]=>
  54. int(5)
  55. [5]=>
  56. int(6)
  57. [6]=>
  58. int(7)
  59. [7]=>
  60. int(8)
  61. [8]=>
  62. int(9)
  63. [9]=>
  64. int(10)
  65. }
  66. -- An array of elements from high to low --
  67. array(10) {
  68. [0]=>
  69. int(10)
  70. [1]=>
  71. int(9)
  72. [2]=>
  73. int(8)
  74. [3]=>
  75. int(7)
  76. [4]=>
  77. int(6)
  78. [5]=>
  79. int(5)
  80. [6]=>
  81. int(4)
  82. [7]=>
  83. int(3)
  84. [8]=>
  85. int(2)
  86. [9]=>
  87. int(1)
  88. }
  89. -- Numeric Strings as Low and High --
  90. -- An array of elements from low to high --
  91. array(10) {
  92. [0]=>
  93. int(1)
  94. [1]=>
  95. int(2)
  96. [2]=>
  97. int(3)
  98. [3]=>
  99. int(4)
  100. [4]=>
  101. int(5)
  102. [5]=>
  103. int(6)
  104. [6]=>
  105. int(7)
  106. [7]=>
  107. int(8)
  108. [8]=>
  109. int(9)
  110. [9]=>
  111. int(10)
  112. }
  113. -- An array of elements from high to low --
  114. array(10) {
  115. [0]=>
  116. int(10)
  117. [1]=>
  118. int(9)
  119. [2]=>
  120. int(8)
  121. [3]=>
  122. int(7)
  123. [4]=>
  124. int(6)
  125. [5]=>
  126. int(5)
  127. [6]=>
  128. int(4)
  129. [7]=>
  130. int(3)
  131. [8]=>
  132. int(2)
  133. [9]=>
  134. int(1)
  135. }
  136. -- Chars as Low and High --
  137. -- An array of elements from low to high --
  138. array(26) {
  139. [0]=>
  140. string(1) "a"
  141. [1]=>
  142. string(1) "b"
  143. [2]=>
  144. string(1) "c"
  145. [3]=>
  146. string(1) "d"
  147. [4]=>
  148. string(1) "e"
  149. [5]=>
  150. string(1) "f"
  151. [6]=>
  152. string(1) "g"
  153. [7]=>
  154. string(1) "h"
  155. [8]=>
  156. string(1) "i"
  157. [9]=>
  158. string(1) "j"
  159. [10]=>
  160. string(1) "k"
  161. [11]=>
  162. string(1) "l"
  163. [12]=>
  164. string(1) "m"
  165. [13]=>
  166. string(1) "n"
  167. [14]=>
  168. string(1) "o"
  169. [15]=>
  170. string(1) "p"
  171. [16]=>
  172. string(1) "q"
  173. [17]=>
  174. string(1) "r"
  175. [18]=>
  176. string(1) "s"
  177. [19]=>
  178. string(1) "t"
  179. [20]=>
  180. string(1) "u"
  181. [21]=>
  182. string(1) "v"
  183. [22]=>
  184. string(1) "w"
  185. [23]=>
  186. string(1) "x"
  187. [24]=>
  188. string(1) "y"
  189. [25]=>
  190. string(1) "z"
  191. }
  192. -- An array of elements from high to low --
  193. array(26) {
  194. [0]=>
  195. string(1) "z"
  196. [1]=>
  197. string(1) "y"
  198. [2]=>
  199. string(1) "x"
  200. [3]=>
  201. string(1) "w"
  202. [4]=>
  203. string(1) "v"
  204. [5]=>
  205. string(1) "u"
  206. [6]=>
  207. string(1) "t"
  208. [7]=>
  209. string(1) "s"
  210. [8]=>
  211. string(1) "r"
  212. [9]=>
  213. string(1) "q"
  214. [10]=>
  215. string(1) "p"
  216. [11]=>
  217. string(1) "o"
  218. [12]=>
  219. string(1) "n"
  220. [13]=>
  221. string(1) "m"
  222. [14]=>
  223. string(1) "l"
  224. [15]=>
  225. string(1) "k"
  226. [16]=>
  227. string(1) "j"
  228. [17]=>
  229. string(1) "i"
  230. [18]=>
  231. string(1) "h"
  232. [19]=>
  233. string(1) "g"
  234. [20]=>
  235. string(1) "f"
  236. [21]=>
  237. string(1) "e"
  238. [22]=>
  239. string(1) "d"
  240. [23]=>
  241. string(1) "c"
  242. [24]=>
  243. string(1) "b"
  244. [25]=>
  245. string(1) "a"
  246. }
  247. -- Low and High are equal --
  248. array(1) {
  249. [0]=>
  250. int(5)
  251. }
  252. array(1) {
  253. [0]=>
  254. string(1) "q"
  255. }
  256. -- floats as Low and High --
  257. array(6) {
  258. [0]=>
  259. float(5.1)
  260. [1]=>
  261. float(6.1)
  262. [2]=>
  263. float(7.1)
  264. [3]=>
  265. float(8.1)
  266. [4]=>
  267. float(9.1)
  268. [5]=>
  269. float(10.1)
  270. }
  271. array(6) {
  272. [0]=>
  273. float(10.1)
  274. [1]=>
  275. float(9.1)
  276. [2]=>
  277. float(8.1)
  278. [3]=>
  279. float(7.1)
  280. [4]=>
  281. float(6.1)
  282. [5]=>
  283. float(5.1)
  284. }
  285. array(6) {
  286. [0]=>
  287. float(5.1)
  288. [1]=>
  289. float(6.1)
  290. [2]=>
  291. float(7.1)
  292. [3]=>
  293. float(8.1)
  294. [4]=>
  295. float(9.1)
  296. [5]=>
  297. float(10.1)
  298. }
  299. array(6) {
  300. [0]=>
  301. float(10.1)
  302. [1]=>
  303. float(9.1)
  304. [2]=>
  305. float(8.1)
  306. [3]=>
  307. float(7.1)
  308. [4]=>
  309. float(6.1)
  310. [5]=>
  311. float(5.1)
  312. }
  313. -- Passing step with Low and High --
  314. array(11) {
  315. [0]=>
  316. float(1)
  317. [1]=>
  318. float(1.1)
  319. [2]=>
  320. float(1.2)
  321. [3]=>
  322. float(1.3)
  323. [4]=>
  324. float(1.4)
  325. [5]=>
  326. float(1.5)
  327. [6]=>
  328. float(1.6)
  329. [7]=>
  330. float(1.7)
  331. [8]=>
  332. float(1.8)
  333. [9]=>
  334. float(1.9)
  335. [10]=>
  336. float(2)
  337. }
  338. array(11) {
  339. [0]=>
  340. float(2)
  341. [1]=>
  342. float(1.9)
  343. [2]=>
  344. float(1.8)
  345. [3]=>
  346. float(1.7)
  347. [4]=>
  348. float(1.6)
  349. [5]=>
  350. float(1.5)
  351. [6]=>
  352. float(1.4)
  353. [7]=>
  354. float(1.3)
  355. [8]=>
  356. float(1.2)
  357. [9]=>
  358. float(1.1)
  359. [10]=>
  360. float(1)
  361. }
  362. array(11) {
  363. [0]=>
  364. float(1)
  365. [1]=>
  366. float(1.1)
  367. [2]=>
  368. float(1.2)
  369. [3]=>
  370. float(1.3)
  371. [4]=>
  372. float(1.4)
  373. [5]=>
  374. float(1.5)
  375. [6]=>
  376. float(1.6)
  377. [7]=>
  378. float(1.7)
  379. [8]=>
  380. float(1.8)
  381. [9]=>
  382. float(1.9)
  383. [10]=>
  384. float(2)
  385. }
  386. array(11) {
  387. [0]=>
  388. float(1)
  389. [1]=>
  390. float(1.1)
  391. [2]=>
  392. float(1.2)
  393. [3]=>
  394. float(1.3)
  395. [4]=>
  396. float(1.4)
  397. [5]=>
  398. float(1.5)
  399. [6]=>
  400. float(1.6)
  401. [7]=>
  402. float(1.7)
  403. [8]=>
  404. float(1.8)
  405. [9]=>
  406. float(1.9)
  407. [10]=>
  408. float(2)
  409. }
  410. -- Testing basic string with step --
  411. array(7) {
  412. [0]=>
  413. string(1) "a"
  414. [1]=>
  415. string(1) "c"
  416. [2]=>
  417. string(1) "e"
  418. [3]=>
  419. string(1) "g"
  420. [4]=>
  421. string(1) "i"
  422. [5]=>
  423. string(1) "k"
  424. [6]=>
  425. string(1) "m"
  426. }
  427. Done