123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/6/23
- * Time: 下午10:21
- */
- define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
- require_once(BASE_ROOT_PATH . '/fooder.php');
- require_once(BASE_ROOT_PATH . '/helper/relation_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/performance_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/algorithm.php');
- class relation_helperTest extends PHPUnit_Framework_TestCase
- {
- public static function setUpBeforeClass()
- {
- Base::run_util();
- }
- public function testUpContactsA()
- {
- //36490
- $contacts = array('13911129868','13911129869','13911129870','13911129871','13911129867','15618951806','18612396521');
- relation_helper::onUpContacts(36490,'13911129867','江海苗',$contacts);
- }
- public function testUpContactsB()
- {
- //36490
- $contacts = array('13911129867','13911129869','13911129870','13911129872');
- relation_helper::onUpContacts(36511,'18612396521','秦梦洁',$contacts);
- }
- public function testOnLogin()
- {
- relation_helper::onLogin(36490);
- relation_helper::onLogin(36511);
- }
-
- public function testUpContactsC()
- {
- try
- {
- $contacts = '%5B%22178-0211-8910%22%2C%22182-6227-3057%22%2C%22189-6195-0030%22%5D';
- $contacts = session_helper::parse_contacts($contacts);
- relation_helper::onUpContacts(36511,'18612396521','秦梦洁',$contacts);
- } catch (Exception $ex) {
- echo $ex->getMessage();
- }
- }
- public function testMakeType()
- {
- $reg = '/make_type=(\d+)/i';
- $ret = preg_match($reg, '发送红包,红包单号: xxxxxx make_type=6', $arr);
- }
- public function testFollower()
- {
- $follower = relation_helper::follower(36490);
- if(!empty($follower)) {
- //$follower = self::separate_page($follower,$pages);
- $members = Model('member')->field('*')->where(array('member_id' => array('in',$follower)))->limit(false)->select();
- $desc = array();
- foreach ($members as $val) {
- $info = new member_info($val);
- }
- //return self::outsuccess(array('followers' => $follower,'mem_desc' => , 'mobile_page' => mobile_page($pages)));
- }
- }
- public function testDate()
- {
- $title = strftime("熊猫美妆%m月%d日红包风云榜",1469030400);
- }
- public function testSort()
- {
- $mod = Model('member_relation');
- $item = $mod->field('*')->where(array('member_mobile' => '13911129867'))->find();
- $mobiles = unserialize($item['unbuild_mobiles']);
- // perfor_start();
- // for($i = 0; $i < 10000; ++$i) {
- // sort($mobiles);
- // }
- // perfor_end("testSort","string sort");
- foreach ($mobiles as $mobile) {
- $iMobiles[] = intval($mobile);
- }
- perfor_start();
- for($i = 0; $i < 10000; ++$i) {
- sort($iMobiles);
- }
- perfor_end("testSort","int sort");
- $len = count($iMobiles);
- perfor_start();
- for($i = 0; $i < 10000; ++$i) {
- $pos = $i % $len;
- $val = $iMobiles[$pos];
- //algorithm::array_erase($iMobiles,$pos);
- $pos = algorithm::lower_bonud($iMobiles,$val);
- //algorithm::array_insert($iMobiles,$pos,$val);
- }
- perfor_end("testSort","int sort");
- performance_helper::instance()->format_log();
- }
- public function testArrayInsert()
- {
- $x = array(1,3,5,9,10);
- $pos = algorithm::lower_bonud($x,3);
- $posx = algorithm::upper_bound($x,3);
- $y = algorithm::array_insert($x,$pos,0);
- $pos = algorithm::lower_bonud($x,4);
- $posx = algorithm::upper_bound($x,4);
- //$find = algorithm_helper::binary_search($x,0);
- }
- public function testLowerbound()
- {
- $x = array(1,3,5,9,10);
- $find = algorithm::binary_search($x,0);
- $find = algorithm::binary_search($x,1);
- $pos = algorithm::lower_bonud($x,0);
- $pos = algorithm::lower_bonud($x,2);
- $pos = algorithm::lower_bonud($x,3);
- $pos = algorithm::lower_bonud($x,14);
- }
- public function testUpper()
- {
- $x = array(1,3,5,9,10);
- $pos = algorithm::upper_bound($x,0);
- $pos = algorithm::upper_bound($x,2);
- $pos = algorithm::upper_bound($x,3);
- $pos = algorithm::upper_bound($x,14);
- }
- public function testRelation()
- {
- perfor_start();
- for($i = 0; $i < 10000; ++$i) {
- $mod = Model('member_relation');
- $mod->findByMobile('13911129867');
- }
- perfor_end("testRelation","10000 findByMobile");
- $mod = Model('member_relation');
- $item = $mod->findByMobile('13911129867');
- perfor_start();
- for($i = 0; $i < 10000; ++$i) {
- unserialize($item['unbuild_mobiles']);
- }
- perfor_end("testRelation","10000 unserialize");
- perfor_start();
- for($i = 0; $i < 10000; ++$i) {
- $relation = new \relation\mem_relation(36490);
- //$relation->pass_subscribe();
- }
- perfor_end("testRelation","10000 pass_subscribe");
- performance_helper::instance()->format_log();
- }
- }
|