PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/test/arrays.php

http://orionphp.googlecode.com/
PHP | 48 lines | 30 code | 9 blank | 9 comment | 4 complexity | 64cb29f8dd232ceb2fed5e6ca4558b77 MD5 | raw file
Possible License(s): MIT
  1. /*
  2. ARRAY Unit Test 1.0;
  3. */
  4. $i = 0;
  5. while ($i<100){
  6. $i++;
  7. $arr = array(1,2,3,4,5);
  8. $res = $arr[0] + $arr[1] + $arr[2] + $arr[3] + $arr[4];
  9. assert($res != 15, __LINE__);
  10. $arr = array();
  11. assert($arr[0] != null, __LINE__);
  12. $arr[] = array('aa','bb');
  13. assert($arr[0][1] . $arr[0][0] != 'bbaa', __LINE__);
  14. $arr = array('x'=>20,'y'=>30);
  15. assert($arr['x']+$arr['y']!=50, __LINE__);
  16. assert($arr[x]+$arr[y]!=50,__LINE__);
  17. # test last_index
  18. $arr = ['x'=>20,'y'=>30];
  19. $arr[] = 40;
  20. assert($arr[0]!=40,__LINE__);
  21. # test multi array as sets
  22. $arr = ['x'=>[1,2,'a'],'y'=>[3,4,'b']];
  23. $str = ($arr['x'][0] . $arr['x'][1] . $arr['x'][2]) . ($arr['y'][0] . $arr['y'][1] . $arr['y'][2]);
  24. assert($str!='12a34b',__LINE__);
  25. # test clone
  26. $arr['z'] = $arr['x'];
  27. $arr['z'][0] = 10;
  28. assert($arr['z'][0]==$arr['x'][0],__LINE__);
  29. # test link
  30. $arr['m'] =& $arr['z'];
  31. $arr['m'][0] = 444;
  32. assert($arr['z'][0]!=444,__LINE__);
  33. # test in operator
  34. $arr = [1,'2',3,4.0,5,6,7];
  35. assert(!(2 in $arr), __LINE__);
  36. assert(!(3 in $arr), __LINE__);
  37. assert(!(4 in $arr), __LINE__);
  38. }