TestServer.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace loyalsoft;
  3. include_once __DIR__ . '/AppServer.php';
  4. require_once __DIR__ . '/../process/ActiveProc/CipheredBase32.php'; # 算法库
  5. /**
  6. * Description of TestServer
  7. * UT 测试
  8. * @author jgao
  9. */
  10. class TestServer {
  11. /**
  12. * 入口函数专用测试
  13. * @param type $req
  14. */
  15. static public function testApi($req) {
  16. DebugHelper::debug($req);
  17. $app = new AppServer();
  18. new Req($req);
  19. $ret = $app->api();
  20. DebugHelper::debug($ret);
  21. }
  22. /**
  23. * 运行环境自检:
  24. * PHP 版本,扩展模块
  25. * redis操作性
  26. * sqldb操作性
  27. */
  28. static function selfTest() {
  29. echoLine("phpver: " . PHP_VERSION . PHP_EOL); # 打印下PHP版本
  30. SelfChecker::CheckConfig(); # 进行配置环境检测
  31. }
  32. //----------------------------------------------------
  33. public function testRedisLua($key, $value) {
  34. $mem = gMem();
  35. $script = <<<SCR
  36. if redis.call("get",KEYS[1]) == ARGV[1]
  37. then
  38. return redis.call("del",KEYS[1])
  39. else
  40. return 0
  41. end
  42. SCR;
  43. DebugHelper:: var_dump($script);
  44. $ret = $mem->redis->eval($script, 1, $key, $value);
  45. DebugHelper:: var_dump($ret);
  46. $mem->close();
  47. }
  48. public function testBinSearch($v) {
  49. $arr = array(1, 2, 3, 4, 4, 11, 12, 124);
  50. $start = 0;
  51. $end = count($arr) - 1;
  52. while ($start <= $end) {
  53. $index = intval(($start + $end) / 2);
  54. if ($v < $arr[$index]) {
  55. $end = $index - 1;
  56. } elseif ($v > $arr[$index]) {
  57. $start = $index + 1;
  58. } else {
  59. echo($index);
  60. return;
  61. }
  62. }
  63. echo($index);
  64. }
  65. }