relation_helperTest.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/6/23
  6. * Time: 下午10:21
  7. */
  8. define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
  9. require_once(BASE_ROOT_PATH . '/fooder.php');
  10. require_once(BASE_ROOT_PATH . '/helper/relation_helper.php');
  11. require_once(BASE_ROOT_PATH . '/helper/performance_helper.php');
  12. require_once(BASE_ROOT_PATH . '/helper/algorithm.php');
  13. class relation_helperTest extends PHPUnit_Framework_TestCase
  14. {
  15. public static function setUpBeforeClass()
  16. {
  17. Base::run_util();
  18. }
  19. public function testUpContactsA()
  20. {
  21. //36490
  22. $contacts = array('13911129868','13911129869','13911129870','13911129871','13911129867','15618951806','18612396521');
  23. relation_helper::onUpContacts(36490,'13911129867','江海苗',$contacts);
  24. }
  25. public function testUpContactsB()
  26. {
  27. //36490
  28. $contacts = array('13911129867','13911129869','13911129870','13911129872');
  29. relation_helper::onUpContacts(36511,'18612396521','秦梦洁',$contacts);
  30. }
  31. public function testOnLogin()
  32. {
  33. relation_helper::onLogin(36490);
  34. relation_helper::onLogin(36511);
  35. }
  36. public function testUpContactsC()
  37. {
  38. try
  39. {
  40. $contacts = '%5B%22178-0211-8910%22%2C%22182-6227-3057%22%2C%22189-6195-0030%22%5D';
  41. $contacts = session_helper::parse_contacts($contacts);
  42. relation_helper::onUpContacts(36511,'18612396521','秦梦洁',$contacts);
  43. } catch (Exception $ex) {
  44. echo $ex->getMessage();
  45. }
  46. }
  47. public function testMakeType()
  48. {
  49. $reg = '/make_type=(\d+)/i';
  50. $ret = preg_match($reg, '发送红包,红包单号: xxxxxx make_type=6', $arr);
  51. }
  52. public function testFollower()
  53. {
  54. $follower = relation_helper::follower(36490);
  55. if(!empty($follower)) {
  56. //$follower = self::separate_page($follower,$pages);
  57. $members = Model('member')->field('*')->where(array('member_id' => array('in',$follower)))->limit(false)->select();
  58. $desc = array();
  59. foreach ($members as $val) {
  60. $info = new member_info($val);
  61. }
  62. //return self::outsuccess(array('followers' => $follower,'mem_desc' => , 'mobile_page' => mobile_page($pages)));
  63. }
  64. }
  65. public function testDate()
  66. {
  67. $title = strftime("熊猫美妆%m月%d日红包风云榜",1469030400);
  68. }
  69. public function testSort()
  70. {
  71. $mod = Model('member_relation');
  72. $item = $mod->field('*')->where(array('member_mobile' => '13911129867'))->find();
  73. $mobiles = unserialize($item['unbuild_mobiles']);
  74. // perfor_start();
  75. // for($i = 0; $i < 10000; ++$i) {
  76. // sort($mobiles);
  77. // }
  78. // perfor_end("testSort","string sort");
  79. foreach ($mobiles as $mobile) {
  80. $iMobiles[] = intval($mobile);
  81. }
  82. perfor_start();
  83. for($i = 0; $i < 10000; ++$i) {
  84. sort($iMobiles);
  85. }
  86. perfor_end("testSort","int sort");
  87. $len = count($iMobiles);
  88. perfor_start();
  89. for($i = 0; $i < 10000; ++$i) {
  90. $pos = $i % $len;
  91. $val = $iMobiles[$pos];
  92. //algorithm::array_erase($iMobiles,$pos);
  93. $pos = algorithm::lower_bonud($iMobiles,$val);
  94. //algorithm::array_insert($iMobiles,$pos,$val);
  95. }
  96. perfor_end("testSort","int sort");
  97. performance_helper::instance()->format_log();
  98. }
  99. public function testArrayInsert()
  100. {
  101. $x = array(1,3,5,9,10);
  102. $pos = algorithm::lower_bonud($x,3);
  103. $posx = algorithm::upper_bound($x,3);
  104. $y = algorithm::array_insert($x,$pos,0);
  105. $pos = algorithm::lower_bonud($x,4);
  106. $posx = algorithm::upper_bound($x,4);
  107. //$find = algorithm_helper::binary_search($x,0);
  108. }
  109. public function testLowerbound()
  110. {
  111. $x = array(1,3,5,9,10);
  112. $find = algorithm::binary_search($x,0);
  113. $find = algorithm::binary_search($x,1);
  114. $pos = algorithm::lower_bonud($x,0);
  115. $pos = algorithm::lower_bonud($x,2);
  116. $pos = algorithm::lower_bonud($x,3);
  117. $pos = algorithm::lower_bonud($x,14);
  118. }
  119. public function testUpper()
  120. {
  121. $x = array(1,3,5,9,10);
  122. $pos = algorithm::upper_bound($x,0);
  123. $pos = algorithm::upper_bound($x,2);
  124. $pos = algorithm::upper_bound($x,3);
  125. $pos = algorithm::upper_bound($x,14);
  126. }
  127. public function testRelation()
  128. {
  129. perfor_start();
  130. for($i = 0; $i < 10000; ++$i) {
  131. $mod = Model('member_relation');
  132. $mod->findByMobile('13911129867');
  133. }
  134. perfor_end("testRelation","10000 findByMobile");
  135. $mod = Model('member_relation');
  136. $item = $mod->findByMobile('13911129867');
  137. perfor_start();
  138. for($i = 0; $i < 10000; ++$i) {
  139. unserialize($item['unbuild_mobiles']);
  140. }
  141. perfor_end("testRelation","10000 unserialize");
  142. perfor_start();
  143. for($i = 0; $i < 10000; ++$i) {
  144. $relation = new \relation\mem_relation(36490);
  145. //$relation->pass_subscribe();
  146. }
  147. perfor_end("testRelation","10000 pass_subscribe");
  148. performance_helper::instance()->format_log();
  149. }
  150. }